diff --git a/spa/plugins/audioconvert/resample-native.c b/spa/plugins/audioconvert/resample-native.c index 85bdc4cf2..f393e3dce 100644 --- a/spa/plugins/audioconvert/resample-native.c +++ b/spa/plugins/audioconvert/resample-native.c @@ -315,29 +315,26 @@ static uint32_t impl_native_delay (struct resample *r) return d->n_taps / 2 - 1; } -static int32_t impl_native_phase_ns(struct resample *r) +static float impl_native_phase (struct resample *r) { struct native_data *d = r->data; + float pho = 0; if (d->func == d->info->process_full) { - float pho = -(float)((int32_t)d->phase) / d->out_rate; + pho = -(float)((int32_t)d->phase) / d->out_rate; /* XXX: this is how it seems to behave, but not clear why */ if (d->hist >= d->n_taps - 1) pho += 1.0f; - - return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate); } else if (d->func == d->info->process_inter) { - float pho = -d->phase / d->out_rate; + pho = -d->phase / d->out_rate; /* XXX: this is how it seems to behave, but not clear why */ if (d->hist >= d->n_taps - 1) pho += 1.0f; - - return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate); } - return 0; + return pho; } int resample_native_init(struct resample *r) @@ -356,7 +353,7 @@ int resample_native_init(struct resample *r) r->process = impl_native_process; r->reset = impl_native_reset; r->delay = impl_native_delay; - r->phase_ns = impl_native_phase_ns; + r->phase = impl_native_phase; q = &window_qualities[r->quality]; diff --git a/spa/plugins/audioconvert/resample-peaks.c b/spa/plugins/audioconvert/resample-peaks.c index 431260b5c..aade7711e 100644 --- a/spa/plugins/audioconvert/resample-peaks.c +++ b/spa/plugins/audioconvert/resample-peaks.c @@ -100,7 +100,7 @@ static void impl_peaks_reset (struct resample *r) d->i_count = d->o_count = 0; } -static int32_t impl_peaks_phase_ns (struct resample *r) +static float impl_peaks_phase (struct resample *r) { return 0; } @@ -130,7 +130,7 @@ int resample_peaks_init(struct resample *r) r->delay = impl_peaks_delay; r->in_len = impl_peaks_in_len; r->out_len = impl_peaks_out_len; - r->phase_ns = impl_peaks_phase_ns; + r->phase = impl_peaks_phase; spa_log_debug(r->log, "peaks %p: in:%d out:%d features:%08x:%08x", r, r->i_rate, r->o_rate, r->cpu_flags, d->peaks.cpu_flags); diff --git a/spa/plugins/audioconvert/resample.h b/spa/plugins/audioconvert/resample.h index 86c48adc8..5308fa828 100644 --- a/spa/plugins/audioconvert/resample.h +++ b/spa/plugins/audioconvert/resample.h @@ -32,7 +32,10 @@ struct resample { void * SPA_RESTRICT dst[], uint32_t *out_len); void (*reset) (struct resample *r); uint32_t (*delay) (struct resample *r); - int32_t (*phase_ns) (struct resample *r); + + /** Fractional part of delay (in input samples) */ + float (*phase) (struct resample *r); + void *data; }; @@ -43,7 +46,7 @@ struct resample { #define resample_process(r,...) (r)->process(r,__VA_ARGS__) #define resample_reset(r) (r)->reset(r) #define resample_delay(r) (r)->delay(r) -#define resample_phase_ns(r) (r)->phase_ns(r) +#define resample_phase(r) (r)->phase(r) int resample_native_init(struct resample *r); int resample_peaks_init(struct resample *r); diff --git a/spa/plugins/audioconvert/test-resample-delay.c b/spa/plugins/audioconvert/test-resample-delay.c index 93da2300d..91a04a5ac 100644 --- a/spa/plugins/audioconvert/test-resample-delay.c +++ b/spa/plugins/audioconvert/test-resample-delay.c @@ -222,7 +222,7 @@ static void check_delay(double rate, uint32_t out_rate, uint32_t options) feed_sine(&r, 512, &in, &in_phase, false); /* Test delay */ - expect = resample_delay(&r) + (double)resample_phase_ns(&r) * 48000 / SPA_NSEC_PER_SEC; + expect = resample_delay(&r) + (double)resample_phase(&r); out = feed_sine(&r, 256, &in, &in_phase, true); got = find_delay(samp_in, in, samp_out, out, out_rate / 48000.0, 100, tol); @@ -295,7 +295,7 @@ static void check_delay_vary_rate(double rate, double end_rate, uint32_t out_rat feed_sine(&r, 255, &in, &in_phase, false); /* Test delay */ - expect = (double)resample_delay(&r) + (double)resample_phase_ns(&r) * 48000 / SPA_NSEC_PER_SEC; + expect = (double)resample_delay(&r) + (double)resample_phase(&r); out = feed_sine(&r, 256, &in, &in_phase, true); got = find_delay(samp_in, in, samp_out, out, out_rate/48000.0, 100, tol); @@ -360,7 +360,7 @@ static void run(uint32_t in_rate, uint32_t out_rate, double end_rate, double mid feed_sine(&r, 255, &in, &in_phase, true); /* Test delay */ - expect = (double)resample_delay(&r) + (double)resample_phase_ns(&r) * (double)in_rate / SPA_NSEC_PER_SEC; + expect = (double)resample_delay(&r) + (double)resample_phase(&r); out = feed_sine(&r, 256, &in, &in_phase, true); got = find_delay(samp_in, in, samp_out, out, ((double)out_rate)/in_rate, 100, tol);