Skip to content

Commit

Permalink
SDL2_mixer: add support for WAV music (fix #11655) (#11845)
Browse files Browse the repository at this point in the history
Unintuitivelly, SDL2_mixer is being built without support for WAV music
~ through Mix_LoadMUS() ~, even though support for WAV samples ~ through
Mix_LoadWAV() ~ is always present.

One option for fixing this would be to add a "wav" option to
SDL2_MIXER_FORMATS, to enable WAV music support, but that could still
cause confusion, as, unlike other formats, it would only affect music,
not samples.

Since the size increase is about 8K (~10%) for the lib and 4K (~0.3%)
for the test program linked against it, enable support for WAV music
uncondittionally.
  • Loading branch information
pudiva authored Aug 10, 2020
1 parent 8fb5454 commit d81f400
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 6 additions & 5 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3206,19 +3206,20 @@ def test_sdl2_mixer_wav(self):
self.btest('sdl2_mixer_wav.c', expected='1', args=['--preload-file', 'sound.wav', '-s', 'USE_SDL=2', '-s', 'USE_SDL_MIXER=2', '-s', 'INITIAL_MEMORY=33554432'])

@parameterized({
'ogg': ('ogg', 'alarmvictory_1.ogg'),
'mp3': ('mp3', 'pudinha.mp3'),
'wav': ([], '0', 'the_entertainer.wav'),
'ogg': (['ogg'], 'MIX_INIT_OGG', 'alarmvictory_1.ogg'),
'mp3': (['mp3'], 'MIX_INIT_MP3', 'pudinha.mp3'),
})
@requires_sound_hardware
def test_sdl2_mixer_music(self, fmt, music_name):
def test_sdl2_mixer_music(self, formats, flags, music_name):
shutil.copyfile(path_from_root('tests', 'sounds', music_name), music_name)
self.btest('sdl2_mixer_music.c', expected='1', args=[
'--preload-file', music_name,
'-DSOUND_PATH=' + json.dumps(music_name),
'-DFLAGS=' + ('MIX_INIT_' + fmt.upper() if fmt else '0'),
'-DFLAGS=' + flags,
'-s', 'USE_SDL=2',
'-s', 'USE_SDL_MIXER=2',
'-s', 'SDL2_MIXER_FORMATS=' + json.dumps([fmt] if fmt else []),
'-s', 'SDL2_MIXER_FORMATS=' + json.dumps(formats),
'-s', 'INITIAL_MEMORY=33554432'
])

Expand Down
11 changes: 6 additions & 5 deletions tests/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ def test_sdl2_mixer_wav(self):
])

@parameterized({
'ogg': ('ogg', 'alarmvictory_1.ogg'),
'mp3': ('mp3', 'pudinha.mp3'),
'wav': ([], '0', 'the_entertainer.wav'),
'ogg': (['ogg'], 'MIX_INIT_OGG', 'alarmvictory_1.ogg'),
'mp3': (['mp3'], 'MIX_INIT_MP3', 'pudinha.mp3'),
})
def test_sdl2_mixer_music(self, fmt, music_name):
def test_sdl2_mixer_music(self, formats, flags, music_name):
shutil.copyfile(path_from_root('tests', 'sounds', music_name), music_name)
self.btest('sdl2_mixer_music.c', expected='1', args=[
'-O2',
'--minify', '0',
'--preload-file', music_name,
'-DSOUND_PATH=' + json.dumps(music_name),
'-DFLAGS=' + ('MIX_INIT_' + fmt.upper() if fmt else '0'),
'-DFLAGS=' + flags,
'-s', 'USE_SDL=2',
'-s', 'USE_SDL_MIXER=2',
'-s', 'SDL2_MIXER_FORMATS=' + json.dumps([fmt] if fmt else []),
'-s', 'SDL2_MIXER_FORMATS=' + json.dumps(formats),
'-s', 'INITIAL_MEMORY=33554432'
])

Expand Down
3 changes: 2 additions & 1 deletion tools/ports/sdl2_mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def create():

flags = [
'-s', 'USE_SDL=2',
'-O2'
'-O2',
'-DMUSIC_WAV',
]

if "ogg" in settings.SDL2_MIXER_FORMATS:
Expand Down

0 comments on commit d81f400

Please sign in to comment.