simpleaudio: SA_SAMPLE_FORMAT framework
This commit is contained in:
parent
39bee9adf1
commit
3053ea78bc
|
@ -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 )
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue