Skip to content

Commit

Permalink
cleanup: remove PortAudio support
Browse files Browse the repository at this point in the history
This was discussed in some of the earlier commits. PortAudio doesn't give any real advantages over libao and libao is at least as portable as PortAudio. And we should try to keep the code clean.
  • Loading branch information
albertz committed Apr 18, 2011
1 parent efc2c15 commit e73d325
Showing 1 changed file with 1 addition and 73 deletions.
74 changes: 1 addition & 73 deletions hairtunes.c
Expand Up @@ -37,15 +37,7 @@
#include <math.h>
#include <sys/stat.h>
#include <fcntl.h>

#if !defined(HAVE_AO)
#define HAVE_AO 1
#endif
#if HAVE_AO
#include <ao/ao.h>
#else
#include <portaudio.h>
#endif

#ifdef FANCY_RESAMPLING
#include <samplerate.h>
Expand Down Expand Up @@ -664,11 +656,7 @@ int stuff_buffer(double playback_rate, short *inptr, short *outptr) {
}

void *audio_thread_func(void *arg) {
#if HAVE_AO
ao_device* dev = arg;
#else
PaStream* stream = arg;
#endif
ao_device* dev = arg;
// file handle for named pipe
int fd = -1;

Expand Down Expand Up @@ -730,15 +718,7 @@ void *audio_thread_func(void *arg) {
exit(1);
}
} else {
#if HAVE_AO
ao_play(dev, (char *)outbuf, play_samples*4);
#else
int err = Pa_WriteStream(stream, (char *)outbuf, play_samples*4);
if( err != paNoError ) {
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
exit(1);
}
#endif
}
}

Expand All @@ -752,7 +732,6 @@ void* init_pipe(char* pipe) {
return NULL;
}

#if HAVE_AO
void* init_ao() {
ao_initialize();
int driver = ao_default_driver_id();
Expand All @@ -768,59 +747,14 @@ void* init_ao() {
ao_device *dev = ao_open_live(driver, &fmt, 0);
return dev;
}
#else
void* init_portaudio() {
int err __attribute__((unused));
err = Pa_Initialize();
if( err != paNoError ) {
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
exit(1);
}

PaStreamParameters outputParameters;
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
outputParameters.channelCount = NUM_CHANNELS;
outputParameters.sampleFormat = paInt16;
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultHighOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;

/* -- setup stream -- */
PaStream* stream = NULL;
err = Pa_OpenStream(
&stream,
NULL,
&outputParameters,
sampling_rate,
OUTFRAME_BYTES,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
NULL, /* no callback, use blocking API */
NULL ); /* no callback, so no callback userData */
if( err != paNoError ) {
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
exit(1);
}

err = Pa_StartStream( stream );
if( err != paNoError ) {
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
exit(1);
}

return stream;
}
#endif

int init_output(void) {
void* arg = 0;

if (pipename) {
arg = init_pipe(pipename);
} else {
#if HAVE_AO
arg = init_ao();
#else
arg = init_portaudio();
#endif
}

#ifdef FANCY_RESAMPLING
Expand All @@ -837,12 +771,6 @@ int init_output(void) {
}

int uninit_output(void) {
#if HAVE_AO
#else
int err = Pa_Terminate();
if( err != paNoError )
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
#endif
return 0;
}

0 comments on commit e73d325

Please sign in to comment.