#!/bin/sh # # setting up the alsa configuration. . /etc/rc.config if [ "$ALSA_DEVICE" = "all" ]; then cards="$(LC_ALL=C aplay -l | grep '^card' | sed 's/card \([0-9]\+\).*device \([0-9]\+\).*/\1 \2/')" elif [ -n "${ALSA_DEVICE##-*}" -a "$ALSA_DEVICE" != "auto" ]; then cards="$(echo "$ALSA_DEVICE" | sed "s/,/\n/g")" else rm -f /etc/asound.conf exit fi channels=$(echo -e "$cards" | wc -l) char() { echo "abcdefghijklmnopqrstuvwxyz" | cut -b $(($1+1)) } if [ $channels = 1 ]; then echo -e "$cards" | { read card device name echo "pcm.!default {" echo " type hw" echo " card $card" echo " device $device" echo "}" } > /etc/asound.conf exit fi cat > /etc/asound.conf << EOF pcm.!default { type plug slave { pcm "all" } } pcm.all { type route slave { pcm multi channels $(($channels*2)) } $( i=0 while [ $i -lt $channels ]; do echo " ttable.0.$(($i*2+0)) 1.0" echo " ttable.1.$(($i*2+1)) 1.0" i=$(($i+1)) done ) } pcm.multi { type multi $( i=0 while [ $i -lt $channels ]; do echo " slaves.$(char $i) {" echo " pcm \"$(char $i)\"" echo " channels 2" echo " }" i=$(($i+1)) done i=0 while [ $i -lt $channels ]; do echo " bindings.$(($i*2+0)).slave $(char $i)" echo " bindings.$(($i*2+0)).channel 0" echo " bindings.$(($i*2+1)).slave $(char $i)" echo " bindings.$(($i*2+1)).channel 1" i=$(($i+1)) done ) } $( i=0 echo -e "$cards" | while [ $i -lt $channels ]; do read card device name echo "pcm.$(char $i) {" echo " type hw" echo " card $card" echo " device $device" echo " channels 2" echo "}" i=$(($i+1)) done ) EOF