| #!/system/bin/sh |
| # |
| # Copyright (c) 2015 Nest Labs, Inc. |
| # All rights reserved. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| set -x |
| |
| AUDIO_TOOL=/system/bin/audio-tool |
| TINYMIX="${AUDIO_TOOL} mix" |
| |
| die() { |
| echo "ERROR: $@" 1>&2 |
| exit 0 |
| } |
| |
| set_defaults() { |
| # QCOM has 1000 mixer controls, and they are fragile. Merely observing |
| # some of them causes crashes. Therefore we focus on a subset of controls |
| # that we manipulate. |
| |
| ${TINYMIX} 'QUIN_MI2S_RX Audio Mixer MultiMedia1' 0 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX1' 0 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX2' 0 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX3' 0 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX4' 0 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC1 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'DEC1 Volume' 84 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC2 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'DEC3 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'DEC4 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'MultiMedia1 Mixer SLIM_0_TX' 0 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX1 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX2 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX3 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX4 MUX' ZERO || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM_0_TX Channels' One || die "failed to set mixer value" |
| } |
| |
| config_single_mic_recording() { |
| ${TINYMIX} 'MultiMedia1 Mixer SLIM_0_TX' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM_0_TX Channels' One || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX1' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX1 MUX' DEC1 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC1 MUX' DMIC1 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC1 Volume' 68 || die "failed to set mixer value" |
| } |
| |
| config_single_other_mic_recording() { |
| ${TINYMIX} 'MultiMedia1 Mixer SLIM_0_TX' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM_0_TX Channels' One || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX3' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX3 MUX' DEC3 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC3 MUX' DMIC3 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC3 Volume' 68 || die "failed to set mixer value" |
| } |
| |
| config_four_mic_recording() { |
| ${TINYMIX} 'MultiMedia1 Mixer SLIM_0_TX' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX1' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX2' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX3' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'AIF1_CAP Mixer SLIM TX4' 1 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM_0_TX Channels' Four || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX1 MUX' DEC1 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC1 MUX' DMIC1 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX2 MUX' DEC2 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC2 MUX' DMIC2 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX3 MUX' DEC3 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC3 MUX' DMIC3 || die "failed to set mixer value" |
| ${TINYMIX} 'SLIM TX4 MUX' DEC4 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC4 MUX' DMIC4 || die "failed to set mixer value" |
| if [ ! -z "$1" ]; then |
| if [ $1 -gt 83 ] && [ $1 -lt 125 ] ; then |
| ${TINYMIX} 'DEC1 Volume' $1 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC2 Volume' $1 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC3 Volume' $1 || die "failed to set mixer value" |
| ${TINYMIX} 'DEC4 Volume' $1 || die "failed to set mixer value" |
| fi |
| fi |
| } |
| |
| config_speaker_playback() { |
| ${TINYMIX} 'QUIN_MI2S_RX Audio Mixer MultiMedia1' 1 || die "failed to set mixer value" |
| if [ ! -z "$1" ]; then |
| if [ $1 -gt 0 ] && [ $1 -lt 512 ] ; then |
| ${TINYMIX} 'Speaker Driver Playback Volume' $1 || die "failed to set mixer value" |
| fi |
| fi |
| } |
| |
| config_loopback() { |
| config_four_mic_recording $1 |
| config_speaker_playback $2 |
| } |
| |
| usage() { |
| cat <<EOF |
| usage: audio-config <USE-CASE> |
| |
| Where <USE-CASE> may be one of: |
| |
| default, d, dflt - set mixers to what are (normally) the boot-up |
| default values. |
| |
| 1mic, 1 - configure for single DMIC recording. |
| |
| 4mic, 4 - configure for 4x DMIC recording. |
| |
| loopback, l - configure for 4x DMIC + Playback. |
| |
| playback, p - configure for playback on speaker driver. |
| |
| EOF |
| } |
| |
| if [ $# -eq 0 ] ; then |
| usage |
| exit 0 |
| fi |
| |
| if [ $# -gt 3 ] ; then |
| usage |
| die "Too many argument given" |
| fi |
| |
| set_defaults |
| |
| case $1 in |
| default|d|dflt) |
| ;; |
| 1mic|1) |
| config_single_mic_recording |
| ;; |
| 4mic|4) |
| config_four_mic_recording $2 |
| ;; |
| playback|p) |
| config_speaker_playback $2 |
| ;; |
| loopback|l) |
| config_loopback $2 $3 |
| ;; |
| alt) |
| config_single_other_mic_recording |
| ;; |
| *) |
| usage |
| die "Invalid/unsupported argument" |
| ;; |
| esac |