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;
|
tx_interactive = 0;
|
||||||
#if USE_SNDFILE
|
#if USE_SNDFILE
|
||||||
sa_out = simpleaudio_open_stream_sndfile(SA_STREAM_PLAYBACK,
|
sa_out = simpleaudio_open_stream_sndfile(SA_STREAM_PLAYBACK,
|
||||||
|
SA_SAMPLE_FORMAT_FLOAT,
|
||||||
sample_rate, nchannels,
|
sample_rate, nchannels,
|
||||||
filename);
|
filename);
|
||||||
#endif
|
#endif
|
||||||
@ -529,6 +530,7 @@ main( int argc, char*argv[] )
|
|||||||
|
|
||||||
if ( ! sa_out )
|
if ( ! sa_out )
|
||||||
sa_out = simpleaudio_open_system_audio(SA_STREAM_PLAYBACK,
|
sa_out = simpleaudio_open_system_audio(SA_STREAM_PLAYBACK,
|
||||||
|
SA_SAMPLE_FORMAT_FLOAT,
|
||||||
sample_rate, nchannels,
|
sample_rate, nchannels,
|
||||||
program_name, "output audio");
|
program_name, "output audio");
|
||||||
if ( ! sa_out )
|
if ( ! sa_out )
|
||||||
@ -552,6 +554,7 @@ main( int argc, char*argv[] )
|
|||||||
if ( filename ) {
|
if ( filename ) {
|
||||||
#if USE_SNDFILE
|
#if USE_SNDFILE
|
||||||
sa = simpleaudio_open_stream_sndfile(SA_STREAM_RECORD,
|
sa = simpleaudio_open_stream_sndfile(SA_STREAM_RECORD,
|
||||||
|
SA_SAMPLE_FORMAT_FLOAT,
|
||||||
sample_rate, nchannels,
|
sample_rate, nchannels,
|
||||||
filename);
|
filename);
|
||||||
#endif
|
#endif
|
||||||
@ -561,6 +564,7 @@ main( int argc, char*argv[] )
|
|||||||
|
|
||||||
if ( ! sa )
|
if ( ! sa )
|
||||||
sa = simpleaudio_open_system_audio(SA_STREAM_RECORD,
|
sa = simpleaudio_open_system_audio(SA_STREAM_RECORD,
|
||||||
|
SA_SAMPLE_FORMAT_FLOAT,
|
||||||
sample_rate, nchannels,
|
sample_rate, nchannels,
|
||||||
program_name, "input audio");
|
program_name, "input audio");
|
||||||
if ( !sa )
|
if ( !sa )
|
||||||
|
@ -105,6 +105,7 @@ static const struct simpleaudio_backend simpleaudio_backend_alsa = {
|
|||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_alsa(
|
simpleaudio_open_stream_alsa(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
sa_sample_format_t sa_sample_format,
|
||||||
unsigned int rate, unsigned int channels,
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name )
|
char *app_name, char *stream_name )
|
||||||
{
|
{
|
||||||
@ -120,6 +121,8 @@ simpleaudio_open_stream_alsa(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert( sa_sample_format == SA_SAMPLE_FORMAT_FLOAT );
|
||||||
|
|
||||||
/* set up ALSA hardware params */
|
/* set up ALSA hardware params */
|
||||||
error = snd_pcm_set_params(pcm,
|
error = snd_pcm_set_params(pcm,
|
||||||
SND_PCM_FORMAT_FLOAT,
|
SND_PCM_FORMAT_FLOAT,
|
||||||
@ -160,6 +163,7 @@ simpleaudio_open_stream_alsa(
|
|||||||
snd_pcm_close(pcm);
|
snd_pcm_close(pcm);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
sa->format = sa_sample_format;
|
||||||
sa->rate = rate;
|
sa->rate = rate;
|
||||||
sa->channels = channels;
|
sa->channels = channels;
|
||||||
sa->samplesize = sizeof(float);
|
sa->samplesize = sizeof(float);
|
||||||
|
@ -89,6 +89,7 @@ static const struct simpleaudio_backend simpleaudio_backend_pulse = {
|
|||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_pulseaudio(
|
simpleaudio_open_stream_pulseaudio(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
sa_sample_format_t sa_sample_format,
|
||||||
unsigned int rate, unsigned int channels,
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name )
|
char *app_name, char *stream_name )
|
||||||
{
|
{
|
||||||
@ -97,6 +98,8 @@ simpleaudio_open_stream_pulseaudio(
|
|||||||
// FIXME - use source for something
|
// FIXME - use source for something
|
||||||
// just take the default pulseaudio source for now
|
// just take the default pulseaudio source for now
|
||||||
|
|
||||||
|
assert( sa_sample_format == SA_SAMPLE_FORMAT_FLOAT );
|
||||||
|
|
||||||
/* The sample type to use */
|
/* The sample type to use */
|
||||||
pa_sample_spec ss = {
|
pa_sample_spec ss = {
|
||||||
.format = PA_SAMPLE_FLOAT32,
|
.format = PA_SAMPLE_FLOAT32,
|
||||||
@ -134,6 +137,7 @@ simpleaudio_open_stream_pulseaudio(
|
|||||||
pa_simple_free(s);
|
pa_simple_free(s);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
sa->format = sa_sample_format;
|
||||||
sa->rate = ss.rate;
|
sa->rate = ss.rate;
|
||||||
sa->channels = ss.channels;
|
sa->channels = ss.channels;
|
||||||
sa->samplesize = sizeof(float);
|
sa->samplesize = sizeof(float);
|
||||||
|
@ -135,9 +135,12 @@ sndfile_format_from_path( const char *path )
|
|||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_sndfile(
|
simpleaudio_open_stream_sndfile(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
sa_sample_format_t sa_sample_format,
|
||||||
unsigned int rate, unsigned int channels,
|
unsigned int rate, unsigned int channels,
|
||||||
char *path )
|
char *path )
|
||||||
{
|
{
|
||||||
|
assert( sa_sample_format == SA_SAMPLE_FORMAT_FLOAT );
|
||||||
|
|
||||||
/* setting for SA_STREAM_PLAYBACK (file write) */
|
/* setting for SA_STREAM_PLAYBACK (file write) */
|
||||||
SF_INFO sfinfo = {
|
SF_INFO sfinfo = {
|
||||||
.format = 0,
|
.format = 0,
|
||||||
@ -165,6 +168,7 @@ simpleaudio_open_stream_sndfile(
|
|||||||
sf_close(s);
|
sf_close(s);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
sa->format = sa_sample_format;
|
||||||
sa->rate = sfinfo.samplerate;
|
sa->rate = sfinfo.samplerate;
|
||||||
sa->channels = sfinfo.channels;
|
sa->channels = sfinfo.channels;
|
||||||
sa->samplesize = sizeof(float);
|
sa->samplesize = sizeof(float);
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
#include "simpleaudio_internal.h"
|
#include "simpleaudio_internal.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
|
||||||
|
sa_sample_format_t
|
||||||
|
simpleaudio_get_format( simpleaudio *sa )
|
||||||
|
{
|
||||||
|
return sa->format;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
simpleaudio_get_rate( simpleaudio *sa )
|
simpleaudio_get_rate( simpleaudio *sa )
|
||||||
{
|
{
|
||||||
|
@ -31,26 +31,36 @@ typedef struct simpleaudio simpleaudio;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* sa_stream_direction */
|
||||||
enum {
|
enum {
|
||||||
SA_STREAM_PLAYBACK,
|
SA_STREAM_PLAYBACK,
|
||||||
SA_STREAM_RECORD,
|
SA_STREAM_RECORD,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* sa_stream_format */
|
||||||
|
typedef enum {
|
||||||
|
SA_SAMPLE_FORMAT_S16,
|
||||||
|
SA_SAMPLE_FORMAT_FLOAT,
|
||||||
|
} sa_sample_format_t;
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_pulseaudio(
|
simpleaudio_open_stream_pulseaudio(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
sa_sample_format_t sa_sample_format,
|
||||||
unsigned int rate, unsigned int channels,
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name );
|
char *app_name, char *stream_name );
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_alsa(
|
simpleaudio_open_stream_alsa(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
sa_sample_format_t sa_sample_format,
|
||||||
unsigned int rate, unsigned int channels,
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name );
|
char *app_name, char *stream_name );
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_sndfile(
|
simpleaudio_open_stream_sndfile(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
sa_sample_format_t sa_sample_format,
|
||||||
unsigned int rate, unsigned int channels,
|
unsigned int rate, unsigned int channels,
|
||||||
char *path );
|
char *path );
|
||||||
|
|
||||||
@ -67,6 +77,9 @@ simpleaudio_get_channels( simpleaudio *sa );
|
|||||||
unsigned int
|
unsigned int
|
||||||
simpleaudio_get_framesize( simpleaudio *sa );
|
simpleaudio_get_framesize( simpleaudio *sa );
|
||||||
|
|
||||||
|
sa_sample_format_t
|
||||||
|
simpleaudio_get_format( simpleaudio *sa );
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
simpleaudio_get_samplesize( simpleaudio *sa );
|
simpleaudio_get_samplesize( simpleaudio *sa );
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ typedef struct simpleaudio_backend simpleaudio_backend;
|
|||||||
|
|
||||||
struct simpleaudio {
|
struct simpleaudio {
|
||||||
const struct simpleaudio_backend *backend;
|
const struct simpleaudio_backend *backend;
|
||||||
|
sa_sample_format_t format;
|
||||||
unsigned int rate;
|
unsigned int rate;
|
||||||
unsigned int channels;
|
unsigned int channels;
|
||||||
void * backend_handle;
|
void * backend_handle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user