SDL does not detect audio devices on CentOS

I want to use SDL2, to play audio .wav files, on a USB attached sound card, on CentOS Linux 7.4.1708.
The files play with SoX play, or aplay, if I set correct device env variable, so the HW is good.
But, I am having troubles getting SDL to recognize attached audio devices.
SDL finds several audio drivers, but only the system audio device.
If I set the default audio device to the USB audio card, it still will not play. And, I did open permissions of /dev/snd/* devices.
What am I doing wrong? Or rather, What should I do to make it work?

Thanks,
Wayne

PS. Sorry for the long post. I want to be sure I’m providing full information.

Here is the code I’m running. And below that is the console output.
Below that is the device list from aplay -[l,L]

**** test program source ****

more testAudio.c
int main(int argc, char** argv) {
int i;

/* Initialize only SDL Audio on default device */
if (SDL_Init(SDL_INIT_AUDIO) < 0)  return 1;

/* List Audio Drivers */
int audDvrCnt = SDL_GetNumAudioDrivers();
printf("SDL_GetNumAudioDrivers(): Found %d Audio Drivers:\n", audDvrCnt);
for (i=0; i<audDvrCnt; i++)  printf("    Audio Driver %d: %s\n", i, SDL_GetAudioDriver(i));

/* Find Audio Output Devices*/
int audOutCnt = SDL_GetNumAudioDevices(0);
printf("SDL_GetNumAudioDevices(0): Found %d Audio Out Devices:\n", audOutCnt);
for (i=0; i<audOutCnt; i++)  printf("    Audio device %d: %s\n", i, SDL_GetAudioDeviceName(i, 0));

/* Find Audio Input Devices*/
int audInCnt = SDL_GetNumAudioDevices(1);
printf("SDL_GetNumAudioDevices(1): Found %d Audio In Devices:\n", audInCnt);
for (i=0; i<audInCnt; i++)  printf("    Audio device %d: %s\n", i, SDL_GetAudioDeviceName(i, 1));

return 0;

}

**** test program output ****

testAudio
SDL_GetNumAudioDrivers(): Found 5 Audio Drivers:
Audio Driver 0: pulseaudio
Audio Driver 1: alsa
Audio Driver 2: dsp
Audio Driver 3: disk
Audio Driver 4: dummy
SDL_GetNumAudioDevices(0): Found 1 Audio Out Devices:
Audio device 0: System audio output device
SDL_GetNumAudioDevices(1): Found 0 Audio In Devices:

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC269VB Analog [ALC269VB Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: CODEC [USB Audio CODEC], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

ls -al /dev/snd
total 0
drwxr-xr-x. 4 root root 380 Oct 11 16:09 .
drwxr-xr-x. 20 root root 3660 Oct 11 16:09 …
drwxr-xr-x. 2 root root 60 Oct 11 16:09 by-id
drwxr-xr-x. 2 root root 100 Oct 11 16:09 by-path
crw-rw-rw-+ 1 root audio 116, 2 Sep 18 09:28 controlC0
crw-rw-rw-+ 1 root audio 116, 6 Sep 18 09:28 controlC1
crw-rw-rw-+ 1 root audio 116, 12 Oct 11 16:09 controlC2
crw-rw-rw-+ 1 root audio 116, 5 Sep 18 09:28 hwC0D0
crw-rw-rw-+ 1 root audio 116, 11 Sep 18 09:28 hwC1D0
crw-rw-rw-+ 1 root audio 116, 4 Oct 11 13:57 pcmC0D0c
crw-rw-rw-+ 1 root audio 116, 3 Oct 11 16:14 pcmC0D0p
crw-rw-rw-+ 1 root audio 116, 7 Sep 29 16:38 pcmC1D3p
crw-rw-rw-+ 1 root audio 116, 8 Sep 29 16:38 pcmC1D7p
crw-rw-rw-+ 1 root audio 116, 9 Sep 29 16:38 pcmC1D8p
crw-rw-rw-+ 1 root audio 116, 10 Sep 29 16:38 pcmC1D9p
crw-rw-rw-+ 1 root audio 116, 14 Oct 11 16:11 pcmC2D0c
crw-rw-rw-+ 1 root audio 116, 13 Oct 11 16:11 pcmC2D0p
crw-rw-rw-+ 1 root audio 116, 1 Sep 18 09:28 seq
crw-rw-rw-+ 1 root audio 116, 33 Sep 18 09:28 timer

lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core

I installed CentOS last night, and I can’t find an SDL2 package at all (it appears to have 1.2.15 by default), but I’m sure I’m probably doing something wrong here.

Check the version of SDL you’re using; if it’s before 2.0.5, our ALSA code doesn’t offer device detection. If it’s before 2.0.4, neither does our PulseAudio code.

(both should work in recent releases, though.)

1 Like

Ah. That clears things up.
I installed with:
cmd: sudo yum install SDL2

What it shows is:
cmd: sudo yum list installed | grep SDL
SDL.x86_64 1.2.15-14.el7 @anaconda
SDL-devel.x86_64 1.2.15-14.el7 @anaconda
SDL2.x86_64 2.0.3-9.el7 @epel
SDL2-devel.x86_64 2.0.3-9.el7 @epel

So, it appears I have version 2.0.3
I’ll search around to see if a newer version is available somehow. If not, at least I understand the failure.
Thanks. I really appreciate the feedback.
Wayne

1 Like