currently I am writing a tool that will utilize three different audio outputs and outputs to them for some events. For this purpose I have installed 3 USB Sound Devices in my computer. I only use Linux and have no intention on porting this to windows, so everything I write will be Linux specific :). The Problem is, that I cannot open a specific sound device, e.g. via ALSA Adress or via USB Path. The documentation here says, that you use the UTF-8 Device string reported by SDL_GetAudioDeviceName. I have written this small tool to enumerate all sound devices:
#include <SDL2/SDL.h>
#include <iostream>
int main()
{
SDL_Init( SDL_INIT_EVERYTHING );
std::cout << SDL_GetError() << std::endl;
atexit( SDL_Quit );
int count = SDL_GetNumAudioDevices(0);
for (int i = 0; i < count; ++i)
{
std::cout << "Device " << i << ": " << SDL_GetAudioDeviceName(i, 0) << std::endl;
}
return 0;
}
(Please note, this is just a quick and dirty program, so no error checking is done, etc).
This gives me this output:
Device 0: Internes Audio Digital Stereo (IEC958)
Device 1: C-Media Electronics, Inc. Audio Adapter
Device 2: C-Media Electronics, Inc. Audio Adapter
Device 3: C-Media Electronics, Inc. Audio Adapter
As you see, the device strings are identical. Is there any way to select the sounddevice either by index or via ALSA Device string (e.g. “hw:0.1”)?
Please note: I will open 3 devies in my program, so setting an envvar wont fix the problem… Or will setenv before the open call work?
Another question is: Do I somehow get informations about the device used? e.g. in alsa, can I get the address (like: “hw:0,3”) or something like that?
Ive hacked it in for alsa now, if someone else needs it. It will add the device string to the name now so it will enumerate something like:
Device 7: USB PnP Sound Device, USB Audio (hw:CARD=Device,DEV=0)
Device 8: USB PnP Sound Device, USB Audio (hw:CARD=Device_1,DEV=0)
Device 9: USB PnP Sound Device, USB Audio (hw:CARD=Device_2,DEV=0)
Finally got around to this: now all devices have unique names. If you have two devices named “SoundBlaster Pro”, the second one will be reported as “SoundBlaster Pro (2)”.