Commit graph

29 commits

Author SHA1 Message Date
Pauli Virtanen
28393cb896 audioconvert: add log topic for resampler 2025-09-07 18:26:03 +00:00
Pauli Virtanen
847982eb0e resample: keep fractional part of in_rate when interpolating
When interpolating with rate correction != 1.0, don't floor the
resulting input rate to the nearest smallest integer.

This allows rate corrections < 1/in_rate to have some effect, and
reduces jumps in the response. One of the jumps is inconveniently
between rate=1.0 and rate=1.0+eps and will cause rate corrections to
oscillate if target rate varies close to 1.0.
2025-07-30 07:59:52 +00:00
Pauli Virtanen
244d5a1cc1 resample: use fixed point for resample phase and input rate
If phase is float, calculations in impl_native_in_len/out_len can
produce wrong results due to rounding error.

It's probably better to not be in the business of predicting
floating-point rounding, so replace this by fixed-point arithmetic.

Also make sure `offset+1` cannot overflow data->filter array in
do_resample_inter* due to float multiplication possibly rounding up.
2025-07-30 07:59:52 +00:00
Wim Taymans
0b0912cc5b resample: optimize phase scaling
Precalculate the constant factor to avoid a division for each sample.
2025-07-23 14:11:11 +02:00
Wim Taymans
d2a9141913 resample: avoid calculating GCD in rate updates
We don't actually need to calculate the GCD for each resampler rate
update. The GCD is only used to scale the in/out rates when using the
full resampler and this we can cache and reuse when we did the setup.

The interpolating resampler can work perfectly fine with a GCD of 1 and
so we can just assume that.
2025-07-23 12:23:20 +02:00
Wim Taymans
fb2b314660 audioconvert: interchange the resampler loops
Iterate the channels in the inner loop instead of the outer loop. This
makes it handle with 0 channels better but also does the more
complicated phase increment code only once for all channels. Also the
filters might stay in the cache for each channel now.
2024-10-30 13:31:24 +01:00
Wim Taymans
1ae4374ccf Fix compilation with -Werror=float-conversion
Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
2024-06-18 12:17:56 +02:00
Dimitrios Katsaros
77f6c009c1 resample: use a float phase in update_rate
My making the phase into a float, the resampler can do finer grained
adjustments, which should improve the stability of adaptive
resampling
2024-02-16 20:08:18 +00:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
4c3f56fca1 resample: cleanup the resampler core functions
Move the increment function to a macro.
Don't use extra local variables, we can just as well call the resample
functipon with them.
2022-11-20 16:19:24 +01:00
Wim Taymans
51f4f1fb69 audioconvert: expose the selected function names
And debug them.
2022-06-28 16:50:14 +02:00
Wim Taymans
0d1cef6b3a audioconvert: move some things around
To make it easier to add other implementations later.
Improve selection of resampler function
2020-04-03 18:03:42 +02:00
Wim Taymans
67a5dd35be resample: add neon optimizations 2020-03-27 08:27:11 -04:00
Wim Taymans
7267a6bc34 resample: remove old debug variable 2020-02-13 20:11:39 +01:00
Wim Taymans
761119f640 resample: fix start position of new samples
When we finished processing the history it might be possible that we
need to skip some samples from the input. Implement this by adding
a start offset for the samples in the buffer.
2020-02-13 16:43:06 +01:00
Wim Taymans
e04d58ee3a Improve some debug 2019-10-02 18:02:07 +02:00
Wim Taymans
a232e67dd8 resample: completely fill resampler
start with a completely filled resampler so that the first
input byte immediately gives an output sample. When then have
n_taps/2 leading (almost) 0 samples.

Also make the passthrough resampler act like the real resampler
by introducing an n_taps/2 delay.
2019-09-05 13:13:20 +02:00
Wim Taymans
595dc0ab5b resample: fix phase calculation 2019-07-09 16:54:52 +02:00
Wim Taymans
0154e6eaac small cleanups
resample: remove unused index variable
2019-07-08 18:23:22 +02:00
Wim Taymans
636c02d38b audioconvert: fix native variable rate resampler 2019-04-30 15:14:05 +02:00
Wim Taymans
dc01b294a2 resample: return the number of consumed samples
We need to return the number of consumed samples, even when we don't
start from the first sample in the buffer.
Add some more logging.
2019-04-02 23:06:46 +02:00
Wim Taymans
d47353c0e6 resample-native: small tweaks 2019-03-29 12:08:45 +01:00
Wim Taymans
d260cb19be audioconvert: compile c version separately
Also compile the c versions in a separate module with their own
flags.
2019-03-28 21:07:53 +01:00
Wim Taymans
e7ef13e310 audioconvert: add avx optimizations 2019-03-28 16:45:57 +01:00
Wim Taymans
c8d3d475bb audioconvert: handle more optimizations
Compile an optimized library for the given CPU with the right flags,
then link it with the main library.
2019-03-27 17:58:48 +01:00
Wim Taymans
eaffb25cc2 resample-native: optimize equal input and output sample rates 2019-03-27 13:38:34 +01:00
Wim Taymans
4fafd10a89 resample-native: cleanups
Add some comments, reorganize for better readability
More alignment of filter and history
Add some more test
2019-03-27 11:23:52 +01:00
Wim Taymans
555fe2f9f5 resample-native: implement variable rate 2019-03-26 17:25:14 +01:00
Wim Taymans
9c8913437b audioconvert: add simple and faster resampler
Add a sinc based resampler that, unlike speex, avoids memcpy and
works directly on the source data. It also allows for ssse3
optimizations and aligned loads. It will later switch to table
interpolation when doing variable rate.
2019-03-26 12:58:26 +01:00