diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-04-14 00:02:47 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-04-14 00:02:47 +0200 |
commit | 2692a7d22c0b691f7f27f969c91e7af05c8ede7d (patch) | |
tree | 3697649ab946e53be25e0f157e1e70f3bc77b5f1 /src/main.cpp | |
parent | 24c13ceaab1ea2ef026d6d94558d703ab8bebe82 (diff) |
Testing audio latency compensation
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5aacd8b..eb90e91 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2417,12 +2417,15 @@ int main(int argc, char **argv) { while(running) { void *sound_buffer; int sound_buffer_size = -1; + double latency_seconds = 0.0; + const double time_before_read = clock_get_monotonic_seconds(); if(audio_device.sound_device.handle) - sound_buffer_size = sound_device_read_next_chunk(&audio_device.sound_device, &sound_buffer, timeout_sec); + sound_buffer_size = sound_device_read_next_chunk(&audio_device.sound_device, &sound_buffer, 1.0, &latency_seconds); const bool got_audio_data = sound_buffer_size >= 0; - - const double this_audio_frame_time = clock_get_monotonic_seconds() - paused_time_offset; + const double time_after_read = clock_get_monotonic_seconds(); + latency_seconds = time_after_read - time_before_read; // TODO: Remove this + const double this_audio_frame_time = (time_after_read - paused_time_offset) - latency_seconds; if(paused) { if(got_audio_data) |