diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-04-15 20:30:41 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-04-15 20:30:41 +0200 |
commit | 7e239c8aa289bbe71bcbb0bcc5908ca02cee4861 (patch) | |
tree | fda770d5c0bacfe1db4d5593174fa0b4fcfe9299 /src/main.cpp | |
parent | 21a2e3c3fa7f91e06a8cfd0b1d3920e2c6083ff5 (diff) |
Test latency comp
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5aacd8b..c716e47 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2417,12 +2417,17 @@ int main(int argc, char **argv) { while(running) { void *sound_buffer; int sound_buffer_size = -1; - if(audio_device.sound_device.handle) - sound_buffer_size = sound_device_read_next_chunk(&audio_device.sound_device, &sound_buffer, timeout_sec); + const double time_before_read_seconds = clock_get_monotonic_seconds(); + if(audio_device.sound_device.handle) { + // TODO: use this instead of calculating time to read. But this can fluctuate and we dont want to go back in time + double latency_seconds = 0.0; + sound_buffer_size = sound_device_read_next_chunk(&audio_device.sound_device, &sound_buffer, timeout_sec, &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_seconds = clock_get_monotonic_seconds(); + const double time_to_read_seconds = time_after_read_seconds - time_before_read_seconds; + const double this_audio_frame_time = time_after_read_seconds - paused_time_offset - time_to_read_seconds; if(paused) { if(got_audio_data) |