filters/portaudio/pasink.c
/**
 * set up port audio with the right number of channels, the sample rate, and frame size
 * configure callbacks for output & end of output
 */
set up port audio with the right number of channels, the sample rate, and frame size
configure callbacks for output & end of output
set up port audio with the right number of channels the sample rate and frame size configure callbacks for output & end of output
int init_portaudio_output(int channels, int sample_rate, int frame_size, pa_output_data *data) {
	PaStreamParameters outputParameters;
	PaError err;
	int i;
	if ((data->buffers = (float**)malloc(BUFFERS * sizeof(float *))) < 0) {
		fprintf(stderr,"Error: Not enough memory");
		return errno;
	}
	for (i = 0; i < BUFFERS; i++) {
		if ((data->buffers[i] = (float*)malloc(frame_size * channels * sizeof(float))) < 0) {
			fprintf(stderr,"Error: Not enough memory");
			return errno;
		}
		data->dirty[i] = 0;
		PROTECT(pthread_mutex_init(&data->reading[i], NULL));
		PROTECT(pthread_mutex_init(&data->writing[i], NULL));
	}
	data->started = 0;
	data->stopped = 0;
	data->buffer_index = 0;
	data->fill_index = 0;
	data->buffer_size = channels * frame_size;
	err = Pa_Initialize();
    if( err != paNoError ) goto error;
	outputParameters.device = Pa_GetDefaultOutputDevice(); 
    if (outputParameters.device == paNoDevice) {
      fprintf(stderr,"Error: No default output device.\n");
      goto error;
    }
	outputParameters.channelCount = channels;
    outputParameters.sampleFormat = paFloat32; 		
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
    outputParameters.hostApiSpecificStreamInfo = NULL;
	err = Pa_OpenStream(
              &(data->stream),
              NULL, 
              &outputParameters,
              sample_rate,
              frame_size,
              paNoFlag,      
              pa_output_callback,
              data );
    if( err != paNoError ) goto error;
	return 0;
error:
    Pa_Terminate();
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
    fprintf( stderr, "Error number: %d\n", err );
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
    return err;
}
int init_portaudio_output ( int channels , int sample_rate , int frame_size , pa_output_data * data ) { PaStreamParameters outputParameters ; PaError err ; int i ; if ( ( data -> buffers = ( float * * ) malloc ( BUFFERS * sizeof ( float * ) ) ) < 0 ) { fprintf ( stderr , " " ) ; return errno ; } for ( i = 0 ; i < BUFFERS ; i ++ ) { if ( ( data -> buffers [ i ] = ( float * ) malloc ( frame_size * channels * sizeof ( float ) ) ) < 0 ) { fprintf ( stderr , " " ) ; return errno ; } data -> dirty [ i ] = 0 ; PROTECT ( pthread_mutex_init ( & data -> reading [ i ] , NULL ) ) ; PROTECT ( pthread_mutex_init ( & data -> writing [ i ] , NULL ) ) ; } data -> started = 0 ; data -> stopped = 0 ; data -> buffer_index = 0 ; data -> fill_index = 0 ; data -> buffer_size = channels * frame_size ; err = Pa_Initialize ( ) ; if ( err != paNoError ) goto error ; outputParameters . device = Pa_GetDefaultOutputDevice ( ) ; if ( outputParameters . device == paNoDevice ) { fprintf ( stderr , " \n " ) ; goto error ; } outputParameters . channelCount = channels ; outputParameters . sampleFormat = paFloat32 ; outputParameters . suggestedLatency = Pa_GetDeviceInfo ( outputParameters . device ) -> defaultLowOutputLatency ; outputParameters . hostApiSpecificStreamInfo = NULL ; err = Pa_OpenStream ( & ( data -> stream ) , NULL , & outputParameters , sample_rate , frame_size , paNoFlag , pa_output_callback , data ) ; if ( err != paNoError ) goto error ; return 0 ; error : Pa_Terminate ( ) ; fprintf ( stderr , " \n " ) ; fprintf ( stderr , " \n " , err ) ; fprintf ( stderr , " \n " , Pa_GetErrorText ( err ) ) ; return err ; }
set up port audio with the right number of channels, the sample rate, and frame size
 configure callbacks for output & end of output
set up port audio with the right number of channels the sample rate and frame size configure callbacks for output & end of output
/* default output device */ /* 32 bit floating point output */ /* no input */ /* clip samples! */