48 #define NUM_SECONDS (5)
49 #define SAMPLE_RATE (44100)
50 #define FRAMES_PER_BUFFER (64)
53 #define M_PI (3.14159265)
56 #define TABLE_SIZE (200)
59 float sine[TABLE_SIZE];
70 static int patestCallback(
const void *inputBuffer,
void *outputBuffer,
71 unsigned long framesPerBuffer,
77 float *out = (
float*)outputBuffer;
84 for( i=0; i<framesPerBuffer; i++ )
86 *out++ = data->sine[data->left_phase];
87 *out++ = data->sine[data->right_phase];
88 data->left_phase += 1;
89 if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
90 data->right_phase += 3;
91 if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
100 static void StreamFinished(
void* userData )
103 printf(
"Stream Completed: %s\n", data->message );
116 printf(
"PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
119 for( i=0; i<TABLE_SIZE; i++ )
121 data.sine[i] = (float) sin( ((
double)i/(
double)TABLE_SIZE) * M_PI * 2. );
123 data.left_phase = data.right_phase = 0;
126 if( err != paNoError )
goto error;
130 fprintf(stderr,
"Error: No default output device.\n");
147 if( err != paNoError )
goto error;
149 sprintf( data.message,
"No Message" );
151 if( err != paNoError )
goto error;
154 if( err != paNoError )
goto error;
156 printf(
"Play for %d seconds.\n", NUM_SECONDS );
160 if( err != paNoError )
goto error;
163 if( err != paNoError )
goto error;
166 printf(
"Test finished.\n");
171 fprintf( stderr,
"An error occured while using the portaudio stream\n" );
172 fprintf( stderr,
"Error number: %d\n", err );
PaError Pa_Initialize(void)
PaError Pa_StopStream(PaStream *stream)
PaError Pa_OpenStream(PaStream **stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData)
PaError Pa_SetStreamFinishedCallback(PaStream *stream, PaStreamFinishedCallback *streamFinishedCallback)
PaError Pa_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
The portable PortAudio API.
PaSampleFormat sampleFormat
unsigned long PaStreamCallbackFlags
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
PaDeviceIndex Pa_GetDefaultOutputDevice(void)
const char * Pa_GetErrorText(PaError errorCode)
PaError Pa_CloseStream(PaStream *stream)
PaError Pa_Terminate(void)