21

I'm using Raspbian Jessie (2015-11-21) to run Jasper (master branch) on the Raspberry Pi 2 Model B. The installation instructions in the documentation seem to be for Wheezy and not Jessie.

Running Jasper on Wheezy works fine. But, on Jessie, I had problems configuring the sound. Either my mic worked but not the speaker or vice versa.

What needs to be done is, the default sound card must be set to USB because that is where my USB mic is connected and Jasper requires this. There are a lot of answers that talk about configuring ALSA via ~/.asoundrc, /etc/asound.conf and even /usr/share/alsa/alsa.conf but none of them worked for me.

When I open my mixer via alsamixer and hit F6, I always see bcm2835 as the default card. That's the Pi2's default card but I want to make my USB the default card.

How do I do this?

2 Answers 2

28

According to the ALSA Wiki, under the title that reads "How to choose a particular order for multiple installed cards", it states the following:

Which card is card number 0, 1 and so is by default determined by module load order. This is particularly useful to choose which card becomes the default one.

In theory therefore it is possible to choose which of several installed cards becomes card 0, the default one, by ensuring its driver module is loaded first. (Note: this assumes that each sound card requires a different driver. If you have two soundcards of the same type, please skip to the next section.)

There are two ways to achieve this, the "old" index= option of the card driver module, and the alternative (and new) slots= option of the snd module.

It documents two methods of doing this:

  1. The older "index=" method
  2. The newer "slots=" method

The former is what the Jasper installation instructions recommend. It's also what a majority of the solutions out there talk about. However, this is the older method and may not work on more current Raspbian Jessie images.

A combination of both methods is what worked for me.

First of all, check to see what order your cards have been loaded in:

$ cat /proc/asound/modules
 0 snd_bcm2835
 1 snd_usb_audio

Counting cards begins from 0 so the default bcm2835 is loaded first and my USB card which has my mic is loaded second.

To reorder my cards, I first create a file named /etc/modprobe.d/alsa-base.conf. It can be named anything you want as long as it ends with .conf. I then added the following:

# This sets the index value of the cards but doesn't reorder.
options snd_usb_audio index=0
options snd_bcm2835 index=1

# Does the reordering.
options snd slots=snd_usb_audio,snd_bcm2835

The comments should explain what each line does. Once you do that, it seems you have to reboot your machine for it to work.

Once you reboot, you should be able to record some audio with the default card which should now be your mic:

$ arecord temp.wav

and then play it, specifying the card as 1 and device as 0 which is where your speaker output should be:

aplay -D plughw:1,0 temp.wav

I initially only added the line with slots in it. This worked in making my USB card the default card but it was indexed wrong. For example, once I did that, this is what my /proc/asound/modules looked like:

$ cat /proc/asound/modules
 1 snd_usb_audio
 2 snd_bcm2835

Ideally, it should look like this:

 0 snd_usb_audio
 1 snd_bcm2835

And that is why I also use the index method to achieve this.

3
  • Glad it helped :) I'll have a bash setup script as well as a Chef cookbook to do all of this in a few days, on my Github account (link in my profile).
    – Housni
    Commented Jan 11, 2016 at 18:08
  • I have two devices called snd_usb_audio, unfortunately. Commented Jul 29, 2017 at 19:22
  • @Housni Did you make that script yet?
    – not2qubit
    Commented Mar 7, 2018 at 15:45
0

After trying to debug alsa issues for this project and getting BOTH usb mic and bcm2835 speakers working I think there is a basic problem that ALL of the ALSA advice I received does not deal with.

The /usr/share/alsa/cards directory does not have a bcm2835.conf file. The /usr/share/alsa directory file alsa.conf leaves a LOT of stubs that need to be specified. Unless a card for bcm2835 is supplied, firing up Jasper.py displays a lot of supposedly non-fatal error messages. By working up a bcm2835.conf file, you can get rid of the irritating messages.

It seems to me that this is a Jessie bug; there really should be a file that resolves these error messages. I seems just lazy for the jessie programmer that deals with ALSA to not have created one that is tested.

I have not worked down thru all of the error messages, but I suspect that other messages are caused by this as well.

Another case of not having a mature release is the failure to check for old firmware during boot. Old firmware on my jessie resulted in a desktop that would not respond to keyboard or mouse which is a showstopper for using jessie with old firmware, unless you know ssh. Not a naive user situation.

2
  • 1
    WRT it "seems just lazy for the jessie programmer that deals with ALSA to not have created one that is tested", do not be confused into believing that Debian 8, aka. jessie, from which Raspbian is built, is intended primarily for the Raspberry Pi and BCM2835 SoC. The latter would account for < 1% of Debian users, so it can hardly be considered a priority for them. The fact that a group of primarily volunteers do not want to work at a keyboard 25 hours/day to be everything to everybody does not make them lazy....
    – goldilocks
    Commented Jun 8, 2016 at 0:28
  • ...It just indicates there is not sufficient interest by people in the community with the necessary technical expertise to do the work.
    – goldilocks
    Commented Jun 8, 2016 at 0:28

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