SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Audio conversion issues when sampling from 22050hz to 48000hz

Open crudelios opened this issue 3 years ago • 2 comments

There seems to be an issue when upsampling audio from 22050hz to 48000hz on x86 builds of SDL >= 2.23.1. The audio still plays, but there's constant buzzing. Buzzing seems to happen at the end of a sound effect playback.

You can listen to the issue here:

buzzing.webm

Some details:

In our project we use SDL mixer to mix music and sound effects. The musics are 44100hz mp3 files and the sound effects (which are the ones that cause the buzzing) are 8-bit PCM wav files sampled at 22050hz. The mixer itself is also set to a sample rate of 22050hz with a sample format of AUDIO_S16.

The issue only happens when the audio output for Windows is set to 48000hz. If set to 44100hz, audio plays fine. It also doesn't seem to happen on 64-bit builds of SDL, only on 32-bit builds. I am unsure if the issue affects other platforms.

This does not seem to be an SDL mixer issue because the buzzing goes away when SDL2.dll is replaced with the 2.0.22 version. In fact, the 2.23.1 version already has the buzzing, so I think it was the audio optimizations commit (111c3add738587f97f41f8eaea35c6ee0d084ca5) that started causing the problem.

crudelios avatar Sep 07 '22 09:09 crudelios

Probably related to https://github.com/libsdl-org/SDL/issues/5538

vladkosi avatar Sep 08 '22 12:09 vladkosi

I'm not sure it is related as that bug seems to be before SDL 2.0.22, while in my case audio works fine on SDL 2.0.22.

crudelios avatar Sep 08 '22 13:09 crudelios

The buzzing is audible in DXX-Rebirth, and is very prominent (and annoying) in VCMI.

GranMinigun avatar Oct 04 '22 19:10 GranMinigun

The fix made to the resampler this weekend might fix this. If anyone can conveniently test the latest in SDL's revision control and report back, I would appreciate it!

icculus avatar Nov 07 '22 20:11 icculus

Built from commit b095df7f5, now it has a different artefact - loud beep.

https://user-images.githubusercontent.com/11149380/200754923-9b478469-0e47-4cd6-8b3e-5bdf7bff2848.mp4

GranMinigun avatar Nov 09 '22 06:11 GranMinigun

The buzzing is audible in DXX-Rebirth, and is very prominent (and annoying) in VCMI.

Is VCMI this thing? https://vcmi.eu/

I tried D2X-Rebirth on Windows, but the precompiled downloads at https://www.dxx-rebirth.com/download-dxx-rebirth/ are using SDL 1.2; I guess I should build from scratch.

icculus avatar Nov 11 '22 01:11 icculus

Is VCMI this thing?

Correct.

As for D2X-Rebirth, perhaps running it through sdl12-compat would show the same behaviour? Didn't try that myself though, my build on Linux is SDL2-based.

GranMinigun avatar Nov 12 '22 07:11 GranMinigun

I can't get this to reproduce on Linux, either; SDL2 build of D2X-Rebirth, with my copy of SDL2's PulseAudio driver forcing the device to only accept audio at 48000Hz so it definitely has to resample, and it sounds fine.

So something else is going on here.

I would say try exporting the environment variable SDL_AUDIODRIVER=alsa and see if it behaves differently, so we can decide if it's maybe a PulseAudio (or Pipewire) issue?

icculus avatar Nov 17 '22 14:11 icculus

Rebuilt against 78ea6af2c. D2X-Rebirth sets 44100 Hz output rate. I do have PipeWire setup re-routing ALSA, PulseAudio, and Jack to it. No difference between alsa and pipewire drivers (same artefact as the last sample), but jack driver interestingly enough has a different artefact. Here's a recording from VCMI, as it's more prominent there, but it happens in D2X-Rebirth as well, in the same spot as in previous recording, just quieter. Will check with raw ALSA.

Edit: alsa driver and raw ALSA - same beep as previously.

https://user-images.githubusercontent.com/11149380/202554601-32ab9aef-597f-4663-96f8-fa569728246a.mp4

GranMinigun avatar Nov 17 '22 20:11 GranMinigun

I can confirm similar issuses also when resampling from 22050 Hz to 44100 Hz. The problem is not present when ResampleFloatType is set to double in SDL_ResampleAudio.

maxmitti avatar Nov 20 '22 15:11 maxmitti

Do you see the same issue on SDL 2.25.1? https://github.com/libsdl-org/SDL/releases/tag/prerelease-2.25.1

slouken avatar Nov 20 '22 22:11 slouken

Do you see the same issue on SDL 2.25.1? https://github.com/libsdl-org/SDL/releases/tag/prerelease-2.25.1

Yes. This was when using 769ae18.

maxmitti avatar Nov 21 '22 06:11 maxmitti

The issue seems to be fixed for my case on windows on the latest v2.26.0 build.

Edit: Fixed for my case only, but some other issues apparently remain.

crudelios avatar Nov 22 '22 10:11 crudelios

I have just tried again with 2.26.0 and the issue still exists in my case. Perhaps they are different issues with similar symptoms.

maxmitti avatar Nov 23 '22 19:11 maxmitti