summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorMax Hilbrunner <mhilbrunner@users.noreply.github.com>2018-07-17 14:37:12 +0200
committerGitHub <noreply@github.com>2018-07-17 14:37:12 +0200
commit044737246b81a09bf97070b9a719b4d0aa303535 (patch)
tree3afca0182485eb224c7a19c4f07e985f0e97da0e /servers
parent1d84c4f870c5ef7c83bdbaa111bb301612a75ebe (diff)
parent3930e755e4642e5705bb00edc1b35bec6077f9dc (diff)
Merge pull request #20215 from marcelofg55/audio_latency
Added Performance.AUDIO_OUTPUT_LATENCY
Diffstat (limited to 'servers')
-rw-r--r--servers/audio_server.cpp9
-rw-r--r--servers/audio_server.h5
2 files changed, 14 insertions, 0 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index f2df7119e7..69c1318a48 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -234,6 +234,13 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {
todo -= to_copy;
to_mix -= to_copy;
}
+
+ // Calculate latency for Performance.AUDIO_OUTPUT_LATENCY
+ if (OS::get_singleton()) {
+ uint64_t ticks = OS::get_singleton()->get_ticks_usec();
+ output_latency = (ticks - output_latency_ticks) / 1000000.f;
+ output_latency_ticks = ticks;
+ }
}
void AudioServer::_mix_step() {
@@ -1178,6 +1185,8 @@ AudioServer::AudioServer() {
mix_frames = 0;
channel_count = 0;
to_mix = 0;
+ output_latency = 0;
+ output_latency_ticks = 0;
}
AudioServer::~AudioServer() {
diff --git a/servers/audio_server.h b/servers/audio_server.h
index b7fcd9c093..f928acc7b5 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -190,6 +190,9 @@ private:
Mutex *audio_data_lock;
+ float output_latency;
+ uint64_t output_latency_ticks;
+
void init_channels_and_buffers();
void _mix_step();
@@ -306,6 +309,8 @@ public:
String get_device();
void set_device(String device);
+ float get_output_latency() { return output_latency; }
+
AudioServer();
virtual ~AudioServer();
};