# Sampling a low-frequency sound doesn't work at some sampling rates

When sampling a low-frequency sound (like a 55Hz sine wave) I hear an additional high frequency sound at certain sampling rates, but not at others. This happens in Audacity and in my own program. For example, I hear both a low and a high pitch when sampling at 44,100 Hz, but only a low pitch when sampling at 48,000 Hz. What could this be?

More information:

The high frequencies are present for other input frequencies and it's not dependent on amplitude.

I'm sampling the sine wave using the standard sin() function in C++:

for( int i = 0; i < N; i++ )
{
float time = float(i) / float(samples_per_second);
output[i] = sin( 2*pi * 55 * time ) * 0.5;
}


Not sure how Audacity is doing it. With Audacity I generate a sine tone, and then changing just the project's sampling rate will make the high pitch appear/disappear.

The same thing happens playing back a bass drum sound (in Audacity and my program). I sample it just by indexing into a table loaded from a .wav file.

Even more information:

I noticed that the high frequency artifact sounds the same as sampling at a different rate with no interpolation, like this:

float in_idx = 0.0f;
for( int out_idx = 0; out_idx < N; out_idx++ )
{
output[out_idx] = input[ int(in_idx) ];
in_idx += 44100.0f / 48000.0f;
}


So maybe Windows or the driver or the hardware are deciding not to use interpolation for some reason.

• How are you sampling the sound? Are the high frequency tones present for other input frequencies? Is there any dependence on the amplitude of the 55 Hz signal? One possibility is that your ADC is clipping, which introduces harmonics.
– MBaz
Sep 5 '20 at 1:41
• @MBaz I updated the question.
– KTC
Sep 5 '20 at 3:52

## 3 Answers

Could be a few things

1. You may be borderline clipping. Your sine wave has an amplitude of 1, which is just at the edge of clipping (depending on how its rendered). Try it with an amplitude of 0.5
2. Your hardware is sloppy. For example, cheap laptop sound cards often cut corners in the anti aliasing filters and or clipping management
3. Your operating system is poorly configured, particular if you use Windows. If you change sample rate in the project, it may just trigger the operating system to do sample rate conversion. If the sound card only supports 48 kHz natively, the OS will up-convert 44.1 kHz to 48 kHz and the quality of the sample rate converter can be fairly bad. On Windows all audio goes through the kernel mixer (unless you specifically bypass it) and that often messes with the audio as well.
4. Driver problem. The interface between the OS and the sound card could be sloppy.
• If #3 is the prolem, and the audio device natively supports the 44100 Hz sample rate, then one can choose that in the driver settings. See answers.microsoft.com/en-us/windows/forum/… Sep 5 '20 at 8:16
• I forgot to mention in my question that I am using an amplitude smaller than 1. So I suppose it's #2, #3, and/or #4. Changing the sampling rate in the device properties in Windows does remove the artifact, but I'm not sure if it's a problem with Windows, the driver, or the hardware.
– KTC
Sep 5 '20 at 20:28
• I updated my question.
– KTC
Sep 5 '20 at 20:40

That's is most probably because the filtering post sampling is not adequate. After sampling you would repetitions of the frequency spectrum of the sinusoid, which need to be filtered out.

Or there are non linearities being produced in the acquisition.

The reason you only hear it with certain sampling rates is the filtering (bandwidth) in Audacity amplifies the effect for certain sampling rates as those repetitions or non linearities will fall in a different frequency range based on the sampling rate

• I'm not sure I understand.
– KTC
Sep 5 '20 at 20:42

One of Microsoft's many audio APIs (MME, AKA "waveOut") has a bug in Windows 7. https://www2.iis.fraunhofer.de/AAC/ie9.html

I am using the library PortAudio, so my solution is to compile it without MME support, forcing it to use DirectSound or WASAPI instead.