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)
61 Sine() : stream(0), left_phase(0), right_phase(0)
64 for(
int i=0; i<TABLE_SIZE; i++ )
66 sine[i] = (float) sin( ((
double)i/(
double)TABLE_SIZE) * M_PI * 2. );
69 sprintf( message,
"No Message" );
76 outputParameters.
device = index;
84 printf(
"Output device name: '%s'\r", pInfo->
name);
103 if (err != paNoError)
111 if (err != paNoError)
130 return (err == paNoError);
141 return (err == paNoError);
151 return (err == paNoError);
156 int paCallbackMethod(
const void *inputBuffer,
void *outputBuffer,
157 unsigned long framesPerBuffer,
161 float *out = (
float*)outputBuffer;
168 for( i=0; i<framesPerBuffer; i++ )
170 *out++ = sine[left_phase];
171 *out++ = sine[right_phase];
173 if( left_phase >= TABLE_SIZE ) left_phase -= TABLE_SIZE;
175 if( right_phase >= TABLE_SIZE ) right_phase -= TABLE_SIZE;
186 static int paCallback(
const void *inputBuffer,
void *outputBuffer,
187 unsigned long framesPerBuffer,
194 return ((
Sine*)userData)->paCallbackMethod(inputBuffer, outputBuffer,
201 void paStreamFinishedMethod()
203 printf(
"Stream Completed: %s\n", message );
209 static void paStreamFinished(
void* userData)
211 return ((
Sine*)userData)->paStreamFinishedMethod();
215 float sine[TABLE_SIZE];
230 if (_result == paNoError)
236 PaError result()
const {
return _result; }
249 printf(
"PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
252 if( paInit.result() != paNoError )
goto error;
258 printf(
"Play for %d seconds.\n", NUM_SECONDS );
267 printf(
"Test finished.\n");
271 fprintf( stderr,
"An error occurred while using the portaudio stream\n" );
272 fprintf( stderr,
"Error number: %d\n", paInit.result() );
273 fprintf( stderr,
"Error message: %s\n",
Pa_GetErrorText( paInit.result() ) );
#define paFramesPerBufferUnspecified
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)