summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/performance.cpp5
-rw-r--r--main/performance.h1
-rw-r--r--servers/audio_server.cpp9
-rw-r--r--servers/audio_server.h5
4 files changed, 20 insertions, 0 deletions
diff --git a/main/performance.cpp b/main/performance.cpp
index fc915e2e76..70e0a5f7aa 100644
--- a/main/performance.cpp
+++ b/main/performance.cpp
@@ -32,6 +32,7 @@
#include "message_queue.h"
#include "os/os.h"
#include "scene/main/scene_tree.h"
+#include "servers/audio_server.h"
#include "servers/physics_2d_server.h"
#include "servers/physics_server.h"
#include "servers/visual_server.h"
@@ -68,6 +69,7 @@ void Performance::_bind_methods() {
BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS);
BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS);
BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT);
+ BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY);
BIND_ENUM_CONSTANT(MONITOR_MAX);
}
@@ -104,6 +106,7 @@ String Performance::get_monitor_name(Monitor p_monitor) const {
"physics_3d/active_objects",
"physics_3d/collision_pairs",
"physics_3d/islands",
+ "audio/output_latency",
};
@@ -147,6 +150,7 @@ float Performance::get_monitor(Monitor p_monitor) const {
case PHYSICS_3D_ACTIVE_OBJECTS: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_ACTIVE_OBJECTS);
case PHYSICS_3D_COLLISION_PAIRS: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_COLLISION_PAIRS);
case PHYSICS_3D_ISLAND_COUNT: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_ISLAND_COUNT);
+ case AUDIO_OUTPUT_LATENCY: return AudioServer::get_singleton()->get_output_latency();
default: {}
}
@@ -186,6 +190,7 @@ Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
+ MONITOR_TYPE_TIME,
};
diff --git a/main/performance.h b/main/performance.h
index 464226b517..de00df5ff9 100644
--- a/main/performance.h
+++ b/main/performance.h
@@ -77,6 +77,7 @@ public:
PHYSICS_3D_COLLISION_PAIRS,
PHYSICS_3D_ISLAND_COUNT,
//physics
+ AUDIO_OUTPUT_LATENCY,
MONITOR_MAX
};
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();
};