| Panard's HomePage | |
Recording mixer of HDA sound cards using ALSADraft If you have any suggestion for improving this document, please contact me: panard at inzenet.org IntroductionALSA configurationYou will need alsa-driver at least 1.0.19.
We assume the main sound card (the one you hear the sound from) is the card 0 ( ~/.asoundrc :
# if your sound card supports it:
#pcm.copy {
# type plug
# slave {
# pcm hw
# }
# route_policy copy
#}
# else :
pcm.aloopin {
type hw;
card 3;
device 0;
subdevice 0;
}
pcm.copy {
type hw;
card 3;
device 1;
subdevice 0;
}
pcm.copy2 {
type plug
slave {
pcm "copy"
}
route_policy copy
}
pcm.multi {
type multi
slaves.a.pcm "hw:0,0,0" # main sound card
slaves.a.channels 2
slaves.b.pcm "aloopin" # aloop sound card
slaves.b.channels 2
bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1
bindings.2.slave b
bindings.2.channel 0
bindings.3.slave b
bindings.3.channel 1
}
ctl.multi {
type hw;
card 0;
}
pcm.hdaloop {
type route
slave.pcm "multi"
slave.channels 4;
ttable.0.0 1
ttable.1.1 1
ttable.0.2 1
ttable.1.3 1
# test:
# ttable.2.2 1
# ttable.3.3 1
}
ctl.hdaloop {
type hw;
card 0;
}
## select the one you want:
#pcm.!default { type plug; slave { pcm "hdaloop"; }}
#pcm.!default { type plug; slave { pcm "aloopin"; }}
#pcm.!default pcm.hdaloop
#pcm.!default pcm.aloopin
Recording scriptTherec_output script :
#!/bin/bash
if [[ x$1 == x-play ]]; then
PLAY=true
shift
else
PLAY=false
fi
DESTDIR=${DESTDIR:-/media/2/music}
QUALITY=${QUALITY:-6}
ALSA_CAPTURE="${ALSA_CAPTURE:-copy}"
ALSA_SAFE_PCM="plug:dmix"
CAPTURE_QUALITY="${CAPTURE_QUALITY:-cd}"
# if your sound card supports it.
#CAPTURE_SOURCE="Mix"
#PCM_VOLUME="90%"
run_cmd() {
echo $*
"${@}"
}
if [ -z $1 ]; then
tmpfile=`mktemp`
# if your sound card supports it.
#amixer cset iface=MIXER,name='PCM Playback Volume' $PCM_VOLUME
#amixer cset iface=MIXER,name='Capture Source' $CAPTURE_SOURCE
if $PLAY; then
(sleep 1; run_cmd aplay -D $ALSA_SAFE_PCM $tmpfile)&
fi
run_cmd arecord -f $CAPTURE_QUALITY -D $ALSA_CAPTURE $tmpfile
else
tmpfile=$1
fi
output=`kdialog --getsavefilename $DESTDIR '*.ogg *.mp3'`
if [[ "x$output" != "x" ]]; then
artist=`kdialog --inputbox artist --title artist`
title=`kdialog --inputbox title --title title`
fi
if [[ "x$output" != "x" ]]; then
ext=${output/*./}
if [[ "x$ext" == "x" ]]; then
output="${output}.ogg"
ext="ogg"
fi
case $ext in
ogg ) oggenc -q $QUALITY $tmpfile -o "$output" --artist "$artist" --title "$title" ;;
mp3 ) lame -h -V $QUALITY $tmpfile -o "$output" --ta "$artist" --tt "$title" ;;
* ) echo "unknown '$ext' file extension!" >&2 ; false ;;
esac
[ $? -eq 0 ] && rm -iv $tmpfile
else
rm -iv $tmpfile
fi
References
|
|