3

For some really wierd reason, absolutely no sound plays with SDL_mixer. I've tried everything: Reinstalling the library, checking if the music is actually playable, using Mix_FadeInMusic and Mix_FadeOutMusic, to ABSOLUTELY NO AVAIL. It's telling me the music is loading, and it's telling me that it's playing. I'm using Windows 8.1 64 bit with VC 2013.

Code:

SDL_Init(SDL_INIT_EVERYTHING);
// Create window

Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG | MIX_INIT_FLAC | MIX_INIT_FLUIDSYNTH | MIX_INIT_MOD | MIX_INIT_MODPLUG);

if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096)) {
    printf("Unable to open audio!\n");
    ovr_Shutdown();
    SDL_Quit();
    exit(1);
}

music = Mix_LoadMUS(tmpLoc);
if (music == NULL) SDL_ShowSimpleMessageBox(NULL, "", "Music is null", window);
Mix_PlayMusic(music, -1,1000);
if (!Mix_PlayingMusic()) SDL_ShowSimpleMessageBox(NULL, "", "No music playing", window);

// OpenGL stuff
while (quit == false)
{
    // Loop
}
Mix_HaltMusic();
Mix_FreeMusic(music);
Mix_CloseAudio();
Mix_Quit();
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
monster860
  • 124
  • 9

1 Answers1

1

Surprisingly, SDL requires an environment variable under Windows (an artifact of having been originally targeted at Linux) in order to actually output audio.

Try setting SDL_AUDIODRIVER=waveout (or you can use =dsound).

Or, you can call SDL_AudioInit("waveout") or SDL_AudioInit("dsound") just after your SDL_Init() call. (To be efficient, you could modify your flags argument to SDL_Init() to specify all-but-audio).

SDL_AudioInit() is commented by the authors as an "internal" api. Elsewhere in the library it is called to... guess what... initialize your audio using a string it gets from the environment variable.

I encountered this issue while working with ffmpeg's ffplay, which relies on (a statically linked) SDL to output audio (and which then fails to output audio unless/until I manually set the env variable).

I speculate that the SDL authors have some default that is sensible under Linux but makes for a snafu under Windows:

Client code like yours (and ffplay) get no error returned, no exception, just SDL happily pushing audio out into the void.

Jim Davis
  • 41
  • 3