diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-05-13 19:27:06 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-05-13 19:27:09 +0200 |
commit | 133c3a22b9cf3a55ebda19ce2af6db2e236462f1 (patch) | |
tree | a9e13c2cc25ae4d1e93486cb8f9f3978fe6c7d6f /src | |
parent | 0288b94ecf380b4750395934040eb985ee8fe2a7 (diff) |
Better audio sync for 60 fps
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5f2ede8..1c5024b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1044,18 +1044,20 @@ static void run_recording_saved_script_async(const char *script_file, const char } } -static double audio_codec_get_desired_delay(AudioCodec audio_codec) { +static double audio_codec_get_desired_delay(AudioCodec audio_codec, int fps) { + const double fps_inv = 1.0 / (double)fps; + const double base = 0.01 + 1.0/165.0; switch(audio_codec) { case AudioCodec::OPUS: - return 0.01; + return std::max(0.0, base - fps_inv); case AudioCodec::AAC: - return 0.0185 * 2.0; + return std::max(0.0, (base + 0.008) * 2.0 - fps_inv); case AudioCodec::FLAC: // TODO: Test - return 0.01; + return std::max(0.0, base - fps_inv); } assert(false); - return 0.01; + return std::max(0.0, base - fps_inv); } struct AudioDevice { @@ -2336,7 +2338,7 @@ int main(int argc, char **argv) { const double audio_fps = (double)audio_codec_context->sample_rate / (double)audio_codec_context->frame_size; const double timeout_sec = 1000.0 / audio_fps / 1000.0; - const double audio_startup_time_seconds = force_no_audio_offset ? 0 : audio_codec_get_desired_delay(audio_codec);// * ((double)audio_codec_context->frame_size / 1024.0); + const double audio_startup_time_seconds = force_no_audio_offset ? 0 : audio_codec_get_desired_delay(audio_codec, fps);// * ((double)audio_codec_context->frame_size / 1024.0); const double num_audio_frames_shift = audio_startup_time_seconds / timeout_sec; std::vector<AudioDevice> audio_devices; |