Difference between revisions of "ALSA"

From ArmadeusWiki
Jump to: navigation, search
(Automate ALSA settings at boot)
(mixer id have changed)
Line 124: Line 124:
 
# amixer contents
 
# amixer contents
 
...
 
...
numid=6,iface=MIXER,name='Handset Capture Switch'
+
numid=7,iface=MIXER,name='Handset Capture Switch'
 
   ; type=BOOLEAN,access=rw------,values=1
 
   ; type=BOOLEAN,access=rw------,values=1
 
   : values=off
 
   : values=off
Line 132: Line 132:
 
* Check you can get individually access to the control:
 
* Check you can get individually access to the control:
 
<pre class="apf">
 
<pre class="apf">
# amixer cget numid=6
+
# amixer cget numid=7
numid=6,iface=MIXER,name='Handset Capture Switch'
+
numid=7,iface=MIXER,name='Handset Capture Switch'
 
   ; type=BOOLEAN,access=rw------,values=1
 
   ; type=BOOLEAN,access=rw------,values=1
 
   : values=off
 
   : values=off
Line 139: Line 139:
 
* And then modify its value:
 
* And then modify its value:
 
<pre class="apf">
 
<pre class="apf">
# amixer cset numid=6 on
+
# amixer cset numid=7 on
numid=6,iface=MIXER,name='Handset Capture Switch'
+
numid=7,iface=MIXER,name='Handset Capture Switch'
 
   ; type=BOOLEAN,access=rw------,values=1
 
   ; type=BOOLEAN,access=rw------,values=1
 
   : values=on
 
   : values=on
Line 146: Line 146:
 
* Now we can do the same for the ''Handset Capture Volume'':
 
* Now we can do the same for the ''Handset Capture Volume'':
 
<pre class="apf">
 
<pre class="apf">
# amixer cget numid=5
+
# amixer cget numid=6
numid=5,iface=MIXER,name='Handset Capture Volume'
+
numid=6,iface=MIXER,name='Handset Capture Volume'
 
   ; type=INTEGER,access=rw------,values=1,min=0,max=100,step=0
 
   ; type=INTEGER,access=rw------,values=1,min=0,max=100,step=0
 
   : values=50
 
   : values=50
  
# amixer cset numid=5 30
+
# amixer cset numid=6 30
numid=5,iface=MIXER,name='Handset Capture Volume'
+
numid=6,iface=MIXER,name='Handset Capture Volume'
 
   ; type=INTEGER,access=rw------,values=1,min=0,max=100,step=0
 
   ; type=INTEGER,access=rw------,values=1,min=0,max=100,step=0
 
   : values=30
 
   : values=30
Line 165: Line 165:
 
modprobe snd-imx-alsa-tsc2102
 
modprobe snd-imx-alsa-tsc2102
 
# default values for Audio In:
 
# default values for Audio In:
amixer cset numid=6 on
+
amixer cset numid=7 on
amixer cset numid=5 30
+
amixer cset numid=6 30
 
</source>
 
</source>
  

Revision as of 10:27, 28 May 2010

This page will summarize the informations to use ALSA, ie the sound capabilities (Audio In/Audio Out) of your Armadeus board.

Introduction

ALSA stands for Advanced Linux Sound Architecture and provides audio and MIDI functionality to the Linux operating system. Everyone wanting to write portable & state of the art Linux applications dealing with sound should consider using ALSA.
ALSA is composed of a low level part (target specific Linux drivers) and a userspace library (libasound) with a lot of tools (aplay, arecord, alsamixer).

Hardware

On the i.MX family, used on the Armadeus boards, (good quality) sound can be produced that way:

  1. the i.MX is connected to an audio CODEC (like the TSC2102 on the APF9328 or the TSC2101 on the APF27) through one of its SSI interfaces
  2. the i.MX takes PCM data (ALSA format) from memory and send them (through DMA) to the SSI module
  3. this one converts the data to a serial stream of bits in the I2S format (or AC97). That stream is then sent to the CODEC
  4. the stream is converted by the CODEC's DAC to an analog sound

Sound acquisition (on TSC2101 only) is done in the reverse way.

Installation

ALSA is by default installed on the standard Armadeus rootfs. If you want to change the default configuration, you can consult this wiki page.

Usage

  • Load the ALSA drivers:
 # modprobe snd-imx-alsa-tsc2102
 TI TSC210x driver initializing
 TSC210x detected
  • If you want OSS support (optional):
 modprobe snd-pcm-oss
 modprobe snd-mixer-oss
  • If you want MIDI sequencer support (optional):
 modprobe snd-seq
 modprobe snd-seq-device

Loading script

If you want the drivers to be loaded automatically during each boot, you can add a script in /etc/init.d/. For example:

 # vi /etc/init.d/S60alsa
#!/bin/sh
  
modprobe snd-imx-alsa-tsc2102
 # chmod a+x /etc/init.d/S60alsa

First checks (optionnal)

  • Check if ALSA is running:
 # cat /proc/asound/version
 Advanced Linux Sound Architecture Driver Version 1.0.17.
# aplay -lL
default:CARD=IMX-ALSA
    i.MX+TSC210x audio, i.MX SSI
    Default Audio Device
null
    Discard all samples (playback) or generate zero samples (capture)
**** List of PLAYBACK Hardware Devices ****
card 0: IMX-ALSA [i.MX+TSC210x audio], device 0: i.MX SSI [i.MX SSI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

or

 # cat /proc/asound/cards
 0 [IMX-ALSA       ]: i.MX - i.MX+TSC210x audio
                      Freescale i.MX with TSC210x codec

Setting playback and capture volume

  • For this work, you can use alsamixer "pseudo graphic" tool:
# alsamixer

Alsamixer.png

  • choose the Item to setup by using <- -> arrow keys (here Master Playback volume is selected)
  • modify its value with up/down arrow keys
  • you can switch View between Playback and Capture settings with TAB key
  • Capture Handset input is by default muted, you can unmute it by pressing the SPACE key when selected
  • when stereo channels are used you can modify individual channel volume with:
    • 'q': left up, 'z': left down
    • 'e': right up, 'c': right down
  • if alsamixer changed your terminal layout after exiting you can get it back with:
# reset

First tries

  • To play a test sound (connect your headset first ;-) ):
 # aplay /usr/share/sounds/alsa/Side_Left.wav
 Playing WAVE '/usr/share/sounds/alsa/Side_Left.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono

Note: the audio file Side_Left.wav can be copied from your Linux host (if not already on your rootfs)

  • To record a test sound (on APF27Dev only) (connect your microphone first ;-) ):
# arecord /tmp/foo.wav
Recording WAVE '/tmp/foo.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
  • and to replay it after:
# aplay /tmp/foo.wav
Playing WAVE '/tmp/foo.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
  • for a faster and "wider" sampling:
# arecord -f S16_LE -r 16000 /tmp/toto.wav
Recording WAVE '/tmp/toto.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono

Automate ALSA settings at boot

  • alsamixer is quite cool to setup ALSA parameters in live but in some cases you may want to set them up at a default value at system startup. Here is the way to do.
  • use amixer tool. Display all the possible controls and identify the one of interest (here we'll take Handset Capture Switch):
# amixer contents
...
numid=7,iface=MIXER,name='Handset Capture Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=off
...
  • Handset Capture Switch control here is of boolean type, off by default and control the Audio In On/Off.
  • Check you can get individually access to the control:
# amixer cget numid=7
numid=7,iface=MIXER,name='Handset Capture Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=off
  • And then modify its value:
# amixer cset numid=7 on
numid=7,iface=MIXER,name='Handset Capture Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on
  • Now we can do the same for the Handset Capture Volume:
# amixer cget numid=6
numid=6,iface=MIXER,name='Handset Capture Volume'
  ; type=INTEGER,access=rw------,values=1,min=0,max=100,step=0
  : values=50

# amixer cset numid=6 30
numid=6,iface=MIXER,name='Handset Capture Volume'
  ; type=INTEGER,access=rw------,values=1,min=0,max=100,step=0
  : values=30
  • Now you know the way to do it, you can add these commands to the S60alsa script we built in the previous chapter:
 # vi /etc/init.d/S60alsa
#!/bin/sh
  
modprobe snd-imx-alsa-tsc2102
# default values for Audio In:
amixer cset numid=7 on
amixer cset numid=6 30

Going further

Now that ALSA is working, you can switch to serious things ;-) ->

ALSA Soc

On the APF boards we are going to use Embedded version of ALSA: ALSA Soc ->

But for the moment only "standard" version is functionnal.

Links