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:
- The older "index=" method
- 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.