diff --git a/app/src/audio_player.c b/app/src/audio_player.c index ea44e8d9..bd799c51 100644 --- a/app/src/audio_player.c +++ b/app/src/audio_player.c @@ -266,6 +266,16 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink, // The compensation must apply instantly, it must not be smoothed ap->avg_buffering.avg += instant_compensation + inserted_silence - dropped; + if (ap->avg_buffering.avg < 0) { + // Since dropping samples instantly reduces buffering, the difference + // is applied immediately to the average value, assuming that the delay + // between the producer and the consumer will be caught up. + // + // However, when this assumption is not valid, the average buffering + // may decrease indefinitely. Prevent it to become negative to limit + // the consequences. + ap->avg_buffering.avg = 0; + } // However, the buffering level must be smoothed sc_average_push(&ap->avg_buffering, can_read);