Store compensation state as a boolean
We don't need to store the last compensation value anymore, we just need to know if it's non-zero.
This commit is contained in:
parent
e9dd0f68ad
commit
5936167ff7
@ -288,7 +288,7 @@ sc_audio_regulator_push(struct sc_audio_regulator *ar, const AVFrame *frame) {
|
|||||||
|
|
||||||
// Enable compensation when the difference exceeds +/- 4ms.
|
// Enable compensation when the difference exceeds +/- 4ms.
|
||||||
// Disable compensation when the difference is lower than +/- 1ms.
|
// 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 / 1000 /* 1ms */
|
||||||
: ar->sample_rate * 4 / 1000; /* 4ms */
|
: 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);
|
LOGW("Resampling compensation failed: %d", ret);
|
||||||
// not fatal
|
// not fatal
|
||||||
} else {
|
} 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->played, false);
|
||||||
atomic_init(&ar->received, false);
|
atomic_init(&ar->received, false);
|
||||||
atomic_init(&ar->underflow, 0);
|
atomic_init(&ar->underflow, 0);
|
||||||
ar->compensation = 0;
|
ar->compensation_active = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ struct sc_audio_regulator {
|
|||||||
// Number of silence samples inserted since the last received packet
|
// Number of silence samples inserted since the last received packet
|
||||||
atomic_uint_least32_t underflow;
|
atomic_uint_least32_t underflow;
|
||||||
|
|
||||||
// Current applied compensation value (only used by the receiver thread)
|
// Non-zero compensation applied (only used by the receiver thread)
|
||||||
int compensation;
|
bool compensation_active;
|
||||||
|
|
||||||
// Set to true the first time a sample is received
|
// Set to true the first time a sample is received
|
||||||
atomic_bool received;
|
atomic_bool received;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user