From 762a3ea78896a0ea654e65d6543e6708daabb37f Mon Sep 17 00:00:00 2001 From: Kamal Mostafa Date: Sat, 25 Aug 2012 00:32:11 -0700 Subject: [PATCH] minimodem: --volume sets tx amplitude --- src/minimodem.1.in | 5 +++++ src/minimodem.c | 19 +++++++++++++++---- src/simple-tone-generator.c | 19 ++++++++++++++----- src/simpleaudio.h | 2 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/minimodem.1.in b/src/minimodem.1.in index cb49296..b4936dc 100644 --- a/src/minimodem.1.in +++ b/src/minimodem.1.in @@ -73,6 +73,11 @@ encode or decode an audio file (extension sets audio format) .TP .B \-b, \-\-bandwidth {rx_bandwidth} .TP +.B \-v, \-\-volume {tx_amplitude or 'E'} +Sets the generated signal amplitude (default is 1.0). As a special case +useful for testing, the value 'E' sets the amplitude to the very small value +FLT_EPSILON. (This option applies to \-\-tx mode only). +.TP .B \-M, \-\-mark {mark_freq} .TP .B \-S, \-\-space {space_freq} diff --git a/src/minimodem.c b/src/minimodem.c index 33b7656..4573330 100644 --- a/src/minimodem.c +++ b/src/minimodem.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -257,7 +258,7 @@ benchmarks() // enable the sine wave LUT - simpleaudio_tone_init(1024); + simpleaudio_tone_init(1024, 1.0); sa_out = simpleaudio_open_stream(backend, SA_STREAM_PLAYBACK, SA_SAMPLE_FORMAT_S16, sample_rate, 1, @@ -277,7 +278,7 @@ benchmarks() // disable the sine wave LUT - simpleaudio_tone_init(0); + simpleaudio_tone_init(0, 1.0); sa_out = simpleaudio_open_stream(backend, SA_STREAM_PLAYBACK, SA_SAMPLE_FORMAT_S16, sample_rate, 1, @@ -328,6 +329,7 @@ usage() " -5, --baudot Baudot 5-N-1\n" " -f, --file {filename.flac}\n" " -b, --bandwidth {rx_bandwidth}\n" + " -v, --volume {amplitude or 'E'}\n" " -M, --mark {mark_freq}\n" " -S, --space {space_freq}\n" " -T, --txstopbits {m.n}\n" @@ -382,6 +384,7 @@ main( int argc, char*argv[] ) unsigned int sample_rate = 48000; unsigned int nchannels = 1; // FIXME: only works with one channel + float tx_amplitude = 1.0; unsigned int tx_sin_table_len = 4096; /* validate the default system audio mechanism */ @@ -424,6 +427,7 @@ main( int argc, char*argv[] ) { "baudot", 0, 0, '5' }, { "file", 1, 0, 'f' }, { "bandwidth", 1, 0, 'b' }, + { "volume", 1, 0, 'v' }, { "mark", 1, 0, 'M' }, { "space", 1, 0, 'S' }, { "txstopbits", 1, 0, 'T' }, @@ -435,7 +439,7 @@ main( int argc, char*argv[] ) { "benchmarks", 0, 0, MINIMODEM_OPT_BENCHMARKS }, { 0 } }; - c = getopt_long(argc, argv, "Vtrc:l:a85f:b:M:S:T:qAR:", + c = getopt_long(argc, argv, "Vtrc:l:a85f:b:v:M:S:T:qAR:", long_options, &option_index); if ( c == -1 ) break; @@ -475,6 +479,13 @@ main( int argc, char*argv[] ) band_width = atof(optarg); assert( band_width != 0 ); break; + case 'v': + if ( optarg[0] == 'E' ) + tx_amplitude = FLT_EPSILON; + else + tx_amplitude = atof(optarg); + assert( tx_amplitude > 0.0 ); + break; case 'M': bfsk_mark_f = atoi(optarg); assert( bfsk_mark_f > 0 ); @@ -642,7 +653,7 @@ main( int argc, char*argv[] ) */ if ( TX_mode ) { - simpleaudio_tone_init(tx_sin_table_len); + simpleaudio_tone_init(tx_sin_table_len, tx_amplitude); int tx_interactive = 0; if ( ! stream_name ) { diff --git a/src/simple-tone-generator.c b/src/simple-tone-generator.c index 4ca88a5..bc459f3 100644 --- a/src/simple-tone-generator.c +++ b/src/simple-tone-generator.c @@ -27,14 +27,17 @@ +static float tone_mag = 1.0; + static unsigned int sin_table_len; static short *sin_table_short; static float *sin_table_float; void -simpleaudio_tone_init( unsigned int new_sin_table_len ) +simpleaudio_tone_init( unsigned int new_sin_table_len, float mag ) { sin_table_len = new_sin_table_len; + tone_mag = mag; if ( sin_table_len != 0 ) { sin_table_short = realloc(sin_table_short, sin_table_len * sizeof(short)); @@ -45,10 +48,13 @@ simpleaudio_tone_init( unsigned int new_sin_table_len ) } unsigned int i; + unsigned short mag_s = 32767.0 * tone_mag + 0.5f; + if ( mag_s < 2 ) // "short epsilon" + mag_s = 2; for ( i=0; i