Recording 145.500 MHz from an SDR receiver for the record
Archive post.
Translated from Ukrainian.
We’ve already worked out recording to a file from an SDR receiver, so now we can build an audio archive of the traffic on the calling frequency. Remember the note on recording from a scanner, and let’s try to combine it all into one handy script.
The script below needs a working OpenWebRX server.
#!/bin/bash
# частота мониторинга, в данном случае вызывной канал на 2м диапазоне
FREQ=145500000
# основная папка для складывания записей
ARCHIVE_FOLDER="/tmp/sdr_archive"
# временный файл
TEMP_FILE="/tmp/ham_145500.ogg"
# проверяем что бы существовал pipe для записи уровня шумодава
fifo_file="/tmp/record_squelch_pipe"
if [ -f "$fifo_file" ]
then
echo "squelch pipe $fifo_file founded."
else
echo "$fifo_file not found. created it"
mkfifo $fifo_file
fi
# подсчет частоты сдвига
# числа 145000000 и 2000000 нужно брать из OpenWebRX сервера: center_freq и samp_rate соответственно
FREQ_OFFSET=`python -c "print float(145000000-$FREQ)/2000000"`
# записываем занчение выше которого должен срабатывать шумодав
echo "0.0002" > $fifo_file
# функция которая ждет пока не появится звук на входе звуковой карте
# и остановится когда звук пропадет
function vox() {
echo "-----[ START recording cycle ]-----"
rm -rf $TEMP_FILE
nc -v 127.0.0.1 4951 | csdr convert_u8_f | csdr shift_addition_cc $FREQ_OFFSET | csdr fir_decimate_cc 181 0.000828675 HAMMING | csdr squelch_and_smeter_cc --fifo $fifo_file --outfifo /dev/null 5 1 | csdr fmdemod_quadri_cf | csdr limit_ff | csdr deemphasis_nfm_ff 11025 | csdr fastagc_ff | csdr convert_f_s16 | sox -r 11025 -e signed -b 16 -c 1 -t raw - $TEMP_FILE silence 1 00:01 0.1% 1 00:03 3%
wait
echo "-----[ END recording cycle ]-----"
echo "-----[ prepare file ]-----"
# проверяем что полученный в итоге файл имеет хоть какой-то размер (800байт)
for i in $TEMP_FILE ; do
b=`stat -c %s "$i"`
if [ $b -ge 800 ] ; then
# создаем подпапку 2017/10/14
ARCHIVE_SUB_FOLDER=`date +%Y/%m/%d`
mkdir -p $ARCHIVE_FOLDER/$ARCHIVE_SUB_FOLDER
# формируем имя файла из даты когда закончилась запись
NAME=`date +%s.%H_%M_%S`
FILENAME=$ARCHIVE_FOLDER/$ARCHIVE_SUB_FOLDER/$NAME.ogg
echo "MOVE $TEMP_FILE to $FILENAME"
mv $TEMP_FILE $FILENAME
else
rm -rf $TEMP_FILE
fi
done
echo "-----[ end cycle ]-----"
# повторяем цикл
vox
}
# запускаем функцию записи в цикле
vox
Then, as usual, make it executable with chmod +x ./record_from_sdr.sh and run ./record_from_sdr.sh.
UPDATE: October 15, 2017
To make the files smaller and playable in most browsers, I switched from OGG to MP3.
On Ubuntu that means installing the package sudo apt-get install libsox-fmt-mp3
and changing the extension in the script from .ogg to .mp3.
To convert all .ogg files in a folder, run:
for f in *.ogg; do sox "$f" "${f%.ogg}.mp3"; done