diff --git a/src/minimodem.c b/src/minimodem.c index 43b4f1f..5acaf69 100644 --- a/src/minimodem.c +++ b/src/minimodem.c @@ -520,6 +520,7 @@ main( int argc, char*argv[] ) tx_interactive = 0; #if USE_SNDFILE sa_out = simpleaudio_open_stream_sndfile(SA_STREAM_PLAYBACK, + SA_SAMPLE_FORMAT_FLOAT, sample_rate, nchannels, filename); #endif @@ -529,6 +530,7 @@ main( int argc, char*argv[] ) if ( ! sa_out ) sa_out = simpleaudio_open_system_audio(SA_STREAM_PLAYBACK, + SA_SAMPLE_FORMAT_FLOAT, sample_rate, nchannels, program_name, "output audio"); if ( ! sa_out ) @@ -552,6 +554,7 @@ main( int argc, char*argv[] ) if ( filename ) { #if USE_SNDFILE sa = simpleaudio_open_stream_sndfile(SA_STREAM_RECORD, + SA_SAMPLE_FORMAT_FLOAT, sample_rate, nchannels, filename); #endif @@ -561,6 +564,7 @@ main( int argc, char*argv[] ) if ( ! sa ) sa = simpleaudio_open_system_audio(SA_STREAM_RECORD, + SA_SAMPLE_FORMAT_FLOAT, sample_rate, nchannels, program_name, "input audio"); if ( !sa ) diff --git a/src/simpleaudio-alsa.c b/src/simpleaudio-alsa.c index b6e68df..b2d1e25 100644 --- a/src/simpleaudio-alsa.c +++ b/src/simpleaudio-alsa.c @@ -105,6 +105,7 @@ static const struct simpleaudio_backend simpleaudio_backend_alsa = { simpleaudio * simpleaudio_open_stream_alsa( int sa_stream_direction, + sa_sample_format_t sa_sample_format, unsigned int rate, unsigned int channels, char *app_name, char *stream_name ) { @@ -120,6 +121,8 @@ simpleaudio_open_stream_alsa( return NULL; } + assert( sa_sample_format == SA_SAMPLE_FORMAT_FLOAT ); + /* set up ALSA hardware params */ error = snd_pcm_set_params(pcm, SND_PCM_FORMAT_FLOAT, @@ -160,6 +163,7 @@ simpleaudio_open_stream_alsa( snd_pcm_close(pcm); return NULL; } + sa->format = sa_sample_format; sa->rate = rate; sa->channels = channels; sa->samplesize = sizeof(float); diff --git a/src/simpleaudio-pulse.c b/src/simpleaudio-pulse.c index 932ea38..47741af 100644 --- a/src/simpleaudio-pulse.c +++ b/src/simpleaudio-pulse.c @@ -89,6 +89,7 @@ static const struct simpleaudio_backend simpleaudio_backend_pulse = { simpleaudio * simpleaudio_open_stream_pulseaudio( int sa_stream_direction, + sa_sample_format_t sa_sample_format, unsigned int rate, unsigned int channels, char *app_name, char *stream_name ) { @@ -97,6 +98,8 @@ simpleaudio_open_stream_pulseaudio( // FIXME - use source for something // just take the default pulseaudio source for now + assert( sa_sample_format == SA_SAMPLE_FORMAT_FLOAT ); + /* The sample type to use */ pa_sample_spec ss = { .format = PA_SAMPLE_FLOAT32, @@ -134,6 +137,7 @@ simpleaudio_open_stream_pulseaudio( pa_simple_free(s); return NULL; } + sa->format = sa_sample_format; sa->rate = ss.rate; sa->channels = ss.channels; sa->samplesize = sizeof(float); diff --git a/src/simpleaudio-sndfile.c b/src/simpleaudio-sndfile.c index 232d567..94abfb2 100644 --- a/src/simpleaudio-sndfile.c +++ b/src/simpleaudio-sndfile.c @@ -135,9 +135,12 @@ sndfile_format_from_path( const char *path ) simpleaudio * simpleaudio_open_stream_sndfile( int sa_stream_direction, + sa_sample_format_t sa_sample_format, unsigned int rate, unsigned int channels, char *path ) { + assert( sa_sample_format == SA_SAMPLE_FORMAT_FLOAT ); + /* setting for SA_STREAM_PLAYBACK (file write) */ SF_INFO sfinfo = { .format = 0, @@ -165,6 +168,7 @@ simpleaudio_open_stream_sndfile( sf_close(s); return NULL; } + sa->format = sa_sample_format; sa->rate = sfinfo.samplerate; sa->channels = sfinfo.channels; sa->samplesize = sizeof(float); diff --git a/src/simpleaudio.c b/src/simpleaudio.c index a12c4fc..4a86fa0 100644 --- a/src/simpleaudio.c +++ b/src/simpleaudio.c @@ -21,6 +21,12 @@ #include "simpleaudio_internal.h" #include "malloc.h" +sa_sample_format_t +simpleaudio_get_format( simpleaudio *sa ) +{ + return sa->format; +} + unsigned int simpleaudio_get_rate( simpleaudio *sa ) { diff --git a/src/simpleaudio.h b/src/simpleaudio.h index 4ac4ef8..f922ba9 100644 --- a/src/simpleaudio.h +++ b/src/simpleaudio.h @@ -31,26 +31,36 @@ typedef struct simpleaudio simpleaudio; * */ +/* sa_stream_direction */ enum { SA_STREAM_PLAYBACK, SA_STREAM_RECORD, }; +/* sa_stream_format */ +typedef enum { + SA_SAMPLE_FORMAT_S16, + SA_SAMPLE_FORMAT_FLOAT, +} sa_sample_format_t; + simpleaudio * simpleaudio_open_stream_pulseaudio( int sa_stream_direction, + sa_sample_format_t sa_sample_format, unsigned int rate, unsigned int channels, char *app_name, char *stream_name ); simpleaudio * simpleaudio_open_stream_alsa( int sa_stream_direction, + sa_sample_format_t sa_sample_format, unsigned int rate, unsigned int channels, char *app_name, char *stream_name ); simpleaudio * simpleaudio_open_stream_sndfile( int sa_stream_direction, + sa_sample_format_t sa_sample_format, unsigned int rate, unsigned int channels, char *path ); @@ -67,6 +77,9 @@ simpleaudio_get_channels( simpleaudio *sa ); unsigned int simpleaudio_get_framesize( simpleaudio *sa ); +sa_sample_format_t +simpleaudio_get_format( simpleaudio *sa ); + unsigned int simpleaudio_get_samplesize( simpleaudio *sa ); diff --git a/src/simpleaudio_internal.h b/src/simpleaudio_internal.h index fbdac00..688c908 100644 --- a/src/simpleaudio_internal.h +++ b/src/simpleaudio_internal.h @@ -33,6 +33,7 @@ typedef struct simpleaudio_backend simpleaudio_backend; struct simpleaudio { const struct simpleaudio_backend *backend; + sa_sample_format_t format; unsigned int rate; unsigned int channels; void * backend_handle;