49 #define NUM_SECONDS (5)
50 #define SAMPLE_RATE (44100)
51 #define FRAMES_PER_BUFFER (1024)
54 #define M_PI (3.14159265)
57 #define TABLE_SIZE (200)
66 float buffer[FRAMES_PER_BUFFER][2];
67 float sine[TABLE_SIZE];
75 printf(
"PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
78 for( i=0; i<TABLE_SIZE; i++ )
80 sine[i] = (float) sin( ((
double)i/(
double)TABLE_SIZE) * M_PI * 2. );
85 if( err != paNoError )
goto error;
89 fprintf(stderr,
"Error: No default output device.\n");
106 if( err != paNoError )
goto error;
109 printf(
"Play 3 times, higher each time.\n" );
111 for( k=0; k < 3; ++k )
114 if( err != paNoError )
goto error;
116 printf(
"Play for %d seconds.\n", NUM_SECONDS );
118 bufferCount = ((NUM_SECONDS * SAMPLE_RATE) / FRAMES_PER_BUFFER);
120 for( i=0; i < bufferCount; i++ )
122 for( j=0; j < FRAMES_PER_BUFFER; j++ )
124 buffer[j][0] = sine[left_phase];
125 buffer[j][1] = sine[right_phase];
126 left_phase += left_inc;
127 if( left_phase >= TABLE_SIZE ) left_phase -= TABLE_SIZE;
128 right_phase += right_inc;
129 if( right_phase >= TABLE_SIZE ) right_phase -= TABLE_SIZE;
133 if( err != paNoError )
goto error;
137 if( err != paNoError )
goto error;
146 if( err != paNoError )
goto error;
149 printf(
"Test finished.\n");
154 fprintf( stderr,
"An error occured while using the portaudio stream\n" );
155 fprintf( stderr,
"Error number: %d\n", err );
158 if( err == paUnanticipatedHostError )
161 fprintf( stderr,
"Host API error = #%ld, hostApiType = %d\n", hostErrorInfo->
errorCode, hostErrorInfo->
hostApiType );
162 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)