Added Performance.AUDIO_OUTPUT_LATENCY

This commit is contained in:
Marcelo Fernandez 2018-07-16 22:43:47 -03:00
parent e1f2feec2e
commit 3930e755e4
4 changed files with 20 additions and 0 deletions

View file

@ -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,
};

View file

@ -77,6 +77,7 @@ public:
PHYSICS_3D_COLLISION_PAIRS,
PHYSICS_3D_ISLAND_COUNT,
//physics
AUDIO_OUTPUT_LATENCY,
MONITOR_MAX
};

View file

@ -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() {

View file

@ -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();
};