diff options
-rw-r--r-- | doc/classes/AudioServer.xml | 2 | ||||
-rw-r--r-- | doc/classes/Performance.xml | 2 | ||||
-rw-r--r-- | drivers/pulseaudio/audio_driver_pulseaudio.cpp | 25 |
3 files changed, 13 insertions, 16 deletions
diff --git a/doc/classes/AudioServer.xml b/doc/classes/AudioServer.xml index 20a87aea7b..cb4fb8d5ca 100644 --- a/doc/classes/AudioServer.xml +++ b/doc/classes/AudioServer.xml @@ -132,7 +132,7 @@ <method name="get_output_latency" qualifiers="const"> <return type="float" /> <description> - Returns the audio driver's output latency. + Returns the audio driver's output latency. This can be expensive, it is not recommended to call this every frame. </description> </method> <method name="get_speaker_mode" qualifiers="const"> diff --git a/doc/classes/Performance.xml b/doc/classes/Performance.xml index 377dbba9fc..4d01fe1760 100644 --- a/doc/classes/Performance.xml +++ b/doc/classes/Performance.xml @@ -192,7 +192,7 @@ Number of islands in the 3D physics engine. [i]Lower is better.[/i] </constant> <constant name="AUDIO_OUTPUT_LATENCY" value="23" enum="Monitor"> - Output latency of the [AudioServer]. [i]Lower is better.[/i] + Output latency of the [AudioServer]. Equivalent to calling [method AudioServer.get_output_latency], it is not recommended to call this every frame. </constant> <constant name="NAVIGATION_ACTIVE_MAPS" value="24" enum="Monitor"> Number of active navigation maps in the [NavigationServer3D]. This also includes the two empty default navigation maps created by World2D and World3D. diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index ab94d8911f..8ca396af20 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -370,27 +370,24 @@ Error AudioDriverPulseAudio::init() { } float AudioDriverPulseAudio::get_latency() { - if (latency == 0) { //only do this once since it's approximate anyway - lock(); + lock(); - pa_usec_t palat = 0; - if (pa_stream_get_state(pa_str) == PA_STREAM_READY) { - int negative = 0; + pa_usec_t pa_lat = 0; + if (pa_stream_get_state(pa_str) == PA_STREAM_READY) { + int negative = 0; - if (pa_stream_get_latency(pa_str, &palat, &negative) >= 0) { - if (negative) { - palat = 0; - } + if (pa_stream_get_latency(pa_str, &pa_lat, &negative) >= 0) { + if (negative) { + pa_lat = 0; } } + } - if (palat > 0) { - latency = double(palat) / 1000000.0; - } - - unlock(); + if (pa_lat > 0) { + latency = double(pa_lat) / 1000000.0; } + unlock(); return latency; } |