c++windows-7sdlsdl-mixer

How to specify device using SDL_mixer


I've got a program that plays some sounds using the SDL_mixer library (http://www.libsdl.org/projects/SDL_mixer/). It works well when I'm just using Mix_OpenAudio to open a connection with the default device. However, I need to target a specific audio device. I see that the SDL library itself has a method called SDL_OpenAudioDevice that would do what I need, but then I would have to write my own mixer and all that stuff.

Anyone know how to use SDL_mixer to open a specific audio device, or of a different mixer for SDL that supports this? I don't really want to write my own mixer. I'm developing a Win32 app on Windows 7 in C++.


Solution

  • It appears you cannot use SDL_mixer to specify a device. SDL_mixer uses the old SDL method SDL_OpenAudio and therefore no device can be specifically targeted. I also looked into SFML, however it has the same limitation. I then checked out PortAudio, but it doesn't mix stuff for you either, so it looks as though its at the same level as SDL. However, it turns out that writing a simple mixer to play looping sounds targeted at an audio device by name is not that hard.

    See documentation on the SDL site for the methods SDL_OpenAudioDevice and SDL_MixAudioFormat. I also found these code examples helpful in learning how to load my wav files correctly and how to loop on a sample:

    http://www.libsdl.org/tmp/SDL/test/loopwave.c http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlconvertaudio.html