From e9dd0f68adc59bae67f04bc859a8287785771ace Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 4 Nov 2024 23:06:19 +0100 Subject: [PATCH] Fix audio regulator compensation A call to swr_set_compensation() configures the resampler to drop or duplicate "diff" samples over an interval of "distance" samples. If the function is not called again, then after "distance" samples, no more compensation will be applied. So it must always be called, even if the new computed diff value happens to be the same as the previous one. In practice, it is unlikely that the diff value is exactly the same every second, except when it is actively clamped (to 2% of the sample rate). --- app/src/audio_regulator.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/audio_regulator.c b/app/src/audio_regulator.c index 911b2bfa..fb0c3758 100644 --- a/app/src/audio_regulator.c +++ b/app/src/audio_regulator.c @@ -309,14 +309,12 @@ sc_audio_regulator_push(struct sc_audio_regulator *ar, const AVFrame *frame) { LOGV("[Audio] Buffering: target=%" PRIu32 " avg=%f cur=%" PRIu32 " compensation=%d", ar->target_buffering, avg, can_read, diff); - if (diff != ar->compensation) { - int ret = swr_set_compensation(swr_ctx, diff, distance); - if (ret < 0) { - LOGW("Resampling compensation failed: %d", ret); - // not fatal - } else { - ar->compensation = diff; - } + int ret = swr_set_compensation(swr_ctx, diff, distance); + if (ret < 0) { + LOGW("Resampling compensation failed: %d", ret); + // not fatal + } else { + ar->compensation = diff; } }