diff --git a/generate-am-radio/bin/build b/generate-am-radio/bin/build new file mode 100755 index 0000000..898df0c --- /dev/null +++ b/generate-am-radio/bin/build @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc filter-radio.c -static -lm -o filter-radio diff --git a/generate-am-radio/bin/filter-radio.c b/generate-am-radio/bin/filter-radio.c new file mode 100644 index 0000000..7db13a7 --- /dev/null +++ b/generate-am-radio/bin/filter-radio.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include + +float level_with_fading (float level, long t, float fast_period, float medium_period, float long_period, float extralong_period) { + return level + + 0.4 * level * sin(t / extralong_period) + + 0.3 * level * sin(t / long_period) + + 0.2 * level * sin(t / medium_period) + + 0.1 * level * sin(t / fast_period); +} + +int main (int argc, char *argv[]) { + + // Randomize from frequency value + srand(atof(argv[3])); + + // Signal component levels + // Payload signal + float signal_level_mkv = 10.0; + if (argc > 4) { + signal_level_mkv = (float) atoi(argv[4]); + } + float signal_fading_fast_period = rand() % 1000 + 300, + signal_fading_medium_period = rand() % 15000 + 17500, + signal_fading_long_period = rand() % 40000 + 60000, + signal_fading_extralong_period = rand() % 200000 + 150000; + + // Payload signal echo + float echo_level_mkv = 0.3, + echo_fading_fast_period = rand() % 2000 + 1500, + echo_fading_medium_period = rand() % 7000 + 4000, + echo_fading_long_period = rand() % 50000 + 25000, + echo_fading_extralong_period = rand() % 200000 + 150000; + const int echo_size_samples = 1000; + + // Background signal + float bg_signal_level_mkv = 0.2, + bg_signal_fading_fast_period = rand() % 2000 + 1500, + bg_signal_fading_medium_period = rand() % 7000 + 4000, + bg_signal_fading_long_period = rand() % 50000 + 25000, + bg_signal_fading_extralong_period = rand() % 200000 + 150000; + + // Interference noise + float interference_level_mkv = 0.02, + interference_freq_factor = rand() % 1000 / 1000.0 * 3.0 + 1.0, + interference_fading_fast_period = rand() % 2000 + 1500, + interference_fading_medium_period = rand() % 7000 + 4000, + interference_fading_long_period = rand() % 50000 + 25000, + interference_fading_extralong_period = rand() % 200000 + 150000; + + // White (or brown) noise + float noise_level_mkv = 0.1; + + // Vars + // Signal component values + float signal, + echo, + bg_signal, + noise, noise_src, + interference; + + // Current levels + float signal_cur_level, + echo_cur_level, + bg_signal_cur_level, + noise_cur_level, + interference_cur_level; + float common_cur_level, common_signal_src; + + // Other vars + float output, prev_output; + + // Time counter + long t = 0; + + // Signal source + FILE *f, *bg_f; + f = fopen(argv[1], "r"); + bg_f = fopen(argv[2], "r"); + + // Echo source + float echo_buffer[echo_size_samples]; + memset(echo_buffer, 0, echo_size_samples); + + while (!feof(f)) { + + // Signals + signal = fgetc(f); + echo = echo_buffer[t % echo_size_samples]; + bg_signal = fgetc(bg_f); + interference = 100 + 100 * sin(t / interference_freq_factor); + noise_src = rand() % 256; + noise = 0.5 * noise + 0.5 * noise_src; + + // Current levels + signal_cur_level = level_with_fading(signal_level_mkv, t, signal_fading_fast_period, signal_fading_medium_period, signal_fading_long_period, signal_fading_extralong_period); + echo_cur_level = level_with_fading(echo_level_mkv, t, echo_fading_fast_period, echo_fading_medium_period, echo_fading_long_period, echo_fading_extralong_period); + bg_signal_cur_level = level_with_fading(bg_signal_level_mkv, t, bg_signal_fading_fast_period, bg_signal_fading_medium_period, bg_signal_fading_long_period, bg_signal_fading_extralong_period); + noise_cur_level = noise_level_mkv; + interference_cur_level = level_with_fading(interference_level_mkv, t, interference_fading_fast_period, interference_fading_medium_period, interference_fading_long_period, interference_fading_extralong_period); + + // Common level + common_cur_level = signal_cur_level + echo_cur_level + bg_signal_cur_level + noise_cur_level + interference_cur_level; + + // Common signal + common_signal_src = signal * signal_cur_level + echo * echo_cur_level + bg_signal * bg_signal_cur_level + noise * noise_cur_level + interference * interference_cur_level; + + // Output with AGC + output = common_signal_src / common_cur_level; + printf("%c", (char)(0.5 * output + 0.5 * prev_output)); + + echo_buffer[t % echo_size_samples] = signal; + prev_output = output; + + t++; + } + + fclose(f); + fclose(bg_f); + return 0; +} diff --git a/generate-am-radio/bin/play-to-stream-vorbis.xml.tpl b/generate-am-radio/bin/play-to-stream-vorbis.xml.tpl new file mode 100644 index 0000000..ba2f4e4 --- /dev/null +++ b/generate-am-radio/bin/play-to-stream-vorbis.xml.tpl @@ -0,0 +1,18 @@ + + http://127.0.0.1:8092/[FREQ]am + hackme + + VORBIS + stdin + + 1 + + /[FREQ]am + + 32 + 3.0 + 1 + 8000 + + 0 + diff --git a/generate-am-radio/bin/stream-radio b/generate-am-radio/bin/stream-radio new file mode 100755 index 0000000..9024fb0 --- /dev/null +++ b/generate-am-radio/bin/stream-radio @@ -0,0 +1,16 @@ +#!/bin/bash + +DIR=`cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd` + +sed 's/\[FREQ\]/'$3'/g' $DIR/play-to-stream-vorbis.xml.tpl > $DIR/config/play-to-stream-vorbis-${3}am.xml +chmod 644 $DIR/config/play-to-stream-vorbis-${3}am.xml + +mkfifo $DIR/pipes/pipe-main-${3}am +mkfifo $DIR/pipes/pipe-bg-${3}am + +ffmpeg -v 0 -i $1 -f wav -ar 8000 -ac 1 -acodec pcm_u8 - | pv -q > $DIR/pipes/pipe-main-${3}am & +ffmpeg -v 0 -i $2 -f wav -ar 8000 -ac 1 -acodec pcm_u8 - | pv -q > $DIR/pipes/pipe-bg-${3}am & + +$DIR/filter-radio $DIR/pipes/pipe-main-${3}am $DIR/pipes/pipe-bg-${3}am $3 $4 \ + | oggenc -Q -r -B 8 -R 8000 -C 1 - -o - \ + | ezstream -c $DIR/config/play-to-stream-vorbis-${3}am.xml diff --git a/generate-am-radio/stop-all-streams b/generate-am-radio/stop-all-streams new file mode 100755 index 0000000..af8f2c8 --- /dev/null +++ b/generate-am-radio/stop-all-streams @@ -0,0 +1,6 @@ +#!/bin/bash + +killall stream-radio +killall ffmpeg +killall ezstream +rm bin/pipes/* diff --git a/generate-am-radio/stream-template-1206am b/generate-am-radio/stream-template-1206am new file mode 100755 index 0000000..b2c44b2 --- /dev/null +++ b/generate-am-radio/stream-template-1206am @@ -0,0 +1,10 @@ +#!/bin/bash + +DIR=`cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd` + +$DIR/bin/stream-radio \ + "PUT_YOUR_FAVORITE_AUDIO_STREAM_HERE"\ + "PUT_HERE_ANY_BACKGROUND_STREAM"\ + 1206\ + 1\ + & diff --git a/icecast/icecast-config.xml b/icecast/icecast-config.xml new file mode 100644 index 0000000..2edf894 --- /dev/null +++ b/icecast/icecast-config.xml @@ -0,0 +1,51 @@ + + + 100 + 10 + 5 + 131072 + 30 + 30 + 30 + 1 + 32768 + + + + hackme + hackme + admin + hackme + + + localhost + + + 8092 + + + 1 + + /usr/share/icecast2 + . + /usr/share/icecast2/web + /usr/share/icecast2/admin + /usr/share/icecast2/icecast.pid + + + + + access.log + error.log + 1 + 10000 + + + + 0 + + icecast2 + icecast + + + diff --git a/icecast/start-icecast b/icecast/start-icecast new file mode 100755 index 0000000..d336c08 --- /dev/null +++ b/icecast/start-icecast @@ -0,0 +1,4 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +icecast2 -b -c $DIR/icecast-config.xml diff --git a/icecast/stop-icecast b/icecast/stop-icecast new file mode 100755 index 0000000..d9b34e2 --- /dev/null +++ b/icecast/stop-icecast @@ -0,0 +1,3 @@ +#!/bin/bash + +pkill icecast2