minimodem: --volume sets tx amplitude
This commit is contained in:
parent
501ee25c7d
commit
762a3ea788
|
@ -73,6 +73,11 @@ encode or decode an audio file (extension sets audio format)
|
||||||
.TP
|
.TP
|
||||||
.B \-b, \-\-bandwidth {rx_bandwidth}
|
.B \-b, \-\-bandwidth {rx_bandwidth}
|
||||||
.TP
|
.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}
|
.B \-M, \-\-mark {mark_freq}
|
||||||
.TP
|
.TP
|
||||||
.B \-S, \-\-space {space_freq}
|
.B \-S, \-\-space {space_freq}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -257,7 +258,7 @@ benchmarks()
|
||||||
|
|
||||||
|
|
||||||
// enable the sine wave LUT
|
// 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_out = simpleaudio_open_stream(backend, SA_STREAM_PLAYBACK,
|
||||||
SA_SAMPLE_FORMAT_S16, sample_rate, 1,
|
SA_SAMPLE_FORMAT_S16, sample_rate, 1,
|
||||||
|
@ -277,7 +278,7 @@ benchmarks()
|
||||||
|
|
||||||
|
|
||||||
// disable the sine wave LUT
|
// 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_out = simpleaudio_open_stream(backend, SA_STREAM_PLAYBACK,
|
||||||
SA_SAMPLE_FORMAT_S16, sample_rate, 1,
|
SA_SAMPLE_FORMAT_S16, sample_rate, 1,
|
||||||
|
@ -328,6 +329,7 @@ usage()
|
||||||
" -5, --baudot Baudot 5-N-1\n"
|
" -5, --baudot Baudot 5-N-1\n"
|
||||||
" -f, --file {filename.flac}\n"
|
" -f, --file {filename.flac}\n"
|
||||||
" -b, --bandwidth {rx_bandwidth}\n"
|
" -b, --bandwidth {rx_bandwidth}\n"
|
||||||
|
" -v, --volume {amplitude or 'E'}\n"
|
||||||
" -M, --mark {mark_freq}\n"
|
" -M, --mark {mark_freq}\n"
|
||||||
" -S, --space {space_freq}\n"
|
" -S, --space {space_freq}\n"
|
||||||
" -T, --txstopbits {m.n}\n"
|
" -T, --txstopbits {m.n}\n"
|
||||||
|
@ -382,6 +384,7 @@ main( int argc, char*argv[] )
|
||||||
unsigned int sample_rate = 48000;
|
unsigned int sample_rate = 48000;
|
||||||
unsigned int nchannels = 1; // FIXME: only works with one channel
|
unsigned int nchannels = 1; // FIXME: only works with one channel
|
||||||
|
|
||||||
|
float tx_amplitude = 1.0;
|
||||||
unsigned int tx_sin_table_len = 4096;
|
unsigned int tx_sin_table_len = 4096;
|
||||||
|
|
||||||
/* validate the default system audio mechanism */
|
/* validate the default system audio mechanism */
|
||||||
|
@ -424,6 +427,7 @@ main( int argc, char*argv[] )
|
||||||
{ "baudot", 0, 0, '5' },
|
{ "baudot", 0, 0, '5' },
|
||||||
{ "file", 1, 0, 'f' },
|
{ "file", 1, 0, 'f' },
|
||||||
{ "bandwidth", 1, 0, 'b' },
|
{ "bandwidth", 1, 0, 'b' },
|
||||||
|
{ "volume", 1, 0, 'v' },
|
||||||
{ "mark", 1, 0, 'M' },
|
{ "mark", 1, 0, 'M' },
|
||||||
{ "space", 1, 0, 'S' },
|
{ "space", 1, 0, 'S' },
|
||||||
{ "txstopbits", 1, 0, 'T' },
|
{ "txstopbits", 1, 0, 'T' },
|
||||||
|
@ -435,7 +439,7 @@ main( int argc, char*argv[] )
|
||||||
{ "benchmarks", 0, 0, MINIMODEM_OPT_BENCHMARKS },
|
{ "benchmarks", 0, 0, MINIMODEM_OPT_BENCHMARKS },
|
||||||
{ 0 }
|
{ 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);
|
long_options, &option_index);
|
||||||
if ( c == -1 )
|
if ( c == -1 )
|
||||||
break;
|
break;
|
||||||
|
@ -475,6 +479,13 @@ main( int argc, char*argv[] )
|
||||||
band_width = atof(optarg);
|
band_width = atof(optarg);
|
||||||
assert( band_width != 0 );
|
assert( band_width != 0 );
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
if ( optarg[0] == 'E' )
|
||||||
|
tx_amplitude = FLT_EPSILON;
|
||||||
|
else
|
||||||
|
tx_amplitude = atof(optarg);
|
||||||
|
assert( tx_amplitude > 0.0 );
|
||||||
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
bfsk_mark_f = atoi(optarg);
|
bfsk_mark_f = atoi(optarg);
|
||||||
assert( bfsk_mark_f > 0 );
|
assert( bfsk_mark_f > 0 );
|
||||||
|
@ -642,7 +653,7 @@ main( int argc, char*argv[] )
|
||||||
*/
|
*/
|
||||||
if ( TX_mode ) {
|
if ( TX_mode ) {
|
||||||
|
|
||||||
simpleaudio_tone_init(tx_sin_table_len);
|
simpleaudio_tone_init(tx_sin_table_len, tx_amplitude);
|
||||||
|
|
||||||
int tx_interactive = 0;
|
int tx_interactive = 0;
|
||||||
if ( ! stream_name ) {
|
if ( ! stream_name ) {
|
||||||
|
|
|
@ -27,14 +27,17 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static float tone_mag = 1.0;
|
||||||
|
|
||||||
static unsigned int sin_table_len;
|
static unsigned int sin_table_len;
|
||||||
static short *sin_table_short;
|
static short *sin_table_short;
|
||||||
static float *sin_table_float;
|
static float *sin_table_float;
|
||||||
|
|
||||||
void
|
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;
|
sin_table_len = new_sin_table_len;
|
||||||
|
tone_mag = mag;
|
||||||
|
|
||||||
if ( sin_table_len != 0 ) {
|
if ( sin_table_len != 0 ) {
|
||||||
sin_table_short = realloc(sin_table_short, sin_table_len * sizeof(short));
|
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 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<sin_table_len; i++ )
|
for ( i=0; i<sin_table_len; i++ )
|
||||||
sin_table_short[i] = 32767 * sin(M_PI*2.0*(float)i/sin_table_len);
|
sin_table_short[i] = mag_s * sin(M_PI*2.0*(float)i/sin_table_len);
|
||||||
for ( i=0; i<sin_table_len; i++ )
|
for ( i=0; i<sin_table_len; i++ )
|
||||||
sin_table_float[i] = sinf(M_PI*2.0*(float)i/sin_table_len);
|
sin_table_float[i] = tone_mag * sinf(M_PI*2.0*(float)i/sin_table_len);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ( sin_table_short ) {
|
if ( sin_table_short ) {
|
||||||
|
@ -122,7 +128,7 @@ simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
||||||
float_buf[i] = sin_lu_float(SINE_PHASE_TURNS);
|
float_buf[i] = sin_lu_float(SINE_PHASE_TURNS);
|
||||||
} else {
|
} else {
|
||||||
for ( i=0; i<nsamples_dur; i++ )
|
for ( i=0; i<nsamples_dur; i++ )
|
||||||
float_buf[i] = sinf(SINE_PHASE_RADIANS);
|
float_buf[i] = tone_mag * sinf(SINE_PHASE_RADIANS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -134,8 +140,11 @@ simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
||||||
for ( i=0; i<nsamples_dur; i++ )
|
for ( i=0; i<nsamples_dur; i++ )
|
||||||
short_buf[i] = sin_lu_short(SINE_PHASE_TURNS);
|
short_buf[i] = sin_lu_short(SINE_PHASE_TURNS);
|
||||||
} else {
|
} else {
|
||||||
|
unsigned short mag_s = 32767.0 * tone_mag + 0.5f;
|
||||||
|
if ( mag_s < 2 ) // "short epsilon"
|
||||||
|
mag_s = 2;
|
||||||
for ( i=0; i<nsamples_dur; i++ )
|
for ( i=0; i<nsamples_dur; i++ )
|
||||||
short_buf[i] = 32767 * sinf(SINE_PHASE_RADIANS);
|
short_buf[i] = mag_s * sinf(SINE_PHASE_RADIANS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,6 @@ void
|
||||||
simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur);
|
simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur);
|
||||||
|
|
||||||
void
|
void
|
||||||
simpleaudio_tone_init( unsigned int new_sin_table_len );
|
simpleaudio_tone_init( unsigned int new_sin_table_len, float mag );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue