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.