libsndfile / libsamplerate

An audio Sample Rate Conversion library
http://libsndfile.github.io/libsamplerate/
BSD 2-Clause "Simplified" License
600 stars 167 forks source link

No anti-aliasing filter for linear resampling #182

Closed jpaasen closed 1 year ago

jpaasen commented 1 year ago

There is no anti-aliasing filter applied for the Linear resampling mode.

So if you create the following chirp:

chirp_stft_targetfs_48000_nmels256_hop480_win1024_fft1024_stft_targetfs48000_hop480_win1024_fft1024

and you resample (down) with Linear you get:

chirp_stft_targetfs_16000_nmels256_hop160_win1024_fft1024_stft_targetfs16000_hop160_win1024_fft1024

This might be intentional, but it is not straightforward from the documentation that this is the case.

The documentation says:

SRC_SINC_FASTEST - This is the fastest bandlimited interpolator and has an SNR of 97dB and a bandwidth of 80%.
SRC_ZERO_ORDER_HOLD - A Zero Order Hold converter (interpolated value is equal to the last value). The quality is poor but the conversion speed is blindlingly fast.
SRC_LINEAR - A linear converter. Again the quality is poor, but the conversion speed is blindingly fast.

The line This is the fastest bandlimited interpolator for SRC_SINC_FASTEST implies that the latter two options are not band-limited.

The documentation could be improved with a line or two, stating the latter two options should NOT be used without the user taking care of the anti-aliasing filtering him/herself.

If you downsample using SRC_SINC_FASTEST. libsamplerate takes care of the anti-aliasing filtering: chirp_sinc_fastest_stft_targetfs_16000_nmels256_hop160_win1024_fft1024_stft_targetfs16000_hop160_win1024_fft1024

evpobr commented 1 year ago

Hi @jpaasen . Pull request?

jpaasen commented 1 year ago

I can do a PR with improvements to the doc. I just wanted to establish if this behavior was intentional or not.

Looking at librosa.resample, that exposes libsamplerate for some of its supported res_type values, there are no warnings about using ‘linear’ for down-sampling. So the misconception seems "widespread".

evpobr commented 1 year ago

We need to ask @erikd. But he doesn't answer.

erikd commented 1 year ago

The linear sample rate converter is provided for completeness and for something to compare actually good converters against.

If you want sample rate conversion without aliasing, then used the SRC_SINC_* converters.

evpobr commented 1 year ago

Hi @erikd :smile: