Let’s make some noise (or how to play audio on Edison)

There’s a huge interest lately in making Edison play audio files and looks like people have troubles doing that. This post is aimed at getting you going, because that’s really not that complex, just a couple of components need to be put in place and used properly.

Here’s a list of steps you need to perform to enjoy some sound:

  1. First, you need to buy a USB sound card and (only in case you have a mini-breakout board with only micro-USB ports) a USB A female to micro-USB B adapter. I don’t have any specific list, but you should ideally look for the one with Linux support declared (however a lot of cheap no-name ones work without that too – so that’s not a hard requirement).
  2. UPDATE 15-Mar-2015: Starting with Edison’s Release 2 image (the one with “ww05” in the name), the usb-snd-audio module is built into the kernel, so no need to mess up with replacing the kernel! :) Just note that you won’t see it using lsmod, it was added statically.
    When you have the HW, either install the kernel + modules from my repo by following my earlier post on that. Alternatively (I haven’t tested this though, but it may work), you can probably get away with just installing the kernel-module-snd-usb-audio module alone (opkg should install a couple of other modules as dependencies automatically).
  3. Connect your USB sound card to the Edison board and flip the mechanical switch closer to the big USB port (if you use the Arduino expansion board). Check that necessary modules are loaded and OS sees the device:

    root@edison1:~# lsmod
    Module                  Size  Used by
    snd_usb_audio         119941  0 <<< This and the below dependencies
    snd_usbmidi_lib        24140  1 snd_usb_audio
    snd_hwdep              13232  1 snd_usb_audio
    snd_rawmidi            24231  1 snd_usbmidi_lib
    usb_f_acm              14335  1
    u_serial               18582  6 usb_f_acm
    g_multi                70703  0
    libcomposite           39245  2 usb_f_acm,g_multi
    bcm_bt_lpm             13676  0
    bcm4334x              574851  0
    
    root@edison1:~# lsusb
    Bus 001 Device 002: ID 047f:da41 Plantronics, Inc. <<< This is my device
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  4. UPDATE 15-Mar-2015:Starting with Edison's Release 2 image (the one with "ww05" in the name), you have Pulseaudio included into the image, so generally speaking you don't need ALSA and can do everything with Pulseaudio, though it would look a bit different than with ALSA - probably I'll sum this up in a blog post at some point.
    Install ALSA utils and dependencies:

    opkg install alsa-utils
  5. Check that ALSA sees your card as well. Note that I'm using a USB headset, so your output may be slighly different:

    root@edison1:~# aplay -Ll
    null
        Discard all samples (playback) or generate zero samples (capture)
    sysdefault:CARD=Loopback
        Loopback, Loopback PCM
        Default Audio Device
    sysdefault:CARD=Headset
        Plantronics USB Headset, USB Audio
        Default Audio Device
    **** List of PLAYBACK Hardware Devices ****
    card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
      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: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
      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 1: Headset [Plantronics USB Headset], device 0: USB Audio [USB Audio]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
  6. Create a ~/.asoundrc file with the below contents to set your card as the default output. The part after the colon must be what ALSA has as the name for your device in the output above (Headset in my case).

    Alternatively this can be put into /etc/asound.conf and then it will be applied to all users in the system as opposed to just one user.

    pcm.!default sysdefault:Headset

    Another way to specify the default device is to use the hw "coordinates" directly and specify the control device separately if needed. It wasn't the case for my one, but just to show you all the options:

    pcm.!default {
            type hw
            card 1
            device 0
    }
    ctl.!default {
            type hw
            card 1
            device 0
    }

    Technically, this step is not mandatory, because all sound players I've seen have options for specifying the device directly (I'll show an example below), however setting the default just makes your life easier and saves some typing.

  7. Now try playing something using the basic aplay utility. The WAV file I'm using would be installed with the speaker-test utility, which is a part of alsa-utils, so you should have it too:

    root@edison1:~# aplay /usr/share/sounds/alsa/Front_Center.wav
    Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
    root@edison1:~#

    You should hear "Front Center" being pronounced.

    An example with specifying the device directly (could be useful for troubleshooting or when you haven't set the default device per the above):

    root@edison1:~# aplay -D hw:1,0 /usr/share/sounds/alsa/Front_Center.wav
    Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
    root@edison1:~#
  8. Finally, if you want to play MP3 files, I've added mpg123 utility into my package repo, with SSE support and enhanced quality enabled. It's small, fast and uses really low amount of resources while supporting playing files and even HTTP streams. When playing a 320Kbps/44100Hz file it barely uses 1% and when listening to a 64Kbps/22050Hz HTTP stream it sits at 0% most of the time :) (as [unscientifically] measured by top with 1-second interval).

    root@edison1:~# mpg123 /home/root/recit.mp3 
    High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
    	version 1.21.0; written and copyright by Michael Hipp and others
    	free software (LGPL) without any warranty but with best wishes
    
    Directory: /home/root/
    Playing MPEG stream 1 of 1: recit.mp3 ...
    
    MPEG 1.0 layer III, 320 kbit/s, 44100 Hz joint-stereo
    
    [0:09] Decoding of recit.mp3 finished.
    
    root@edison1:~# mpg123 http://linux0.cs.uaf.edu/icecast/kuac64stereo
    High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
    	version 1.21.0; written and copyright by Michael Hipp and others
    	free software (LGPL) without any warranty but with best wishes
    
    Directory: http://linux0.cs.uaf.edu/icecast/
    Playing MPEG stream 1 of 1: kuac64stereo ...
    ICY-NAME: KUAC 64Kbs Stereo
    ICY-URL: http://kuac.org/
    
    MPEG 2.0 layer III, 64 kbit/s, 22050 Hz joint-stereo
    ^C
    [0:02] Decoding of kuac64stereo finished.

    You can specify a device directly for mpg123 by using the -a switch, i.e. mpg123 -a hw:1,0 <...>

And that's pretty much it for the basics! You can also use alsamixer utility to set the microphone sensitivity and volume for the device. Make sure to hit F6 and select the card, it seems like it doesn't take into account the .asoundrc/asound.conf settings and always starts with Loopback being selected.

If your sound card has a microphone input, try recording some sound with arecord, that could be fun too.

If you want to leard the details of configuring the ALSA according to your needs, this wiki page was very useful in my research, check it out.

If something doesn't work for you, check that you have necessary modules loaded, that OS and ALSA see your device and that you use the correct device in your defaults or player options. If nothing of that helps - go ahead and start a thread at Intel Makers Community to get some help.

I've also started a dedicated thread for your feedback or additional questions specific to this blog post.

8 Replies to “Let’s make some noise (or how to play audio on Edison)”

  1. We have connected Logitech H390 USB headset to Intel Edison breakout board but headset is not detected.

    lsmod output is as follows. snd_usb_audio module is not loaded.
    root@edison:~# lsmod
    Module Size Used by
    usb_f_acm 14335 1
    u_serial 18582 6 usb_f_acm
    g_multi 70813 0
    libcomposite 39245 2 usb_f_acm,g_multi
    bcm_bt_lpm 13676 0
    bcm4334x 578947 0

    root@edison:~# lsusb
    unable to initialize libusb: -99

    Do we need to do any configuration setting or run a script to detect USB headset?

  2. I am using latest Edison Release edison-image-ww05-15 having snd-usb-module.

  3. Logitech H390 USB headset is working fine with Intel Edison.
    I could play the file using mplayer and aplay.

    Thanks Alex for the posts on Edison.
    Regards
    Mohita

  4. is there a way to specify the default devices to be 2 devices not one.
    the problem is i need Intel Edison to give the audio output to 2 devices simultaneously and that these 2 devises be the default audio output for Intel Edison
    1- a Bluetooth headset using the A2DP
    2- a USB sound Card

  5. Hi,
    I’m trying to use an Intel Edison with Arduino board, I installed the latest kernel but it is not recognize the Sound USB stick I want to use.
    Follow your instruction but the lsmod is not showing the sound module and lsusb shows an unrecognized device. I try to follow all your instructions but the kernel-module-snd-usb-audio is not available on the repositories. I’m using the kernel iot-devkit-prof-dev-image-edison-20160606 I downloaded from intel site. Can you give me an help Thanks

  6. It’s been quite a while since I’ve done that, but in general, IIRC the USB audio module was moved into the kernel as a statically built one, at some point, in the official image. You may want to check if that sound chip you have is at all supported by the kernel version that build has (uname -a will tell you, IIRC that was 3.10.something).

Leave a Reply

Your email address will not be published. Required fields are marked *