~mil/f_scripts

f_scripts/scripts/f_audio -rwxr-xr-x 2.3 KiB
c52a77c4Miles Alan f_audio: Set AIF1 DA0 to 20% rather then 100% to prevent distortion 4 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env osh
shopt -s strict:all
DEP="alsa-utils"
DEC="Adjust audio output devices and volume"
DOC="
  Allows you to adjust audio output devices and volume by using
  alsa-utils amixer. Enables toggling between speaker/headphone/earpiece 
  output as well as adjusting the volume based on a step value

  Set the variable \$F_AUDIO_STEP to modify the percentage points that
  volup/voldown will increment/decrement. 
"
VAR="
  F_AUDIO_STEP=1
"

statustext() {
  echo "Status:"
  echo "--------------"
  printf %b "earpiece \t$(deviceison "$GLOBAL_EARPIECE")\t$(devicevol "$GLOBAL_EARPIECE")\n"
  printf %b "headphone\t$(deviceison "$GLOBAL_HEADPHONE")\t$(devicevol "$GLOBAL_HEADPHONE")\n"
  printf %b "speaker  \t$(deviceison "$GLOBAL_SPEAKER")\t$(devicevol "$GLOBAL_SPEAKER")\n"
  echo "--------------"
}

deviceison() { amixer sget "$1" | grep -qE '\[on\]' && echo "x" || echo " "; }
devicevol() { amixer sget "$1" | grep -oE '([0-9]+)%' | head -n1; }
speaker() { amixer set "$GLOBAL_SPEAKER" toggle >/dev/null; }
earpiece() { amixer set "$GLOBAL_EARPIECE" toggle >/dev/null; }
headphone() { amixer set "$GLOBAL_HEADPHONE" toggle >/dev/null; }
volup() { volset ${F_AUDIO_STEP}+; }
voldown() { volset ${F_AUDIO_STEP}-; }
volset() {
  amixer sget "$GLOBAL_EARPIECE" | grep -qE '\[on\]' && amixer set "$GLOBAL_EARPIECE" $1 > /dev/null
  amixer sget "$GLOBAL_HEADPHONE" | grep -qE '\[on\]' && amixer set "$GLOBAL_HEADPHONE" $1 > /dev/null
  amixer sget "$GLOBAL_SPEAKER" | grep -qE '\[on\]' && amixer set "$GLOBAL_SPEAKER" $1 > /dev/null
}

devicepine64pinephone() {
  amixer set "AIF1 DA0" "20%" > /dev/null
  amixer set "AIF1 Slot 0 Digital DAC" unmute > /dev/null
  amixer set DAC "100%" > /dev/null
  amixer set DAC unmute > /dev/null
  GLOBAL_SPEAKER="Line Out"
  GLOBAL_HEADPHONE="Headphone"
  GLOBAL_EARPIECE="Earpiece"
}

main() {
  local RUN OPTS
  env | grep -q "^$(basename "$0" | tr '[a-z]' '[A-Z]')=" || eval "$VAR"
  eval "$(grep deviceinfo_codename /etc/deviceinfo | cut -d= -f2 | tr -d \"- | xargs -ID echo deviceD)"
  OPTS="speaker headphone earpiece volup voldown"
  [ -p /tmp/fbp.fifo ] && { echo -e "\b\f\r"; echo "$OPTS" | tr " " "\n"; } > /tmp/fbp.fifo
  while true; do
    clear
    statustext
    read -p "Run ($OPTS)" RUN
    "$RUN"
  done
}

if [ -n "$1" ]; then "$@"; else main; fi