Last active
August 29, 2015 14:18
-
-
Save jawi/e5a287379c4ea31562d8 to your computer and use it in GitHub Desktop.
Unified script for configuring WM5102 playback (as used in Wolfsson/CirrusLogic audio card for RPi)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# wm5102cfg.sh - unified script for configuring WM5102 playback. | |
# based on scripts in <https://github.com/CirrusLogic/wiki-content/blob/master/scripts/*.sh> | |
# | |
# (C) 2015 - J.W. Janssen <[email protected]> | |
# Licensed under Apache License v2. | |
AMIXER="/usr/bin/amixer" | |
AMIXER_ARGS="-Dhw:sndrpiwsp" | |
DEFAULT_VOLUME=80 | |
if [ ! -x $AMIXER ]; then | |
echo "$AMIXER not found!" | |
exit 1 | |
fi | |
verbose=0 | |
output=lineout | |
while getopts hvo: flag | |
do | |
case $flag in | |
v) | |
verbose=1 | |
;; | |
o) | |
output=$OPTARG | |
;; | |
h) | |
echo "$0 [-v] [-o OUTPUT]" | |
exit 1 | |
;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
if [ $verbose -eq 0 ]; then | |
AMIXER_ARGS="${AMIXER_ARGS} -q" | |
fi | |
amixer_cset() { | |
$AMIXER $AMIXER_ARGS cset "name='$1'" $2 | |
} | |
reset_all() { | |
amixer_cset "HPOUT1 Digital Switch" off | |
amixer_cset "HPOUT2 Digital Switch" off | |
amixer_cset "SPDIF Out Switch" off | |
amixer_cset "SPDIF In Switch" off | |
amixer_cset "Tx Source" AIF | |
amixer_cset "AIF2TX1 Input 1" None | |
amixer_cset "AIF2TX2 Input 1" None | |
amixer_cset "AIF1TX1 Input 1" None | |
amixer_cset "AIF1TX2 Input 1" None | |
amixer_cset "HPOUT1L Input 1" None | |
amixer_cset "HPOUT1R Input 1" None | |
amixer_cset "HPOUT1L Input 2" None | |
amixer_cset "HPOUT1R Input 2" None | |
amixer_cset "HPOUT2L Input 1" None | |
amixer_cset "HPOUT2R Input 1" None | |
amixer_cset "HPOUT2L Input 2" None | |
amixer_cset "HPOUT2R Input 2" None | |
amixer_cset "Headset Mic Switch" off | |
amixer_cset "DMIC Switch" off | |
amixer_cset "SPKOUTL Input 1" None | |
amixer_cset "SPKOUTR Input 1" None | |
amixer_cset "SPKOUTL Input 2" None | |
amixer_cset "SPKOUTR Input 2" None | |
amixer_cset "Speaker Digital Switch" off | |
} | |
playback_to_speaker() { | |
# Playback from AP to Speaker | |
amixer_cset "Speaker Digital Volume" 128 | |
# reset speaker mixer inputs | |
amixer_cset "SPKOUTL Input 1" None | |
amixer_cset "SPKOUTR Input 1" None | |
amixer_cset "SPKOUTL Input 2" None | |
amixer_cset "SPKOUTR Input 2" None | |
# Route AP to Speaker mixer | |
amixer_cset "SPKOUTL Input 1" AIF1RX1 | |
amixer_cset "SPKOUTL Input 1 Volume" $DEFAULT_VOLUME | |
amixer_cset "SPKOUTR Input 1" AIF1RX2 | |
amixer_cset "SPKOUTR Input 1 Volume" $DEFAULT_VOLUME | |
# Unmute speaker output | |
amixer_cset "Speaker Digital Switch" on | |
} | |
playback_to_lineout() { | |
# Clear the HPOUT2 Input 1 and 2 mixers. This will ensure no previous paths | |
# are connected to the HPOUT2. Note: this doesn't include inputs 3 and 4... | |
amixer_cset "HPOUT2L Input 1" None | |
amixer_cset "HPOUT2R Input 1" None | |
amixer_cset "HPOUT2L Input 2" None | |
amixer_cset "HPOUT2R Input 2" None | |
# Setup HPOUT2 input path and volume | |
amixer_cset "HPOUT2L Input 1" AIF1RX1 | |
amixer_cset "HPOUT2L Input 1 Volume" $DEFAULT_VOLUME | |
amixer_cset "HPOUT2R Input 1" AIF1RX2 | |
amixer_cset "HPOUT2R Input 1 Volume" $DEFAULT_VOLUME | |
# Unmute HPOUT2 Output | |
amixer_cset "HPOUT2 Digital Switch" on | |
} | |
playback_to_headset() { | |
# Playback from AP to Headset | |
# Set path gain to -6dB for safety. ie max 0.5Vrms output level. | |
amixer_cset "HPOUT1 Digital Volume" 116 | |
# Clear the HPOUT1 Input 1 and 2 mixers. This will ensure no previous paths | |
# are connected to the HPOUT1. Note: this doesn't include inputs 3 and 4... | |
amixer_cset "HPOUT1L Input 1" None | |
amixer_cset "HPOUT1R Input 1" None | |
amixer_cset "HPOUT1L Input 2" None | |
amixer_cset "HPOUT1R Input 2" None | |
# Setup HPOUT1 input path and volume | |
amixer_cset "HPOUT1L Input 1" AIF1RX1 | |
amixer_cset "HPOUT1L Input 1 Volume" $DEFAULT_VOLUME | |
amixer_cset "HPOUT1R Input 1" AIF1RX2 | |
amixer_cset "HPOUT1R Input 1 Volume" $DEFAULT_VOLUME | |
# Unmute the HPOUT1 Outputs | |
amixer_cset "HPOUT1 Digital Switch" on | |
} | |
playback_to_spdif() { | |
# Playback to SPDIF Out Enable | |
amixer_cset "SPDIF Out Switch" on | |
# Setup WM5102 AIF2 stereo output source from AIF1 (data from AP), 0dB Gain | |
amixer_cset "Tx Source" AIF | |
amixer_cset "AIF2TX1 Input 1" AIF1RX1 | |
amixer_cset "AIF2TX1 Input 1 Volume" $DEFAULT_VOLUME | |
amixer_cset "AIF2TX2 Input 1" AIF1RX2 | |
amixer_cset "AIF2TX2 Input 1 Volume" $DEFAULT_VOLUME | |
} | |
# Main: set the correct output | |
case $output in | |
sp|speaker) | |
echo "\033[1mSetting playback to speaker...\033[0m" | |
reset_all | |
playback_to_speaker | |
;; | |
lo|lineout) | |
echo "\033[1mSetting playback to line out...\033[0m" | |
reset_all | |
playback_to_lineout | |
;; | |
digital|spdif) | |
echo "\033[1mSetting playback to SPDIF...\033[0m" | |
reset_all | |
playback_to_spdif | |
;; | |
*) | |
echo "\033[1;31mInvalid output: $output!\033[0m" | |
echo "-> use 'sp' or 'speaker' for speaker output;" | |
echo "-> use 'lo' or 'lineout' for line out;" | |
echo "-> use 'digital' or 'spdif' for digital output." | |
exit 1 | |
;; | |
esac | |
###EOF### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment