simpleaudio: sa_stream_direction
This commit is contained in:
parent
775ef649e1
commit
31eb95afe8
|
@ -127,7 +127,8 @@ main( int argc, char*argv[] )
|
|||
return 1;
|
||||
}
|
||||
if ( ! sa ) {
|
||||
sa = simpleaudio_open_source_pulseaudio(argv[0], "input audio");
|
||||
sa = simpleaudio_open_stream_pulseaudio(SA_STREAM_RECORD,
|
||||
argv[0], "input audio");
|
||||
}
|
||||
if ( !sa )
|
||||
return 1;
|
||||
|
|
|
@ -41,6 +41,22 @@ sa_pulse_read( simpleaudio *sa, float *buf, size_t nframes )
|
|||
}
|
||||
|
||||
|
||||
static ssize_t
|
||||
sa_pulse_write( simpleaudio *sa, float *buf, size_t nframes )
|
||||
{
|
||||
int error;
|
||||
pa_simple *s = (pa_simple *)sa->backend_handle;
|
||||
size_t nbytes = nframes * sa->backend_framesize;
|
||||
/* ????? N.B. pa_simple_write always returns 0 or -1, not the number of
|
||||
* written bytes!*/
|
||||
if (pa_simple_write(s, buf, nbytes, &error) < 0) {
|
||||
fprintf(stderr, "pa_simple_write: %s\n", pa_strerror(error));
|
||||
return -1;
|
||||
}
|
||||
return nframes;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
sa_pulse_close( simpleaudio *sa )
|
||||
{
|
||||
|
@ -50,12 +66,14 @@ sa_pulse_close( simpleaudio *sa )
|
|||
|
||||
static const struct simpleaudio_backend simpleaudio_backend_pulse = {
|
||||
sa_pulse_read,
|
||||
sa_pulse_write,
|
||||
sa_pulse_close,
|
||||
};
|
||||
|
||||
simpleaudio *
|
||||
simpleaudio_open_source_pulseaudio(
|
||||
simpleaudio_open_stream_pulseaudio(
|
||||
// unsigned int rate, unsigned int channels,
|
||||
int sa_stream_direction,
|
||||
char *app_name, char *stream_name )
|
||||
{
|
||||
int error;
|
||||
|
@ -74,7 +92,9 @@ simpleaudio_open_source_pulseaudio(
|
|||
|
||||
/* Create the recording stream */
|
||||
pa_simple *s;
|
||||
s = pa_simple_new(NULL, app_name, PA_STREAM_RECORD, NULL, stream_name,
|
||||
s = pa_simple_new(NULL, app_name,
|
||||
sa_stream_direction == SA_STREAM_RECORD ? PA_STREAM_RECORD : PA_STREAM_PLAYBACK,
|
||||
NULL, stream_name,
|
||||
&ss, NULL, NULL, &error);
|
||||
if ( !s ) {
|
||||
fprintf(stderr, "pa_simple_new: %s\n", pa_strerror(error));
|
||||
|
|
|
@ -47,6 +47,7 @@ sa_sndfile_close( simpleaudio *sa )
|
|||
|
||||
static const struct simpleaudio_backend simpleaudio_backend_pulse = {
|
||||
sa_sndfile_read,
|
||||
NULL, // FIXME -- implement this
|
||||
sa_sndfile_close,
|
||||
};
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@ simpleaudio_read( simpleaudio *sa, float *buf, size_t nframes )
|
|||
return sa->backend->simpleaudio_read(sa, buf, nframes);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
simpleaudio_write( simpleaudio *sa, float *buf, size_t nframes )
|
||||
{
|
||||
return sa->backend->simpleaudio_write(sa, buf, nframes);
|
||||
}
|
||||
|
||||
void
|
||||
simpleaudio_close( simpleaudio *sa )
|
||||
{
|
||||
|
|
|
@ -21,9 +21,15 @@ typedef struct simpleaudio simpleaudio;
|
|||
*
|
||||
*/
|
||||
|
||||
enum {
|
||||
SA_STREAM_PLAYBACK,
|
||||
SA_STREAM_RECORD,
|
||||
};
|
||||
|
||||
simpleaudio *
|
||||
simpleaudio_open_source_pulseaudio(
|
||||
simpleaudio_open_stream_pulseaudio(
|
||||
// unsigned int rate, unsigned int channels,
|
||||
int sa_stream_direction,
|
||||
char *app_name, char *stream_name );
|
||||
|
||||
simpleaudio *
|
||||
|
@ -42,6 +48,9 @@ simpleaudio_get_channels( simpleaudio *sa );
|
|||
ssize_t
|
||||
simpleaudio_read( simpleaudio *sa, float *buf, size_t nframes );
|
||||
|
||||
ssize_t
|
||||
simpleaudio_write( simpleaudio *sa, float *buf, size_t nframes );
|
||||
|
||||
void
|
||||
simpleaudio_close( simpleaudio *sa );
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ struct simpleaudio {
|
|||
struct simpleaudio_backend {
|
||||
ssize_t
|
||||
(*simpleaudio_read)( simpleaudio *sa, float *buf, size_t nframes );
|
||||
ssize_t
|
||||
(*simpleaudio_write)( simpleaudio *sa, float *buf, size_t nframes );
|
||||
void
|
||||
(*simpleaudio_close)( simpleaudio *sa );
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue