Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[not for merge] Resampler low pass prototype #655

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

PetrGlad
Copy link
Collaborator

@PetrGlad PetrGlad commented Dec 7, 2024

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

luckily we already have a low_pass filter, see:
https://docs.rs/rodio/latest/rodio/source/trait.Source.html#method.low_pass

@PetrGlad
Copy link
Collaborator Author

PetrGlad commented Dec 19, 2024

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 blt module.

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.

@PetrGlad
Copy link
Collaborator Author

PetrGlad commented Dec 19, 2024

I executed the test with mp3 sample from #584 (comment) . 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:
Screenshot from 2024-12-19 23-05-21

With simple low pass:
Screenshot from 2024-12-19 23-05-35
I cannot se any meaningful differences here.

With pre-upsampled simple low pass:
Screenshot from 2024-12-19 23-05-49
The rejection is better but there are 2 strange spikes.

With bi-quad filter:
Screenshot from 2024-12-19 23-06-10
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.

@PetrGlad PetrGlad marked this pull request as draft December 19, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants