Skip to content

Display and control your Android device

Apply new compensation only if it changed

Romain Vimont0bf866fa8d98
diff --git a/app/src/audio_player.c b/app/src/audio_player.c
index aa34c316..0511ec1f 100644
--- a/app/src/audio_player.c
+++ b/app/src/audio_player.c
@@ -258,10 +258,15 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink,
LOGV("[Audio] Buffering: target=%" PRIu32 " avg=%f cur=%" PRIu32
" compensation=%d", ap->target_buffering, avg,
buffered_samples, diff);
- int ret = swr_set_compensation(swr_ctx, diff, distance);
- if (ret < 0) {
- LOGW("Resampling compensation failed: %d", ret);
- // not fatal
+
+ if (diff != ap->compensation) {
+ int ret = swr_set_compensation(swr_ctx, diff, distance);
+ if (ret < 0) {
+ LOGW("Resampling compensation failed: %d", ret);
+ // not fatal
+ } else {
+ ap->compensation = diff;
+ }
}
}
}
@@ -369,6 +374,7 @@ sc_audio_player_frame_sink_open(struct sc_frame_sink *sink,
ap->received = false;
ap->played = false;
ap->underflow = 0;
+ ap->compensation = 0;
// The thread calling open() is the thread calling push(), which fills the
// audio buffer consumed by the SDL audio thread.
diff --git a/app/src/audio_player.h b/app/src/audio_player.h
index 3227f2fe..4dd9c4dc 100644
--- a/app/src/audio_player.h
+++ b/app/src/audio_player.h
@@ -60,6 +60,9 @@ struct sc_audio_player {
// (protected by SDL_AudioDeviceLock())
uint32_t underflow;
+ // Current applied compensation value (only used by the receiver thread)
+ int compensation;
+
// Set to true the first time a sample is received (protected by
// SDL_AudioDeviceLock())
bool received;