summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-09-01 21:41:24 +0200
committerGitHub <noreply@github.com>2017-09-01 21:41:24 +0200
commit3694c58d3cb9f2af41a8f964e00712bb5578af76 (patch)
tree4dc1bf7bba4a1d76220e9044a6c364867aca56c4 /servers
parent5a69a663c727a48d38d1ccc66b18318c21b692f3 (diff)
parentf231eadc9e2487c70db04f912578ec853f11737c (diff)
Merge pull request #10775 from marcelofg55/buffersize_fixes
Corrections to audio buffer size calculations
Diffstat (limited to 'servers')
-rw-r--r--servers/audio/audio_driver_dummy.cpp17
-rw-r--r--servers/audio/audio_driver_dummy.h3
-rw-r--r--servers/audio_server.cpp23
-rw-r--r--servers/audio_server.h3
4 files changed, 34 insertions, 12 deletions
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp
index 992fece85f..1ae0e7b96b 100644
--- a/servers/audio/audio_driver_dummy.cpp
+++ b/servers/audio/audio_driver_dummy.cpp
@@ -37,17 +37,16 @@ Error AudioDriverDummy::init() {
active = false;
thread_exited = false;
exit_thread = false;
- pcm_open = false;
samples_in = NULL;
- mix_rate = 44100;
+ mix_rate = DEFAULT_MIX_RATE;
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;
- int latency = GLOBAL_DEF("audio/output_latency", 25);
- buffer_size = next_power_of_2(latency * mix_rate / 1000);
+ int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY);
+ buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
- samples_in = memnew_arr(int32_t, buffer_size * channels);
+ samples_in = memnew_arr(int32_t, buffer_frames * channels);
mutex = Mutex::create();
thread = Thread::create(AudioDriverDummy::thread_func, this);
@@ -59,17 +58,15 @@ void AudioDriverDummy::thread_func(void *p_udata) {
AudioDriverDummy *ad = (AudioDriverDummy *)p_udata;
- uint64_t usdelay = (ad->buffer_size / float(ad->mix_rate)) * 1000000;
+ uint64_t usdelay = (ad->buffer_frames / float(ad->mix_rate)) * 1000000;
while (!ad->exit_thread) {
- if (!ad->active) {
-
- } else {
+ if (ad->active) {
ad->lock();
- ad->audio_server_process(ad->buffer_size, ad->samples_in);
+ ad->audio_server_process(ad->buffer_frames, ad->samples_in);
ad->unlock();
};
diff --git a/servers/audio/audio_driver_dummy.h b/servers/audio/audio_driver_dummy.h
index b3fea59389..90af1961b7 100644
--- a/servers/audio/audio_driver_dummy.h
+++ b/servers/audio/audio_driver_dummy.h
@@ -43,8 +43,8 @@ class AudioDriverDummy : public AudioDriver {
int32_t *samples_in;
static void thread_func(void *p_udata);
- int buffer_size;
+ unsigned int buffer_frames;
unsigned int mix_rate;
SpeakerMode speaker_mode;
@@ -53,7 +53,6 @@ class AudioDriverDummy : public AudioDriver {
bool active;
bool thread_exited;
mutable bool exit_thread;
- bool pcm_open;
public:
const char *get_name() const {
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index c0343399c3..3139c6bb7a 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -155,6 +155,29 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {
todo -= to_copy;
to_mix -= to_copy;
}
+
+#ifdef DEBUG_ENABLED
+ if (OS::get_singleton() && OS::get_singleton()->is_stdout_verbose()) {
+ static uint64_t first_ticks = 0;
+ static uint64_t last_ticks = 0;
+ static uint64_t ticks = 0;
+ static int count = 0;
+ static int total = 0;
+
+ ticks = OS::get_singleton()->get_ticks_msec();
+ if ((ticks - first_ticks) > 10 * 1000) {
+ print_line("Audio Driver " + String(AudioDriver::get_singleton()->get_name()) + " average latency: " + itos(total / count) + "ms (frame=" + itos(p_frames) + ")");
+ first_ticks = ticks;
+ total = 0;
+ count = 0;
+ }
+
+ total += ticks - last_ticks;
+ count++;
+
+ last_ticks = ticks;
+ }
+#endif
}
void AudioServer::_mix_step() {
diff --git a/servers/audio_server.h b/servers/audio_server.h
index 05e92ceaf0..13a74856c8 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -54,6 +54,9 @@ public:
SPEAKER_SURROUND_71,
};
+ static const int DEFAULT_MIX_RATE = 44100;
+ static const int DEFAULT_OUTPUT_LATENCY = 15;
+
static AudioDriver *get_singleton();
void set_singleton();