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)
67 float leftBuffer[FRAMES_PER_BUFFER];
68 float rightBuffer[FRAMES_PER_BUFFER];
71 float sine[TABLE_SIZE];
80 printf(
"PortAudio Test: output sine wave NON-INTERLEAVED. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
83 for( i=0; i<TABLE_SIZE; i++ )
85 sine[i] = (float) sin( ((
double)i/(
double)TABLE_SIZE) * M_PI * 2. );
90 if( err != paNoError )
goto error;
94 fprintf(stderr,
"Error: No default output device.\n");
111 if( err != paNoError )
goto error;
114 printf(
"Play 3 times, higher each time.\n" );
117 buffers[0] = leftBuffer;
118 buffers[1] = rightBuffer;
120 for( k=0; k < 3; ++k )
123 if( err != paNoError )
goto error;
125 printf(
"Play for %d seconds.\n", NUM_SECONDS );
127 bufferCount = ((NUM_SECONDS * SAMPLE_RATE) / FRAMES_PER_BUFFER);
129 for( i=0; i < bufferCount; i++ )
131 for( j=0; j < FRAMES_PER_BUFFER; j++ )
133 leftBuffer[j] = sine[left_phase];
134 rightBuffer[j] = sine[right_phase];
135 left_phase += left_inc;
136 if( left_phase >= TABLE_SIZE ) left_phase -= TABLE_SIZE;
137 right_phase += right_inc;
138 if( right_phase >= TABLE_SIZE ) right_phase -= TABLE_SIZE;
142 if( err != paNoError )
goto error;
146 if( err != paNoError )
goto error;
155 if( err != paNoError )
goto error;
158 printf(
"Test finished.\n");
163 fprintf( stderr,
"An error occured while using the portaudio stream\n" );
164 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_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
The portable PortAudio API.
PaSampleFormat sampleFormat
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
PaDeviceIndex Pa_GetDefaultOutputDevice(void)
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)