Downsampling error

I noticed a long time ago there is an error while downsampling tracks, and it still happens to this day on version 3.2.0

Here is an example of what the problem:

This is an audio file that is 44.1kHz
Then here is what it looks like downsampled to 32kHz
As you may notice, in the first image at the 16kHz range, there were no samples missing, but now in the second image there are. I don’t know if it is some setting I have turned on, or if it’s just a problem with Audacity, but if it is the former I would like to know how to fix it.

This isn’t a bug, it’s just the result of resampling to a lower sample rate.

Digital (PCM) audio has a theoretical maximum bandwidth of up to half the sample rate (See:–Shannon_sampling_theorem). When reducing the sample rate, it is essential that the audio is filtered to entirely remove frequencies that are above half the sample rate, but there’s no such thing as a “perfect brick wall filter”. Filters always have a “roll-off slope” (see: Any frequencies that remain above half the sample rate will “bounce back” and create “phantom” tones within the audio range.

Audacity uses a very high quality resampler (“libsoxr”), and has a very steep high-cut filter that kicks in just below half the sample rate. The reason that the filter starts below half the sample rate is to ensure that nothing above half the sample rate gets through.

This graph shows what happens when frequencies above half the sample rate are not fully removed. The brightest line is a sweeping tone that has been resampled from 96 kHz to 44.1 kHz. Notice the red and purple lines that show “phantom” tones that have folded back into the audible range:

This next image shows Audacity 3, resampling from 96 kHz to 44.1 kHz.
Notice that the sweep tone has been cut off just below 22050 Hz, but there are no “phantom” tones. This is significantly better than the first example.


That’s interesting, and I guess I’m glad that happens, I just feel like I see things that are resampled to a lower rate all the time that don’t have missing samples at the top of the spectrum.
Say, what did you use to get the second result? I’m just curious to see what that would sound like.