forked from pavhofman/nonlinear-compensation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrate
executable file
·36 lines (28 loc) · 1.07 KB
/
calibrate
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
#!/bin/bash -eu
export AUDIODRIVER=alsa
export AUDIODEV=hw:0,0
RATE=96000
FILE=cal.wav
VOL=${1:-0dB}
POLYDEG=${2:-5}
FREQ=${3:-1000}
REALFREQ=${4:-1000}
LEN=${5:-2}
if [[ "$LEN" != 0 ]]; then
pasuspender sleep $((LEN+3)) || err=$? &
sox -R -r $RATE -b 32 -c 2 -d "$FILE" trim 1 $LEN &
sleep 0.5
play -q -R -r $RATE -b 32 -n synth $((LEN+2)) sin $FREQ vol $VOL
wait
fi
octave/gen_compen_polynom.m $FILE 1 $POLYDEG ${REALFREQ} q
octave/gen_compen_polynom.m $FILE 2 $POLYDEG ${REALFREQ} q
C1=$(grep -c "^pcm.calibrated_in.ttable.0.0 {.*}" ~/.asoundrc) || { echo "Error: missing ttable.0.0 line in .asoundrc" >&2; exit 1; }
C2=$(grep -c "^pcm.calibrated_in.ttable.1.1 {.*}" ~/.asoundrc) || { echo "Error: missing ttable.1.1 line in .asoundrc" >&2; exit 1; }
sed -i \
-e "/^pcm.calibrated_in.ttable.0.0 {.*}/s/ .*/ { $(cat ${FILE%.wav}.polycoeff1) }/" \
-e "/^pcm.calibrated_in.ttable.1.1 {.*}/s/ .*/ { $(cat ${FILE%.wav}.polycoeff2) }/" \
~/.asoundrc
grep "^pcm.calibrated_in.ttable" ~/.asoundrc
# trigger .asoundrc reload on the next open of device
sudo touch /usr/share/alsa/alsa.conf