50 #define NUM_SECONDS (5)
51 #define SAMPLE_RATE (44100)
53 #define FRAMES_PER_BUFFER (1024)
56 #define M_PI (3.14159265)
59 #define TABLE_SIZE (200)
68 float buffer[FRAMES_PER_BUFFER][CHANNELS];
69 float sine[TABLE_SIZE];
77 assert(CHANNELS >= 1 && CHANNELS <= 2);
79 printf(
"PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
82 for( i=0; i<TABLE_SIZE; i++ )
84 sine[i] = (float) sin( ((
double)i/(
double)TABLE_SIZE) * M_PI * 2. );
89 if( err != paNoError )
goto error;
93 fprintf(stderr,
"Error: No default output device.\n");
110 if( err != paNoError )
goto error;
113 printf(
"Play 3 times, higher each time.\n" );
115 for( k=0; k < 3; ++k )
118 if( err != paNoError )
goto error;
120 printf(
"Play for %d seconds.\n", NUM_SECONDS );
122 bufferCount = ((NUM_SECONDS * SAMPLE_RATE) / FRAMES_PER_BUFFER);
124 for( i=0; i < bufferCount; i++ )
126 for( j=0; j < FRAMES_PER_BUFFER; j++ )
128 buffer[j][0] = sine[left_phase];
129 left_phase += left_inc;
130 if( left_phase >= TABLE_SIZE ) left_phase -= TABLE_SIZE;
134 buffer[j][1] = sine[right_phase];
135 right_phase += right_inc;
136 if( right_phase >= TABLE_SIZE ) right_phase -= TABLE_SIZE;
141 if( err != paNoError )
goto error;
145 if( err != paNoError )
goto error;
155 if( err != paNoError )
goto error;
158 printf(
"Test finished.\n");
163 fprintf( stderr,
"An error occurred while using the portaudio stream\n" );
164 fprintf( stderr,
"Error number: %d\n", err );
167 if( err == paUnanticipatedHostError )
170 fprintf( stderr,
"Host API error = #%ld, hostApiType = %d\n", hostErrorInfo->
errorCode, hostErrorInfo->
hostApiType );
171 fprintf( stderr,
"Host API error = %s\n", hostErrorInfo->
errorText );
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)
const PaHostErrorInfo * Pa_GetLastHostErrorInfo(void)
PaError Pa_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
The portable PortAudio API.
PaSampleFormat sampleFormat
PaDeviceIndex Pa_GetDefaultOutputDevice(void)
PaHostApiTypeId hostApiType
PaError Pa_WriteStream(PaStream *stream, const void *buffer, unsigned long frames)
const char * Pa_GetErrorText(PaError errorCode)
PaError Pa_CloseStream(PaStream *stream)
PaError Pa_Terminate(void)