#!/bin/bash
modprobe snd-aloop

CHANNEL_PATH=/sys/relays/channels

R_VAL=30

# Turn on channels
echo 1 > $CHANNEL_PATH/ch1/mode
echo 1 > $CHANNEL_PATH/ch2/mode

echo 1 > /sys/class/gpio/gpio88/value
echo 1 > /sys/class/gpio/gpio89/value

# Talkback rheostat control (0 is wide open)
echo $R_VAL > /sys/bus/iio/devices/iio\:device1/out_resistance0_raw
echo $R_VAL > /sys/bus/iio/devices/iio\:device0/out_resistance0_raw

# ALSA SETTINGS
echo -e "\033[1;33m\033[1mStartup - Adjusting ASB Settings\033[0m"
amixer set 'DSP Setting' ASB >/dev/null 2>&1 
amixer set 'ADCFGA Left Mute' mute >/dev/null 2>&1 
amixer set 'ADCFGA Right Mute' mute >/dev/null 2>&1
amixer set 'ADC Level' 24 > /dev/null 2>&1
amixer set 'LO DAC' unmute >/dev/null 2>&1
amixer set 'LOL Output Mixer L_DAC' unmute >/dev/null 2>&1
amixer set 'LOR Output Mixer R_DAC' unmute >/dev/null 2>&1
amixer set 'LO Driver Gain' 0 >/dev/null 2>&1
amixer set 'HPL Output Mixer IN1_L' unmute > /dev/null 2>&1
amixer set 'CM_L to Left Mixer Negative Resistor' '10 kOhm' >/dev/null 2>&1
amixer set 'CM_R to Right Mixer Negative Resistor' '10 kOhm' >/dev/null 2>&1
amixer set 'IN1_L to Left Mixer Positive Resistor' '10 kOhm' >/dev/null 2>&1
amixer set 'IN1_L to Right Mixer Positive Resistor' 'Off' >/dev/null 2>&1
amixer set 'IN1_R to Left Mixer Positive Resistor' 'Off' >/dev/null 2>&1
amixer set 'IN1_R to Right Mixer Positive Resistor' '10 kOhm' >/dev/null 2>&1
amixer set 'IN3_L to Left Mixer Positive Resistor' 'Off' >/dev/null 2>&1
amixer set 'PGA Level' 0 > /dev/null 2>&1

#DRC Changes from Ed (2/9/2024)
echo -e "\033[1;33m\033[1mStartup - Adjusting ASB DRC Settings\033[0m"
amixer set 'DRC Attack' 0 >/dev/null 2>&1
amixer set 'DRC Decay' 0 >/dev/null 2>&1
amixer set 'DRC Enable' on >/dev/null 2>&1
amixer set 'DRC Hold Time' 0 >/dev/null 2>&1
amixer set 'DRC Hysteresis' 3 >/dev/null 2>&1
amixer set 'DRC Threshold' 0 >/dev/null 2>&1