The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Selecting an audio device
radium


Joined: 08 Nov 2013
Posts: 1
Location: NZ
I have been having some problems with SDL_OpenAudioDevice.
I am using SDL 2.0.1 on Windows 7 x64

Code:

SDL_AudioSpec want, have;

SDL_zero(want);
want.freq = 44100;
want.format = AUDIO_F32;
want.channels = 2;
want.samples = 4096;
want.callback = audio_callback;  // you wrote this function elsewhere.

device_id = SDL_OpenAudioDevice(SDL_GetAudioDeviceName(device_index , 0) , 0, &want, &have, SDL_AUDIO_ALLOW_ANY_CHANGE);


Note: All SDL sub-systems are inited before this

I know that I have 2 audio devices known to SDL due to the count from SDL_GetNumAudioDrivers is 2.
Even SDL_GetAudioDeviceName give two different device names which matches what my Windows gives me.

But when I run the code above keep on getting the error "Invalid audio device ID"
If I try a similar method above but with SDL_InitAudio I also get an error "Audio target 'Device Name' not available" and then it crashes

Is there something I am missing? or have done wrong?