jakebesworth/Simple-SDL2-Audio

SDL2.0.5 -> SDL2.0.6 breaks Simple-SDL2-Audio on Windows 7

jakebesworth opened this issue · 1 comments

https://github.com/ericb59 Messaged me stating that Windows 7 + SDL2.0.7 + Simple-SDL2-Audio were incompatible.

I built the project on digitalriver Windows 7 ISO build using MinGW 64 bit with Latest Simple-SDL2-Audio and SDL2.0.8 and noticed that it did not play sound. I went back through the versions until 2.0.5 worked, so I figured there was issue with 2.0.6.

2.0.6 Release notes: https://discourse.libsdl.org/t/sdl-2-0-6-released/23109 with mention to audio changes

I did a comparison of releases and noticed: spurious/SDL-mirror@release-2.0.5...release-2.0.6#diff-da39c90a56379c8da9f80fb8682bc49dR1310

+    /* !!! FIXME in 2.1: add SDL_AUDIO_ALLOW_SAMPLES_CHANGE flag?
+       As of 2.0.6, we will build a stream to buffer the difference between
+       what the app wants to feed and the device wants to eat, so everyone
+       gets their way. In prior releases, SDL would force the callback to
+       feed at the rate the device requested, adjusted for resampling.
      */

I found this: https://www.doomworld.com/forum/topic/97402-important-for-devs-sdl2-206s-audio-breakage-in-windows/

Which mentioned others having issues. However, the SDL2 documentation seems to not have been updated since last I wrote the library, so we're technically running on the latest example code SDL2 offers.

I noticed that SDL2_Mixer had an update from 2.0.1 to 2.0.2 because of SDL2.0.6: https://discourse.libsdl.org/t/sdl2-mixer-2-0-2-prerelease/23271

So I did a diff of their code from version 2.0.1 as the - and 2.0.2 as +:

+/* Open the mixer with a certain desired audio format */
+int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize)
+{
+    return Mix_OpenAudioDevice(frequency, format, nchannels, chunksize, NULL,
+                                SDL_AUDIO_ALLOW_FREQUENCY_CHANGE |
+                                SDL_AUDIO_ALLOW_CHANNELS_CHANGE);
+}
+

The flags they set are SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE and NOT SDL_AUDIO_ALLOW_ANY_CHANGE.

I'm not sure why, but this change fixes Simple-SDL2-Audio on Windows 7

Due to the Emscripten change earlier I probably should have played with these parameters first, but in the end I found the solution. Will update the README with Windows 7 SDL2.0.6 Fix.

Fixed in 1ed6a76