From 8332d3e3edba34b8b0706359085e4750705c8f12 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 15 Sep 2020 13:16:31 +0200 Subject: [PATCH] alsa: don't change the resampler delay value Don't change the resampler delay value, we need it to make sure we keep samples around for the next round. With small period sizes, we set the delay to 0 and mess up the resampler and cause dropouts and clicking. Fixes #287 --- spa/plugins/alsa/alsa-pcm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 932244e7c..78c4a3f7a 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -664,7 +664,6 @@ static int alsa_recover(struct state *state, int err) state->alsa_started = false; spa_alsa_write(state, state->threshold * 2); } - return 0; } @@ -688,6 +687,7 @@ static int get_status(struct state *state, snd_pcm_uframes_t *delay, snd_pcm_ufr *target = state->last_threshold; +#define MARGIN 48 if (state->resample && state->rate_match) { state->delay = state->rate_match->delay * 2; state->read_size = state->rate_match->size; @@ -695,9 +695,10 @@ static int get_status(struct state *state, snd_pcm_uframes_t *delay, snd_pcm_ufr * by moving a little closer to the device read/write pointers. * Don't try to get closer than 48 samples but instead increase the * reported latency on the port (TODO). */ - if (*target <= state->delay + 48) - state->delay = SPA_MAX(0, (int)(*target - 48 - state->delay)); - *target -= state->delay; + if (*target <= state->delay + MARGIN) + *target -= SPA_MAX(0, (int)(*target - MARGIN - state->delay)); + else + *target -= state->delay; } else { state->delay = state->read_size = 0; } @@ -1290,6 +1291,7 @@ int spa_alsa_start(struct state *state) reset_buffers(state); state->alsa_sync = true; + state->alsa_recovering = false; if (state->stream == SND_PCM_STREAM_PLAYBACK) { state->alsa_started = false;