14

I am facing a similar problem as described in this question. However I am running Jessie on Raspberry Pi and that it does not have a /etc/modprobe.d/alsa-base.conf file.

So can someone tell me where and how to set the default input and output audio device on Jessie.

Parth Doshi
  • 253
  • 1
  • 3
  • 8
  • You could just try creating that file; I don't know if it was removed because of something to do with device tree, and if so whether that will make any difference. What they are called actually doesn't matter (beyond determining the order in which they are read), as long as they end in .conf. It's what's in them that counts. – goldilocks Dec 23 '15 at 15:13
  • ok I will create it but then what will the contents of the same. Should I add just one line "options snd-usb-audio index=0" ?? – Parth Doshi Dec 23 '15 at 15:19
  • I think there are two lines suggested there, that one and options snd_bcm2835 index=1. – goldilocks Dec 23 '15 at 15:21
  • Hi i tried adding the same but still the default is the snd_bcm2835 only. I also did a reboot – Parth Doshi Dec 23 '15 at 15:50
  • Leave that there, and if you aren't using device tree for anything (e.g. I2C), try adding device_tree= (with nothing after it) in /boot/config.txt to disable it, then reboot again. If that doesn't work, you might as well remove that line from config.txt so you do not forget later. – goldilocks Dec 23 '15 at 15:54
  • "Jessie" will be using systemd as its "init" by default; pulseaudio is a separate thing to Alsa, and systemd and pulseaudio share the same "Father" so I suspect that if PA is around systemd will be interacting with it. I may however be acting as a FUD-merchant here... 8-P – SlySven Dec 23 '15 at 18:01
  • Please see my writeup for further details and solutions. – not2qubit Mar 08 '18 at 12:21

3 Answers3

12

Ok, first delete the file /etc/modprobe.d/alsa-base.conf Raspbian Jessie does not use this config file like Wheezy did.

To find what address your device uses you need to first enter the command aplay -l this shows all audio output devices, and their address. For example, my USB sound card comes up as device 1 in the output which looks like this.

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 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Now, to set the device to your default card you will need to edit the file /usr/share/alsa/alsa.conf with the command sudo nano /usr/share/alsa/alsa.conf scroll down until you find the lines

defaults.ctl.card 0
defaults.pcm.card 0

and change them to (if your device is also listed as device 1, if not change the 1 to whatever address it was listed at)

defaults.ctl.card 1
defaults.pcm.card 1

Explanation: USB sound cards are registered as card 1 on Raspbian Jessie. On Wheezy they would be registered as card -2 by default and editing /etc/modprobe.d/alsa-base.conf would change that.

I do not know if this next step is necessary but without it my card wouldn't work.

Create and edit the file ~/.asoundrc by using the command sudo nano ~/.asoundrc and change it so that it only reads this:

pcm.!default {
    type hw
    card 1
}

ctl.!default {
    type hw
    card 1
}

Now your default audio out (speakers) and audio in (mic) are your usb device.

Patrick Cook
  • 6,365
  • 7
  • 37
  • 63
  • @ParthDoshi I edited the question, in case you aren't using a USB sound card. – Patrick Cook Dec 23 '15 at 18:53
  • thanks Patrick for the quick reply. I will check this and let you know. I am using a USB mic as input and audio speakers as output. My speakers are connected via a 3.5 mm audio jack. – Parth Doshi Dec 23 '15 at 18:54
  • @ParthDoshi so your speakers are using the standard sound card on the pi? – Patrick Cook Dec 23 '15 at 18:55
  • yes they are using the standard sound card. I did a test by running the speaker-test command...I am able to play a sample mp3 file on my PI that I can hear via my speakers clearly, The only problem is the mic as of now – Parth Doshi Dec 23 '15 at 18:56
  • Ok, then you do not need to change one of the lines in those files, I'm figuring out which line right now. – Patrick Cook Dec 23 '15 at 18:57
  • @DarthPoshi Never mind, you still need to edit both lines for the card to work, but it will set your default audio output to that card as well. – Patrick Cook Dec 23 '15 at 19:00
  • @DarthPoshi you can keep the USB mic as the standard input/output and use --device=hw:0,0 to your aplay commands assuming you're using aplay for all audio. Or you can leave the Pi's sound card as the default card and add --device=hw:1,0 to all arecord commands, assuming you're using arecord for all of your recordings. There's no easy way that I know of to use one sound card as input and another as output. – Patrick Cook Dec 23 '15 at 19:04
  • Thanks it worked! :) If you have the time, can you please look at this question too? http://raspberrypi.stackexchange.com/questions/39940/how-to-resolve-invalid-sample-rate-9997 – Parth Doshi Dec 24 '15 at 02:17
  • @ParthDoshi Yah sure, no problem – Patrick Cook Dec 24 '15 at 03:02
  • Per user's edit: There is no need to change ALSA library configuration file, everything just works by creating ~/.asoundrc as instructed (btw thank you, I would comment but I don't have reputation) (edit had to be rejected as clearly conflicting with authors intent) – Ghanima Aug 11 '16 at 18:26
  • Is this the same for Buster? – Mr.Gosh Nov 14 '20 at 16:56
5

Question is referring to another post which has already an answer that simply states that with Jessie there is no need to edit /usr/share/alsa/alsa.conf, just create ~/.asoundrc and type in

pcm.!default {
    type hw
    card 1
}

ctl.!default {
    type hw
    card 1
}

PS: I just tested it with a clean installation on a raspberry 2 connected with Logitech Z-5 speakers, works perfectly

Edoardo
  • 158
  • 1
  • 5
  • I followed your answer and done reboot but when I use Audacity with selected "default" in/output no audio captured and should choose "Loopback PCM hw:0,0" & "Loopback PCM hw:0,1" as my virtual sound card index is 0. Is there another configuration needed for Apps? – Mamdouh Saeed Mar 30 '21 at 06:20
  • 1
    @MamdouhSaeed you should probably play with device index option as other answers are pointing out. I must say since 2016 audio configuration on the raspberry has gotten more complicated in some cases. – Edoardo Mar 31 '21 at 06:29
4

If you have a different device for input and output (e.g. usb mikrophone and 3.5mm audio speaker), you can write it like this in your ~/.asoundrc:

pcm.!default {
  type asym
  playback.pcm
  {
    type hw
    card 0
    device 0
  }
  capture.pcm
  {
    type hw
    card 1
    device 0
  }
}
CodingVoid
  • 41
  • 1