High pitched buzzing when playing a continuous sound - SDL_mixer broken?

I’m playing a constantly sounding tank engine sound in my game, but every few seconds it makes a high pitched buzz (which isn’t there in the WAV file). My code is:

m_audioManagerTankEngine = Mix_LoadWAV("TankEngine.wav");

Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);

Mix_PlayChannel(0, m_audioManagerTankEngine, -1);

I’ve tried playing around with the parameters in Mix_OpenAudio but I always get the buzz.

I’m using SDL_mixer 2.6.2 and I’m fairly sure I didn’t have this problem with previous versions.

Is this a problem with SDL, or maybe I just have duff sound drivers (they are up to date)? I’d really appreciate it if other people could try this code and sound file, to see if it’s a problem with my old laptop and not a general SDL_mixer problem!

This is the TankEngine.wav file:

I’ve run the latest SDL and SDL_mixer playing that WAV sound on a Windows laptop and on a Huawei phone, and both give the strange buzzing sound when playing that TankEngine.wav continuously. Before updating my Android SDL I checked and there was no buzzing, I’m very sure it didn’t used to be on Windows either).

There is something broken in the latest SDL_mixer!

(Also I get a totally blank black screen on my old test Huawei phone, the emulators seem OK. Looks like I’m gonna have to downgrade my SDL install to a previous version :frowning: )

On my system (macOS 12.6, SDL 2.24.1, SDL_Mixer 2.6.2), the way you have things ordered produces no sound at all.

Rearranging things to have the Mix_OpenAudio() call happen before the WAV file gets loaded makes the sound play normally (I’m assuming you’re calling Mix_Init() before doing any of this).

Your WAV plays just fine here with SDL Mixer 2.6.2.

You really need to open an audio device before you load any chunks, as the chunks need to be decoded to a format that matched the format of the audio device. I suspect that’s why you’re having problems.

Ooops. I just copied and pasted my code there in the wrong order - I do Mix_OpenAudio before Mix_LoadWAV in my actual code!

I have SDL_Mixer 2.6.2 and I get the buzzing noise on both Windows and Android. Have you tried the WAV file I posted and set it to run on a continuous loop?

If you’re using SDL 2.0 make sure you link with SDL2_mixer and not SDL_mixer for old SDL 1.2.

I accidentally made that mistake and the sound didn’t sound right and if I passed a different frequency to Mix_OpenAudio it sounded different.

Yes, I just downloaded your WAV file and let it play on a loop. It works fine here on macOS with SDL Mixer 2.6.2.

I’ve done some more testing, I re-saved my WAV file with Audacity at different sampling rates and WAV formats, and I still get the buzzing sound. I found that it doesn’t need to play on a continuous loop, just playing the sound a single time still gives the buzz. I tried different WAV files and I do not get any buzz from them - only this TankEngine.wav file buzzes.

But, I re-saved the file as a .ogg file and there is now no buzzing!

I don’t understand why I get the buzz on two completely different systems (my Windows laptop, and my Android phone) and nobody else seems to have it. But I think there is something amiss in the latest SDL2_mixer that affects some WAV files, as this problem definitely wasn’t in the older version of SDL2_mixer I’ve been using, but is there now.