mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-03-14 05:34:06 -04:00
audioconvert: resampler: fix off-by-one issues
Resampler without prefill was sometime outputting with different delay than with prefill. Adjust initial history by 1 which seems to bring it more in line. The resampler phase also appears to depend on how many samples remain in history which leads to possibly unexpected +-1 variation. Take this into account in reported phase. These changes make the resampler delay tests pass. Both changes are sort of empirical --- I don't fully understand why these would fix things but they seem to be needed to make the delay calculations agree with what the resampler outputs.
This commit is contained in:
parent
79384530b5
commit
eb91f097d9
1 changed files with 7 additions and 3 deletions
|
|
@ -305,7 +305,7 @@ static void impl_native_reset (struct resample *r)
|
||||||
if (r->options & RESAMPLE_OPTION_PREFILL)
|
if (r->options & RESAMPLE_OPTION_PREFILL)
|
||||||
d->hist = d->n_taps - 1;
|
d->hist = d->n_taps - 1;
|
||||||
else
|
else
|
||||||
d->hist = (d->n_taps / 2) - 1;
|
d->hist = d->n_taps / 2;
|
||||||
d->phase = 0;
|
d->phase = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,14 +322,18 @@ static int32_t impl_native_phase_ns(struct resample *r)
|
||||||
if (d->func == d->info->process_full) {
|
if (d->func == d->info->process_full) {
|
||||||
float pho = -(float)((int32_t)d->phase) / d->out_rate;
|
float pho = -(float)((int32_t)d->phase) / d->out_rate;
|
||||||
|
|
||||||
if (pho != 0.0f)
|
/* XXX: this is how it seems to behave, but not clear why */
|
||||||
|
if (d->hist >= d->n_taps - 1)
|
||||||
pho += 1.0f;
|
pho += 1.0f;
|
||||||
|
|
||||||
return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate);
|
return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate);
|
||||||
} else if (d->func == d->info->process_inter) {
|
} else if (d->func == d->info->process_inter) {
|
||||||
float pho = -d->phase / d->out_rate;
|
float pho = -d->phase / d->out_rate;
|
||||||
|
|
||||||
if (pho != 0.0f)
|
/* XXX: this is how it seems to behave, but not clear why */
|
||||||
|
if (d->hist >= d->n_taps - 1)
|
||||||
pho += 1.0f;
|
pho += 1.0f;
|
||||||
|
|
||||||
return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate);
|
return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue