configs

configs
git clone https://git.prime8.dev/configs.git
Log | Files | Refs | README

g14-volume-sync (1477B)


      1 #!/bin/bash
      2 # Sync AMP1/AMP2 Speaker volume with Master volume for ASUS G14 2025
      3 # Scales bass to maintain balance across volume range
      4 
      5 # Find the correct card number (ALC285 codec)
      6 find_card() {
      7 	for card in /proc/asound/card*/codec*; do
      8 		if grep -q "ALC285" "$card" 2>/dev/null; then
      9 			echo "${card}" | grep -oP 'card\K\d+'
     10 			return
     11 		fi
     12 	done
     13 }
     14 
     15 CARD=$(find_card)
     16 
     17 sync_volume() {
     18 	# Get Master volume percentage (0-100)
     19 	master_vol=$(amixer -c "$CARD" sget Master | grep -oP '\[\d+%\]' | head -1 | tr -d '[]%')
     20 
     21 	if [[ -n $master_vol ]]; then
     22 		# AMP range is 0-448, where 400 = 0dB (unity gain)
     23 		# At low master volumes, bass needs to be reduced more aggressively
     24 		# to maintain balance with tweeters
     25 		#
     26 		# Formula: Scale AMP volume so bass doesn't overpower at low volumes
     27 		# At master 100% -> AMP at 400 (0dB)
     28 		# At master 50%  -> AMP at ~350
     29 		# At master 10%  -> AMP at ~200
     30 		# This gives roughly matched perceived loudness
     31 
     32 		# Calculate AMP value: base of 150 + scaled portion up to 250 more
     33 		amp_val=$((150 + (master_vol * 250 / 100)))
     34 
     35 		# Clamp to valid range
     36 		if ((amp_val > 400)); then
     37 			amp_val=400
     38 		fi
     39 		if ((amp_val < 50)); then
     40 			amp_val=50
     41 		fi
     42 
     43 		amixer -c "$CARD" -q sset 'AMP1 Speaker' "$amp_val"
     44 		amixer -c "$CARD" -q sset 'AMP2 Speaker' "$amp_val"
     45 	fi
     46 }
     47 
     48 # Use pactl subscribe to watch for volume changes
     49 pactl subscribe | grep --line-buffered "sink" | while read -r line; do
     50 	if [[ $line == *"change"* ]]; then
     51 		sync_volume
     52 	fi
     53 done