forked from TheBigW/DRC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
measure
executable file
·162 lines (140 loc) · 5.05 KB
/
measure
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
# Automatic measuring script
# Copyright (C) 2002-2005 Denis Sbragion
# This program may be freely redistributed under the terms of
# the GNU GPL and is provided to you as is, without any warranty
# of any kind. Please read the file "COPYING" for details.
# Useful programs
ECHO="echo"
RM="rm"
GLSWEEP="glsweep"
SOX="sox"
LSCONV="lsconv"
ARECORD="arecord"
SYNC="sync"
SLEEP="sleep"
#TEST_MODE=true
# Default parameters
TMP="/tmp"
LEADIN="0.05"
LEADOUT="0.005"
MINGAIN="0.1"
DLSTART="0.9"
$ECHO
$ECHO "Automatic measuring script."
$ECHO "Copyright (C) 2002-2005 Denis Sbragion"
$ECHO
$ECHO "This program may be freely redistributed under the terms of"
$ECHO "the GNU GPL and is provided to you as is, without any warranty"
$ECHO "of any kind. Please read the file "COPYING" for details."
$ECHO
# Command line check
if [[ $# < 12 ]]; then
$ECHO "Usage:"
$ECHO " measure bits rate startf endf lslen lssil indev outdev impfile amplitude recording_channel overall_output_channels current output channel"
$ECHO
$ECHO " bits: measuring bits (16, 24 or 32)"
$ECHO " rate: sample rate"
$ECHO " startf: sweep start frequency in Hz"
$ECHO " endf: sweep end frequency in Hz"
$ECHO " lslen: log sweep length in seconds"
$ECHO " lssil: log sweep silence length in seconds"
$ECHO " indev: ALSA input device"
$ECHO " outdev: ALSA output device"
$ECHO " amplitude of sweep file 0.1 .. 1"
$ECHO " recording chanel to use (device dependend 1..n)"
$ECHO " overall number of audio channels (device dependend 2..n)"
$ECHO " overall number of audio channels (current audio channel to measure in the range of overall audio channels)"
$ECHO
$ECHO "example for a typical stereo measurement:"
$ECHO "example: measure 32 44100 5 21000 45 2 hw:1,0 hw:1,0 impulse.pcm 0.5 2 0"
$ECHO
exit 0
fi
# Get command line parameters
BITS="$1"
RATE="$2"
STARTF="$3"
ENDF="$4"
LSLEN="$5"
LSSIL="$6"
INDEV="$7"
OUTDEV="$8"
IMPFILE="$9"
AMPLITUDE="${10}"
REC_CHANNEL="${11}"
OVERALL_CHANNELS="${12}"
CURRENT_CHANNEL="${13}"
SWEEPFILE="sweep.pcm"
ARECORDFMT="S32_LE"
SOXFMT="-e signed-integer -b 32"
#PLAY_AC3=true
# Generate the log sweep
$ECHO "all parameters " $BITS $RATE $STARTF $ENDF $LSLEN $LSSIL $INDEV $OUTDEV $IMPFILE $AMPLITUDE $REC_CHANNEL $OVERALL_CHANNELS $CURRENT_CHANNEL
PLAY_SWEEP=${TMP}/msplaysweep.wav
PLAY_SWEEP_AC3=${TMP}/msplaysweep.ac3
# determine channel to play the sweep to
if [ -z "$CURRENT_CHANNEL" ]; then
PLAY_SWEEP_PARAM=""
else
PLAY_SWEEP_PARAM="remix"
#TODO construct remix string based on CURRENT_CHANNEL and OVERALL_CHANNELS
for ((i=0;i<OVERALL_CHANNELS;i++));
do
PARAM=" 0"
if [ $i = $CURRENT_CHANNEL ]; then
PARAM=" 1"
fi
PLAY_SWEEP_PARAM="$PLAY_SWEEP_PARAM $PARAM"
done
fi
$ECHO "PLAY_SWEEP_PARAM : " $PLAY_SWEEP_PARAM
$ECHO "generating sweep " $RATE $AMPLITUDE $STARTF $ENDF $LSLEN $LSSIL $LEADIN $LEADOUT ${TMP}/msrawsweep.pcm ${TMP}/msinverse.pcm
$GLSWEEP $RATE $AMPLITUDE $STARTF $ENDF $LSLEN $LSSIL $LEADIN $LEADOUT ${TMP}/msrawsweep.pcm ${TMP}/msinverse.pcm
# Convert to WAV file
$ECHO "Converting sweep to play format..."
$SOX -t raw -r $RATE -c 1 -e float -b32 ${TMP}/msrawsweep.pcm -t wav -c $OVERALL_CHANNELS $SOXFMT $PLAY_SWEEP $PLAY_SWEEP_PARAM
if test $OVERALL_CHANNELS -gt 2
then
MPLAYER_ALSA_DEV=${OUTDEV//:/=}
if [ -z "$PLAY_AC3" ]; then
PLAY_COMMAND="mplayer -ao alsa:device=$MPLAYER_ALSA_DEV $PLAY_SWEEP -channels $OVERALL_CHANNELS"
else
echo "more then 2 channels: "$OVERALL_CHANNELS" performing AC3 conversions of"$PLAY_SWEEP" to "$PLAY_SWEEP_AC3
aften $PLAY_SWEEP $PLAY_SWEEP_AC3
PLAY_COMMAND="mplayer -ao alsa:device=$MPLAYER_ALSA_DEV -ac hwac3 $PLAY_SWEEP_AC3"
fi
else
PLAY_COMMAND="aplay -D $OUTDEV $PLAY_SWEEP"
fi
echo "PLAY_COMMAND: "$PLAY_COMMAND
# Filesystem sync
$ECHO "Waiting 5 seconds for filesystem sync..."
$SYNC
$SLEEP 5
# Record the sweep
$ECHO "Sweep recording."
$SLEEP 1
RLEN=$(( $LSLEN + $LSSIL * 2 ))
REC_WAV_NAME=${TMP}/msrecsweep${CURRENT_CHANNEL}.wav
REC_PCM_NAME=${TMP}/msrecsweep${CURRENT_CHANNEL}.pcm
if [ -z "$TEST_MODE" ]; then
$PLAY_COMMAND &
$ARECORD -D $INDEV -t wav -r $RATE -f $ARECORDFMT -c 2 -d $RLEN $REC_WAV_NAME
else
$ECHO "simulating record!!!\n"
$PLAY_COMMAND
SIM_AMPLITUDE=$(bc <<< "scale=2;$AMPLITUDE +($CURRENT_CHANNEL/10)")
$ECHO "Sim Amplitude: "$SIM_AMPLITUDE" to : "$REC_WAV_NAME" and : "$REC_PCM_NAME
$ECHO "glsweep measure simulation : " $RATE $SIM_AMPLITUDE $STARTF $ENDF $LSLEN $LSSIL $LEADIN $LEADOUT $REC_PCM_NAME ${TMP}/sim_inverse.pcm
$GLSWEEP $RATE $SIM_AMPLITUDE $STARTF $ENDF $LSLEN $LSSIL $LEADIN $LEADOUT $REC_PCM_NAME ${TMP}/sim_inverse.pcm
$SOX -t raw -r $RATE -c 1 -e float -b32 $REC_PCM_NAME -t wav $SOXFMT $REC_WAV_NAME
fi
$ECHO "recorded sweep conversion"
$SOX $REC_WAV_NAME -t raw -r $RATE -e float -b 32 -c 1 $REC_PCM_NAME remix 1 0
IMP_FILE_PCM="${TMP}/measured_impulse${CURRENT_CHANNEL}.pcm"
# Extract the impulse response
$LSCONV $REC_PCM_NAME ${TMP}/msinverse.pcm $IMP_FILE_PCM $REF_PARAM
#convert the result to wav
$ECHO -t raw -r $RATE -c 1 -e float -b32 $IMP_FILE_PCM -t wav $IMPFILE
$SOX -t raw -r $RATE -c 1 -e float -b32 $IMP_FILE_PCM -t wav $IMPFILE