mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
resample: optimize phase scaling
Precalculate the constant factor to avoid a division for each sample.
This commit is contained in:
parent
bacaec1a48
commit
418b7198ee
2 changed files with 7 additions and 6 deletions
|
|
@ -30,6 +30,7 @@ struct native_data {
|
|||
uint32_t in_rate;
|
||||
uint32_t out_rate;
|
||||
float phase;
|
||||
float pm;
|
||||
uint32_t inc;
|
||||
uint32_t frac;
|
||||
uint32_t filter_stride;
|
||||
|
|
@ -85,7 +86,7 @@ DEFINE_RESAMPLER(full,arch) \
|
|||
{ \
|
||||
struct native_data *data = r->data; \
|
||||
uint32_t n_taps = data->n_taps, stride = data->filter_stride_os; \
|
||||
uint32_t index, phase, n_phases = data->out_rate; \
|
||||
uint32_t index, phase, out_rate = data->out_rate; \
|
||||
uint32_t c, o, olen = *out_len, ilen = *in_len; \
|
||||
uint32_t inc = data->inc, frac = data->frac, ch = r->channels; \
|
||||
\
|
||||
|
|
@ -99,7 +100,7 @@ DEFINE_RESAMPLER(full,arch) \
|
|||
inner_product_##arch(&d[o], &s[index], \
|
||||
filter, n_taps); \
|
||||
} \
|
||||
INC(index, phase, n_phases); \
|
||||
INC(index, phase, out_rate); \
|
||||
} \
|
||||
*in_len = index; \
|
||||
*out_len = o; \
|
||||
|
|
@ -111,16 +112,15 @@ DEFINE_RESAMPLER(inter,arch) \
|
|||
{ \
|
||||
struct native_data *data = r->data; \
|
||||
uint32_t index, stride = data->filter_stride; \
|
||||
uint32_t n_phases = data->n_phases, out_rate = data->out_rate; \
|
||||
uint32_t n_taps = data->n_taps; \
|
||||
uint32_t n_taps = data->n_taps, out_rate = data->out_rate; \
|
||||
uint32_t c, o, olen = *out_len, ilen = *in_len; \
|
||||
uint32_t inc = data->inc, frac = data->frac, ch = r->channels; \
|
||||
float phase; \
|
||||
float phase, pm = data->pm; \
|
||||
\
|
||||
index = ioffs; \
|
||||
phase = data->phase; \
|
||||
for (o = ooffs; o < olen && index + n_taps <= ilen; o++) { \
|
||||
float ph = phase * n_phases / out_rate; \
|
||||
float ph = phase * pm; \
|
||||
uint32_t offset = (uint32_t)floorf(ph); \
|
||||
float *filter0 = &data->filter[(offset+0) * stride]; \
|
||||
float *filter1 = &data->filter[(offset+1) * stride]; \
|
||||
|
|
|
|||
|
|
@ -362,6 +362,7 @@ int resample_native_init(struct resample *r)
|
|||
d->in_rate = in_rate;
|
||||
d->out_rate = out_rate;
|
||||
d->gcd = gcd;
|
||||
d->pm = (float)n_phases / r->o_rate;
|
||||
d->filter = SPA_PTROFF_ALIGN(d, sizeof(struct native_data), 64, float);
|
||||
d->hist_mem = SPA_PTROFF_ALIGN(d->filter, filter_size, 64, float);
|
||||
d->history = SPA_PTROFF(d->hist_mem, history_size, float*);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue