Monday, November 5, 2007

ALSA and Gstreamer on Linux

First, check alsa in the kernel or not.

/root/wiki/web # cat /proc/asound/cards
0 [AudioPCI ]: ENS1371 - Ensoniq AudioPCI
Ensoniq AudioPCI ENS1371 at 0x1400, irq 18

Second, use amixer to understand your audio device.

~/.gstreamer-0.10 # amixer info
Card default 'AudioPCI'/'Ensoniq AudioPCI ENS1371 at 0x1400, irq 18'
Mixer name : 'Cirrus Logic CS4297A rev 3'
Components : 'AC97a:43525913'
Controls : 24
Simple ctrls : 13

And the controls.

~/.gstreamer-0.10 # amixer controls
numid=1,iface=MIXER,name='Master Playback Switch'
numid=2,iface=MIXER,name='Master Playback Volume'
numid=16,iface=MIXER,name='PCM Playback Switch'
numid=17,iface=MIXER,name='PCM Playback Volume'
numid=8,iface=MIXER,name='Line Playback Switch'
numid=9,iface=MIXER,name='Line Playback Volume'
numid=10,iface=MIXER,name='CD Playback Switch'
numid=11,iface=MIXER,name='CD Playback Volume'
numid=7,iface=MIXER,name='Mic Boost (+20dB)'
numid=5,iface=MIXER,name='Mic Playback Switch'
numid=6,iface=MIXER,name='Mic Playback Volume'
numid=3,iface=MIXER,name='Phone Playback Switch'
numid=4,iface=MIXER,name='Phone Playback Volume'
numid=12,iface=MIXER,name='Video Playback Switch'
numid=13,iface=MIXER,name='Video Playback Volume'
numid=14,iface=MIXER,name='Aux Playback Switch'
numid=15,iface=MIXER,name='Aux Playback Volume'
numid=18,iface=MIXER,name='Capture Source'
numid=19,iface=MIXER,name='Capture Switch'
numid=20,iface=MIXER,name='Capture Volume'
numid=21,iface=MIXER,name='IEC958 Playback Con Mask'
numid=22,iface=MIXER,name='IEC958 Playback Pro Mask'
numid=23,iface=MIXER,name='IEC958 Playback Default'
numid=24,iface=MIXER,name='IEC958 Playback Switch'

Then find out how to change the volume with amixer.

~/.gstreamer-0.10 # amixer cset iface=MIXER,name='Master Playback Volume' 45
numid=2,iface=MIXER,name='Master Playback Volume'
; type=INTEGER,access=rw---,values=2,min=0,max=63,step=0
: values=45,45
~/.gstreamer-0.10 # amixer cget iface=MIXER,name='Master Playback Volume'
numid=2,iface=MIXER,name='Master Playback Volume'
; type=INTEGER,access=rw---,values=2,min=0,max=63,step=0
: values=45,45

Then use aplay to test a stereo wav samples.

~/.gstreamer-0.10 # aplay ~/Desktop/nelly_raw_225.wav

Till now we can say alsa is ok if aplay works. Now let's play with gstreamer.
I am using gstreamer-0.10 it is the current release.

gst-launch-0.10 -v fakesrc num-buffers=8 ! fakesink
gst-launch-0.10 -v audiotestsrc ! audioconvert ! audioresample ! osssink

One import thing is use "gst-inspect | grep -i wavparse" if I want to know wavparse is ready with my gstreamer. Also directly check the xml in "~/.gstreamer-0.10" is acceptable.

Then use gstreamer to play the same wave file.

gst-launch-0.10 filesrc location=~/Desktop/nelly_raw_225.wav !
wavparse ! audioconvert ! audioresample ! osssink

Hopefully gstreamer works.