summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorMarcelo Fernandez <marcelofg55@gmail.com>2017-08-29 16:47:44 -0300
committerMarcelo Fernandez <marcelofg55@gmail.com>2017-09-01 11:12:13 -0300
commitf231eadc9e2487c70db04f912578ec853f11737c (patch)
tree4e41ad5a1608dcb0f77e21c312c46d0a26613399 /servers
parent06d7e36898d274c2403dcfbe5a83a9d858af0661 (diff)
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();