Outils pour utilisateurs

Outils du site


rbpi:rbpi_activer_microphone

Brancher le microphone USB

La commande dmesg doit retourner ceci. Sinon c'est que le matériel n'est pas reconnu

[19230.583705] usb 1-1.4: new full-speed USB device number 6 using dwc_otg
[19230.690624] usb 1-1.4: New USB device found, idVendor=0d8c, idProduct=013c
[19230.690656] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[19230.690673] usb 1-1.4: Product: USB PnP Sound Device
[19230.690691] usb 1-1.4: Manufacturer: C-Media Electronics Inc.
[19230.697596] input: C-Media Electronics Inc.       USB PnP Sound Device as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.2/0003:0D8C:013C.0004/input/input3
[19230.754352] hid-generic 0003:0D8C:013C.0004: input,hidraw3: USB HID v1.00 Device [C-Media Electronics Inc.       USB PnP Sound Device] on usb-3f980000.usb-1.4/input2
[19230.919548] usbcore: registered new interface driver snd-usb-audio

La commande lsusb doit contenir la ligne suivante :

Bus 001 Device 006: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller

La commande cat /proc/asound/cards doit retourner la sortie suivante

 0 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA
 1 [Device         ]: USB-Audio - USB PnP Sound Device
                      C-Media Electronics Inc. USB PnP Sound Device at usb-3f980000.usb-1.4, full spe

Editer le fichier /etc/modprobe.d/alsa-base.conf, puis dans la ligne suivante remplacer -2 par 0

options snd-usb-audio index=-2

La commande cat /proc/asound/cards doit retourner la sortie suivante

 0 [Device         ]: USB-Audio - USB PnP Sound Device
                      C-Media Electronics Inc. USB PnP Sound Device at usb-3f980000.usb-1.4, full spe
 1 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA

Configurer les cartes sons :

alsamixer -c 0

———– Fonctionnement ALSA —————-
The system-wide configuration file is stored in '/etc/asound.conf', all ALSA compliant applications will read this file each time they start.
The best place to look to get a sense of your current sound devices is here in '/proc/asound/'.
If you don't have a configuration file, ALSA applications will use /proc/asound/card0 as the default sound device.
You can check what verison of ALSA you're running here '/proc/asound/version'.
Each sound device has a bunch of 'pcms' associated with it ; Each pcm is basically an output channel: “front”, “rear”, “surround41”, “surround51”, etc. You can see which pcm channels are available by using this command:

aplay -L | grep CARD

A few of these pcm channels do not correspond to physical audio outputs but are software channels provided by ALSA. The one we're interested in is called 'dmix'. The 'dmix' channel is a software mixer provided by ALSA to handle multiple concurrent input streams.


One thing to note is the use of multiple conventions for identifying a particular sound device. The configuration file will use card0, card1, etc or simply 0, 1, etc. It's also possible to refer to the card by name, such as Creative, Nvidia, etc. These names are defined as soft links in the ALSA proc directory: 'ls -l /proc/asound'.
Typically, when referring to a PCM channel in the configuration file, the format is as follows: “channel-name:card-index,sub-index”. So, for example, “dmix:2,0” refers to the dmix pcm channel on card 2, sub-device 0. You see the sub devices associated with each sound card by using this command:

aplay -l


The final step is the configuration file itself, located here '/etc/asound.conf'.
We need 2 components in this file, a 'pcm' channel definition and a 'ctl' channel definition.

  1. The 'pcm' channel defines our output and is responsible for multiplexing multiple sound streams into a single hardware output channel.
  2. The 'ctl' channel is used for the mixer and is responsible for controlling volume.

ALSA uses a software pcm channel called a 'plug' which handles the multiplexing. It is a software front-end for a slaved pcm output channel. The slaved pcm output channel must itself be capable of mixing. An example configuration file follows:

pcm.custom
{
    type plug
    slave
    {
        pcm "dmix:2,0"
    }
}

ctl.custom
{
    type hw
    card Creative
}

pcm.!default pcm.custom
ctl.!default ctl.custom

In this case, I'm using the 'dmix' output channel for the 3rd sound device on the system “dmix:2,0”. The 3rd index is 2 because it starts from 0 (card0, card1, card2). In addition, 'ctl' schema references the same card but this time using it's soft-linked name 'Creative'.




Enregistrer une capture audio

arecord -D plughw:0,0 -f cd /home/pi/testRecord.wav

** Visualiser les paramètres des cartes son

amixer -c 0

et

amixer -c 1

Il existe aussi des outils d'enregistrement via pulseaudio en ligne de commande : parec, parecord

Lire un enregistrement :

aplay <filepath>
rbpi/rbpi_activer_microphone.txt · Dernière modification: 2016/06/18 08:09 (modification externe)