[not for merge] Resampler low pass prototype
For a context, we plan to introduce a high quality resampler (#647). This change is an attempt to maybe also improve existing default resampler by keeping it light but improving its sound quality slightly.
Here are some resampler changes prototype that I wanted trying. See low_pass::tests::test_low_pass, if this will be deemed sufficiently good, down-sampling step can be optimized (just use decimation).
I would like to have some objective evidence on how it performs, probably need some test harness for that. Or someone with better ears could listen to the output to compare asses it subjectively.
The low pass filter there is primitive has very slope edge, has cut-off frequency at about sample rate / 2 and may distort audio by boosting lows so the audio is up-sampled to 2 x target frequency first, and output is amplified by 0.5.
Low pass filter can be improved, but that will be slower as well. Maybe there are some people who are experienced in DSP so suggest better quick fix ideas.
I have added the prototypes into src/conversions/sample_raters tests, see conversions::sample_rate::test::resampler_tweaks(). You can play with the implementation and the input parameters. The test runs 4 re-sampler versions and stores output to a wav file. The versions tested:
- Bare existing implementation, for comparison.
- With primitive low-pass filter.
- With primitive low pass filter but with 2x up-sampling before filtering
- With existing bi-quad filter from
bltmodule.
I hoped that primitive filter although not being good still can make meaningful difference. This does not seem to be the case. bi-quad filter is better in quality but it always uses f32 and its algorithm is somewhat heavier.
// I wonder if we should add a chirp (frequency sweep) signal to be used in testing.
I executed the test with mp3 sample from https://github.com/RustAudio/rodio/issues/584#issuecomment-2158487695 . Note that the input mp3 has 24kHz sample rate so ideally even after resampling there should not be any frequencies above 12KHz. Moreover actual highest frequency in the input file is ~8.5KHz.Here are my results:
Existing implementation:
With simple low pass:
I cannot se any meaningful differences here.
With pre-upsampled simple low pass:
The rejection is better but there are 2 strange spikes.
With bi-quad filter:
This one leaves some aliasing but the rejection seem to be good.
I can only rely on spectrograms here, so if anyone is interested in having a better resampler in rodio is welcome to try this with your inputs.