Skip to content

Display and control your Android device

Store compensation state as a boolean

Romain Vimont5936167ff77b
diff --git a/app/src/audio_regulator.c b/app/src/audio_regulator.c
index fb0c3758..3e4f78ad 100644
--- a/app/src/audio_regulator.c
+++ b/app/src/audio_regulator.c
@@ -288,7 +288,7 @@ sc_audio_regulator_push(struct sc_audio_regulator *ar, const AVFrame *frame) {
// Enable compensation when the difference exceeds +/- 4ms.
// Disable compensation when the difference is lower than +/- 1ms.
- int threshold = ar->compensation != 0
+ int threshold = ar->compensation_active
? ar->sample_rate / 1000 /* 1ms */
: ar->sample_rate * 4 / 1000; /* 4ms */
@@ -314,7 +314,7 @@ sc_audio_regulator_push(struct sc_audio_regulator *ar, const AVFrame *frame) {
LOGW("Resampling compensation failed: %d", ret);
// not fatal
} else {
- ar->compensation = diff;
+ ar->compensation_active = diff != 0;
}
}
@@ -390,7 +390,7 @@ sc_audio_regulator_init(struct sc_audio_regulator *ar, size_t sample_size,
atomic_init(&ar->played, false);
atomic_init(&ar->received, false);
atomic_init(&ar->underflow, 0);
- ar->compensation = 0;
+ ar->compensation_active = false;
return true;
diff --git a/app/src/audio_regulator.h b/app/src/audio_regulator.h
index 7daa1b05..1c0eeb9f 100644
--- a/app/src/audio_regulator.h
+++ b/app/src/audio_regulator.h
@@ -44,8 +44,8 @@ struct sc_audio_regulator {
// Number of silence samples inserted since the last received packet
atomic_uint_least32_t underflow;
- // Current applied compensation value (only used by the receiver thread)
- int compensation;
+ // Non-zero compensation applied (only used by the receiver thread)
+ bool compensation_active;
// Set to true the first time a sample is received
atomic_bool received;