0

I get the following from aplay -l, lsusb.


pi@raspberrypi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Device_1 [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
pi@raspberrypi:~ $ lsusb
Bus 001 Device 005: ID 046d:c31c Logitech, Inc. Keyboard K120 for Business
Bus 001 Device 008: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 007: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 006: ID 05e3:0606 Genesys Logic, Inc. USB 2.0 Hub / D-Link DUB-H4 USB 2.0 Hub
Bus 001 Device 004: ID 1bcf:0005 Sunplus Innovation Technology Inc. 
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

-----------------------------------------------------------------------------

I want to play my MP3 via CM108 Audio Controllers with libao. I tried these:

ao_initialize();
ao_option aoption;
ao_option *poption;
poption = &aoption;
poption->key = (char*)"dev";
poption->value = (char*)"hw:0";
dev = ao_open_live(driver, &format, poption); 
    while (mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK)
        ao_play(dev, (char *)buffer, done);

So sound is played via the Pi successfully. I understand that hw:0 is a sound card of the Pi. What should I use instead of hw:0 if I want to play via the first or second CM108 Audio Controller? I already tried hw:1 and hw:2 and it does not work.

  • Does aplay work? – CL. Jun 6 '17 at 11:49
  • I dun no how to test sound with aplay but I tried speaker-test -Dhw:1,0 -c2 -twav and it´s work with hw:1,0 and hw:2,0 but these names doesn´t work with above code. – 3ORZ Jun 6 '17 at 11:57
1

Use the full Alsa designation from output of aplay -l, so in your case the first sound card is hw:0,0, the first usb card is hw:1,0 and the second usb card is hw:2,0.

If you install mpg123 and your sound file is called test.mp3 then use following:

mpg123 -o alsa -d hw:1,0 test.mp3

Note that -o alsa will attempt to play the file via alsa, omitting this uses system default (alsa or pulse) whatever is installed. So

mpg 123 -d hw:2,0 test.mp3

will also work on the second usb card using the default sound server (alsa or pulse) on your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.