resample: tweak the resampler to keep delay number of samples

Instead of requiring the upstream node to resubmit the delayed
samples, keep the samples ourselves. The benefit is probably too
small to measure but it simplifies things a lot.
This commit is contained in:
Wim Taymans 2021-01-08 16:35:26 +01:00
parent 84eed9ef6f
commit 7f007b6bca
3 changed files with 12 additions and 12 deletions

View file

@ -1074,8 +1074,7 @@ static snd_pcm_uframes_t
push_frames(struct state *state,
const snd_pcm_channel_area_t *my_areas,
snd_pcm_uframes_t offset,
snd_pcm_uframes_t frames,
snd_pcm_uframes_t keep)
snd_pcm_uframes_t frames)
{
snd_pcm_uframes_t total_frames = 0;
@ -1134,9 +1133,7 @@ push_frames(struct state *state,
}
spa_list_append(&state->ready, &b->link);
}
if (my_areas == NULL)
snd_pcm_rewind(state->hndl, keep);
return total_frames - keep;
return total_frames;
}
@ -1217,7 +1214,7 @@ int spa_alsa_read(struct state *state, snd_pcm_uframes_t silence)
offset = 0;
}
read = push_frames(state, my_areas, offset, frames, state->delay);
read = push_frames(state, my_areas, offset, frames);
total_read += read;

View file

@ -226,7 +226,7 @@ static void impl_native_process(struct resample *r,
if (SPA_LIKELY(hist)) {
/* first work on the history if any. */
if (SPA_UNLIKELY(hist < n_taps)) {
if (SPA_UNLIKELY(hist <= n_taps)) {
/* we need at least n_taps to completely process the
* history before we can work on the new input. When
* we have less, refill the history. */
@ -265,7 +265,7 @@ static void impl_native_process(struct resample *r,
r, *in_len, in, *out_len, out);
remain = *in_len - skip - in;
if (remain > 0 && remain < n_taps) {
if (remain > 0 && remain <= n_taps) {
/* not enough input data remaining for more output,
* copy to history */
for (c = 0; c < r->channels; c++)

View file

@ -802,11 +802,15 @@ static int impl_node_process(void *object)
switch (this->mode) {
case MODE_SPLIT:
/* in split mode we need to output exactly the size of the
* duration so we don't try to flush early */
maxsize = SPA_MIN(maxsize, max * sizeof(float));
flush_out = flush_in = this->io_rate_match != NULL;
flush_out = false;
break;
case MODE_MERGE:
default:
/* in merge mode we consume one duration of samples and
* always output the resulting data */
flush_out = true;
break;
}
@ -873,11 +877,10 @@ static int impl_node_process(void *object)
}
if (this->io_rate_match) {
if (SPA_FLAG_IS_SET(this->io_rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE)) {
if (SPA_FLAG_IS_SET(this->io_rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE))
resample_update_rate(&this->resample, this->io_rate_match->rate);
} else {
else
resample_update_rate(&this->resample, 1.0);
}
this->io_rate_match->delay = resample_delay(&this->resample);
this->io_rate_match->size = resample_in_len(&this->resample, max);
}