-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrtlsdr-airband.sh
314 lines (271 loc) · 7.87 KB
/
rtlsdr-airband.sh
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
# Copyright (c) 2019 by Philip Collier, radio AB9IL <[email protected]>
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version. There is NO warranty; not even for
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Capture a wide RF bandwidth and operate a multichannel SDR receiver.
streamname="RTLSDR-Airband Multichannel"
genre="Voice Communicatons"
#Get the SDR frequency offset (ppm)
corr=$(cat /usr/local/etc/sdr_offset)
#Get the SDR gain (gain)
gain=$(cat /usr/local/etc/sdr_gain)
#Get the SoapySDR driver string
devdriver=$(cat /usr/local/etc/sdr_driver)
#Get the SoapySDR device key, such as "rtl=0"
devkey=$(cat /usr/local/etc/sdr_key)
# strip the number from the device key
key="$(echo "$devkey" | cut -f2 -d "=")"
# file with voice frequencies
voicefreqs="/usr/local/etc/VOICE_FREQS"
#Get the frequency and mode list
readarray FREQLIST < "$voicefreqs"
# compute the median frequency here...
MYLIST=()
for thefreq in "${FREQLIST[@]}"; do
a=$(echo "$thefreq" | cut -f1 -d ",")
MYLIST+=("${a}")
done
IFS=$'\n'
ctrfreq=$(awk '{arr[NR]=$1} END {if (NR%2==1) print arr[(NR+1)/2];
else print (arr[NR/2]+arr[NR/2+1])/2}' <<< sort <<< "${MYLIST[*]}")
# Format the center frequency the SDR will use
ctrfreq=$(printf "%8.2f\n" "$ctrfreq")
echo "Found the frequency list in ${voicefreqs}: ${MYLIST[*]}"
echo "Median frequency is ${ctrfreq}"
unset IFS
# The number of channels
channels=${#MYLIST[@]}
start0(){
#start rtlsdr-airband on PulseAudio
cp -f /usr/local/etc/rtl_airband-pulse.conf /usr/local/etc/rtl_airband.conf
/usr/local/bin/rtl_airband &
# Force pulseaudio and rtl_airband to work
sleep 3
/etc/init.d/alsa-utils restart
pulseaudio -k
# Remind the user to stop manually.
WINDOW=$(zenity --info --height 100 --width 350 \
--title="Multichannel Voice - Running" \
--text="The multichannel receiver is running.
Output is on PulseAudio.
To stop, use this application and select \"Stop Multichannel Voice.\""
);
}
start1(){
#start rtlsdr-airband on the Icecast server
cp -f /usr/local/etc/rtl_airband-icecast.conf /usr/local/etc/rtl_airband.conf
systemctl start icecast2
sleep 3
#start rtlsdr-airband
/usr/local/bin/rtl_airband &
sleep 3
firefox --new-tab http://localhost:7000/mixer1.mp3 &
# Remind the user to stop manually.
WINDOW=$(zenity --info --height 100 --width 350 \
--title="Multichannel Voice - Running" \
--text="The multichannel receiver is running.
Output is on the Icecast server.
To stop, use this application and select \"Stop Multichannel Voice.\""
);
}
start2(){
#build the config file for using PulseAudio
build_pulse
#start reception with output on PulseAudio
start0
}
start3(){
#build the config file for using Icecast
build_icecast
#start reception and output on Icecast
start1
}
stop(){
#stop rtlsdr-airband
killall -9 rtl_airband "$(lsof -t -i:8000)"
#stop the icecast2 server
systemctl stop icecast2
echo "STOPPED RTLSDR-Airband. Alpha Mike Foxtrot..."
exit
}
build_pulse(){
# data and config for PulseAudio
#top of the file, defining SDR tuning, etc
echo '# This is a sample configuration file for RTLSDR-Airband.
# Just a single SDR with multiple AM channels in multichannel mode.
# Each channel is sent to PulseAusio. Settings are described
# in reference.conf.
# increase fft size (min 256, max 8192)
fft_size = 1024
mixers: {
mixer1: {
outputs: (
{
type = "pulse";
stream_name = "'$streamname'";
genre = "'$genre'";
}
);
}
};
devices:
({
type = "soapysdr";
device_string = "driver='$devdriver',soapy='$key'";
gain = '$gain';
centerfreq = '$ctrfreq';
correction = '$corr';
channels:
(' > /usr/local/etc/rtl_airband-pulse.conf
#write the channel and signal modulation confifig data here...
n=1
comma=","
for thechannel in "${FREQLIST[@]}"; do
freq=$(echo $thechannel | cut -f1 -d ",")
sigmode=$(echo $thechannel | cut -f2 -d ",")
if (( $n == $channels )); then
comma=""
fi
# for multiple channels use stereo
if [[ $(( $n % 2 )) -eq 0 ]];
then bal="+0.6" ;
else bal="-0.6" ;
fi
# for one channel use mono
if (( $channels == 1 ));
then bal="0.0"
fi
# middle of the file, defining channels and outputs
echo '{
freq = '$freq';
modulation = "'$sigmode'";
outputs: (
{
type = "mixer";
name = "mixer1";
balance = '$bal';
}
);
}'$comma >> /usr/local/etc/rtl_airband-pulse.conf
let "n++"
done
#bottom of the file
echo ' );
}
);' >> /usr/local/etc/rtl_airband-pulse.conf
}
build_icecast(){
# data and config for icecast
#top of the file, defining SDR tuning, etc
echo '# This is a sample configuration file for RTLSDR-Airband.
# Just a single SDR with multiple AM channels in multichannel mode.
# Each channel is sent to the Icecast server. Settings are described
# in reference.conf.
# increase fft size (min 256, max 8192)
fft_size = 1024
mixers: {
mixer1: {
outputs: (
{
type = "icecast";
server = "localhost";
port = 7000;
mountpoint = "mixer1.mp3";
name = "'$streamname'";
genre = "'$genre'";
username = "source";
password = "skywave";
}
);
}
};
devices:
({
type = "soapysdr";
device_string = "driver='$devdriver',soapy='$key'";
gain = '$gain';
centerfreq = '$ctrfreq';
correction = '$corr';
channels:
(' > /usr/local/etc/rtl_airband-icecast.conf
#write the channel and mode confifig data here...
n=1
comma=","
for thechannel in "${FREQLIST[@]}"; do
freq=$(echo $thechannel | cut -f1 -d ",")
sigmode=$(echo $thechannel | cut -f2 -d ",")
if (( $n == $channels )); then
comma=""
fi
# for multiple channels use stereo
if [[ $(( $n % 2 )) -eq 0 ]];
then bal="+0.6" ;
else bal="-0.6" ;
fi
# for one channel use mono
if (( $channels == 1 ));
then bal="0.0"
fi
# middle of the file, defining channels and outputs
echo '{
freq = '$freq';
modulation = "'$sigmode'";
outputs: (
{
type = "mixer";
name = "mixer1";
balance = '$bal';
}
);
}'$comma >> /usr/local/etc/rtl_airband-icecast.conf
let "n++"
done
#bottom of the file
echo ' );
}
);' >> /usr/local/etc/rtl_airband-icecast.conf
}
backupconf(){
cp -f /usr/local/etc/rtl_airband.conf /usr/local/etc/rtl_airband.conf.bak
}
restoreconf(){
cp -f /usr/local/etc/rtl_airband.conf.bak /usr/local/etc/rtl_airband.conf
}
notifyerror(){
echo "Something went wrong!!!!!!"
WINDOW=$(zenity --info --height 100 --width 350 \
--title="Multicgannel Voice - Error." \
--text="Something went wrong!!!!!!");
}
ans=$(zenity --list --title "Multichannel Voice" --height 540 --width 500 \
--text "Multichannel Voice functions:
--Uses SoapySDR drivers
--Simultaneous multichannel demodulation
--Set demodulation independently per channel
--Stereo mixing for for multiple channels
--Softwaare powered by \"RTLSDR-Airband\"
--Edit the frequencies in /usr/local/etc/VOICE_FREQS
The format is one frequency and mode per line, comma separated.
Frequencies:
${MYLIST[*]}
" \
--radiolist --column "Pick" --column "Action" \
FALSE "Start Multichannel Voice (PulseAudio)" \
FALSE "Set channels and start Multichannel Voice (PulseAudio)" \
FALSE "Backup the current config file" \
FALSE "Restore the config file from a backup" \
FALSE "Edit the frequency list" \
TRUE "Stop Multichannel Voice" \
);
[[ "$ans" == "Start Multichannel Voice (PulseAudio)" ]] && start0
# [[ "$ans" == "Start Multichannel Voice (Icecast)" ]] && start1
[[ "$ans" == "Set channels and start Multichannel Voice (PulseAudio)" ]] && start2
# [[ "$ans" == "Set channels and start Multichannel Voice (Icecast)" ]] && start3
[[ "$ans" == "Backup the current config file" ]] && backupconf
[[ "$ans" == "Restore the config file from a backup" ]] && restoreconf
[[ "$ans" == "Edit the frequency list" ]] && \
x-terminal-emulator -e vi "$voicefreqs"
[[ "$ans" == "Stop Multichannel Voice" ]] && stop