From 22317f54fc507a1511b5a70ef0616d1d4da9dde8 Mon Sep 17 00:00:00 2001 From: Kamal Mostafa Date: Sat, 11 Aug 2012 10:07:12 -0700 Subject: [PATCH] simpleaudio: handle any audio sample rate --- src/minimodem.c | 15 +++++++++------ src/simple-tone-generator.c | 2 +- src/simpleaudio-alsa.c | 5 +---- src/simpleaudio-pulse.c | 8 +++----- src/simpleaudio-sndfile.c | 5 +++-- src/simpleaudio.h | 5 +++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/minimodem.c b/src/minimodem.c index 6691c13..659e431 100644 --- a/src/minimodem.c +++ b/src/minimodem.c @@ -285,6 +285,9 @@ main( int argc, char*argv[] ) simpleaudio * (*simpleaudio_open_system_audio)() = NULL; + unsigned int sample_rate = 48000; + unsigned int nchannels = 1; // FIXME: only works with one channel + /* configure the default system audio mechanism */ #if USE_PULSEAUDIO simpleaudio_open_system_audio = simpleaudio_open_stream_pulseaudio; @@ -511,6 +514,7 @@ main( int argc, char*argv[] ) tx_interactive = 0; #if USE_SNDFILE sa_out = simpleaudio_open_stream_sndfile(SA_STREAM_PLAYBACK, + sample_rate, nchannels, filename); #endif if ( ! sa_out ) @@ -519,6 +523,7 @@ main( int argc, char*argv[] ) if ( ! sa_out ) sa_out = simpleaudio_open_system_audio(SA_STREAM_PLAYBACK, + sample_rate, nchannels, program_name, "output audio"); if ( ! sa_out ) return 1; @@ -540,7 +545,9 @@ main( int argc, char*argv[] ) simpleaudio *sa = NULL; if ( filename ) { #if USE_SNDFILE - sa = simpleaudio_open_stream_sndfile(SA_STREAM_RECORD, filename); + sa = simpleaudio_open_stream_sndfile(SA_STREAM_RECORD, + sample_rate, nchannels, + filename); #endif if ( ! sa ) return 1; @@ -548,15 +555,11 @@ main( int argc, char*argv[] ) if ( ! sa ) sa = simpleaudio_open_system_audio(SA_STREAM_RECORD, + sample_rate, nchannels, program_name, "input audio"); if ( !sa ) return 1; - unsigned int sample_rate = simpleaudio_get_rate(sa); - unsigned int nchannels = simpleaudio_get_channels(sa); - - assert( nchannels == 1 ); - /* * Prepare the input sample chunk rate diff --git a/src/simple-tone-generator.c b/src/simple-tone-generator.c index 97d6496..9591ce6 100644 --- a/src/simple-tone-generator.c +++ b/src/simple-tone-generator.c @@ -43,7 +43,7 @@ simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur) if ( tone_freq != 0 ) { - float wave_nsamples = 48000.0 / tone_freq; // FIXME rate + float wave_nsamples = simpleaudio_get_rate(sa_out) / tone_freq; size_t i; for ( i=0; i