Hi everybody
Is time for a new step in Cybernetic Interface development - audio interface configuration.
Because RaspberryPi lacks a microphone input, which I need for my project, I had to add and configure an external USB sound card.
Due to space constraints I picked the smallest I could find, Konig 3D Sound, based on C-Media CM108 Audio Controller.
It worked from the first try, plugged directly in RPi USB port or in USB Hub.
Configuration and testing steps are listed bellow:
Check sound card configuration:
cat /proc/asound/card ->
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-bcm2708_usb-1.2, full speed
lsusb ->
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
show that the USB sound card is visible. Next, edit alsa-base.conf to load snd-usb-audio as first option:
sudo nano /etc/modprobe.d/alsa-base.conf
Change configuration to make USB sound card the default one:
options snd-usb-audio index=-2
to
options snd-usb-audio index=0
and after a sudo reboot, cat /proc/asound/cards -> should looks like this:
0 [Device ]: USB-Audio - USB PnP Sound Device
C-Media Electronics Inc. USB PnP Sound Device at usb-bcm2708_usb-1.2, full speed
1 [ALSA ]: bcm2835 - bcm2835 ALSA
bcm2835 ALSA
If not already installed, install alsa-base, alsa-utils and mpg321 (or mpg123, mplayer, etc.) :
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install alsa-base alsa-utils mpg321
sudo reboot
Next, edit /etc/asound.conf and change playback and capture devices from "internal" to "usb". Mine look like this:
sudo nano /etc/asound.conf
pcm.usb
{
type hw
card Device
}
pcm.internal
{
type hw
card ALSA
}
pcm.!default
{
type asym
playback.pcm
{
type plug
slave.pcm "usb"
}
capture.pcm
{
type plug
slave.pcm "usb"
}
}
ctl.!default
{
type asym
playback.pcm
{
type plug
slave.pcm "usb"
}
capture.pcm
{
type plug
slave.pcm "usb"
}
}
To be sure, do an other reboot and proceed to test the configuration.
To check configuration I used:
amixer -c 0 - to display current settings. Mine looks like this:
pi@cyberpi ~$ amixer -c 0
Simple mixer control 'Speaker',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 151
Mono:
Front Left: Playback 119 [79%] [-6.06dB] [on]
Front Right: Playback 119 [79%] [-6.06dB] [on]
Simple mixer control 'Mic',0
Capabilities: pvolume pvolume-joined cvolume cvolume-joined pswitch pswitch-joined cswitch cswitch-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: Playback 0 - 127 Capture 0 - 16
Mono: Playback 96 [76%] [17.99dB] [off] Capture 0 [0%] [0.00dB] [on]
Simple mixer control 'Auto Gain Control',0
Capabilities: pswitch pswitch-joined penum
Playback channels: Mono
Mono: Playback [on]
and
alsamixer -c 0 - to modify speakers and microphone levels.
Using mpg321 (mpg123/mplayer/aplay/other) and favourite test sound file, plug headphones or speakers into external soundcard output and check if the sound is correctly played. It did 
pi@cyberpi ~$ mpg321 /home/pi/test.mp3
Ok, with playback working, let's check the recording side.
Plug microphone into USB soundcard input and launch:
pi@cyberpi ~$ arecord -D plughw:0,0 -f cd ./test.wav
Use Ctrl+C to stop recording.
Check the result -> pi@cyberpi ~$ mpg321 test.wav -> success
.
If needed, use "alsamixer -c 0" to adjust sound levels to meet your requirements.
That's it. Now I have both audio playback and recording on Raspberry PI.
Next step is to do some speech recognition and implement the audio aided menus.
All the best
-=Seba=-
