diff --git a/src/minimodem.c b/src/minimodem.c index 8f9ab39..6f6ead4 100644 --- a/src/minimodem.c +++ b/src/minimodem.c @@ -389,6 +389,8 @@ main( int argc, char*argv[] ) float tx_amplitude = 1.0; unsigned int tx_sin_table_len = 4096; + float rxnoise_factor = 0.0; + /* validate the default system audio mechanism */ #if !(USE_PULSEAUDIO || USE_ALSA) # define _MINIMODEM_NO_SYSTEM_AUDIO @@ -411,6 +413,7 @@ main( int argc, char*argv[] ) MINIMODEM_OPT_LUT, MINIMODEM_OPT_FLOAT_SAMPLES, MINIMODEM_OPT_BENCHMARKS, + MINIMODEM_OPT_XRXNOISE, }; while ( 1 ) { @@ -439,6 +442,7 @@ main( int argc, char*argv[] ) { "lut", 1, 0, MINIMODEM_OPT_LUT }, { "float-samples", 0, 0, MINIMODEM_OPT_FLOAT_SAMPLES }, { "benchmarks", 0, 0, MINIMODEM_OPT_BENCHMARKS }, + { "Xrxnoise", 1, 0, MINIMODEM_OPT_XRXNOISE }, { 0 } }; c = getopt_long(argc, argv, "Vtrc:l:a85f:b:v:M:S:T:qAR:", @@ -525,6 +529,9 @@ main( int argc, char*argv[] ) benchmarks(); exit(0); break; + case MINIMODEM_OPT_XRXNOISE: + rxnoise_factor = atof(optarg); + break; default: usage(); } @@ -698,6 +705,8 @@ main( int argc, char*argv[] ) if ( ! sa ) return 1; + if ( rxnoise_factor != 0.0 ) + simpleaudio_set_rxnoise(sa, rxnoise_factor); /* * Prepare the input sample chunk rate diff --git a/src/simpleaudio-sndfile.c b/src/simpleaudio-sndfile.c index f58feb1..3520ac4 100644 --- a/src/simpleaudio-sndfile.c +++ b/src/simpleaudio-sndfile.c @@ -24,6 +24,7 @@ #if USE_SNDFILE #include +#include #include #include #include @@ -60,6 +61,15 @@ sa_sndfile_read( simpleaudio *sa, void *buf, size_t nframes ) sf_perror(s); return -1; } + + if ( sa->rxnoise != 0.0 ) { + int i; + float *fbuf = buf; + float f = sa->rxnoise * 2; + for ( i=0; isamplesize; } +void +simpleaudio_set_rxnoise( simpleaudio *sa, float rxnoise_factor ) +{ + sa->rxnoise = rxnoise_factor; +} + ssize_t simpleaudio_read( simpleaudio *sa, void *buf, size_t nframes ) { diff --git a/src/simpleaudio.h b/src/simpleaudio.h index 537a1e9..d9d329e 100644 --- a/src/simpleaudio.h +++ b/src/simpleaudio.h @@ -75,6 +75,9 @@ simpleaudio_get_format( simpleaudio *sa ); unsigned int simpleaudio_get_samplesize( simpleaudio *sa ); +void +simpleaudio_set_rxnoise( simpleaudio *sa, float rxnoise_factor ); + ssize_t simpleaudio_read( simpleaudio *sa, void *buf, size_t nframes ); diff --git a/src/simpleaudio_internal.h b/src/simpleaudio_internal.h index a6dc250..1613aca 100644 --- a/src/simpleaudio_internal.h +++ b/src/simpleaudio_internal.h @@ -35,6 +35,7 @@ struct simpleaudio { void * backend_handle; unsigned int samplesize; unsigned int backend_framesize; + float rxnoise; // only for the sndfile backend }; struct simpleaudio_backend {