53 #define NUM_SECONDS (12)
54 #define SAMPLE_RATE (44100)
55 #define FRAMES_PER_BUFFER (64)
58 #define M_PI (3.14159265)
61 #define TABLE_SIZE (100)
63 #define CHANNEL_COUNT (6)
69 float sine[TABLE_SIZE];
80 static int patestCallback(
const void *inputBuffer,
void *outputBuffer,
81 unsigned long framesPerBuffer,
87 float *out = (
float*)outputBuffer;
94 for( i=0; i<framesPerBuffer; i++ )
96 for( j = 0; j < CHANNEL_COUNT; ++j ){
97 if( j == data->currentChannel && data->cycleCount < 4410 ){
98 *out++ = data->sine[data->phase];
100 if( data->phase >= TABLE_SIZE ){
101 data->phase -= TABLE_SIZE;
109 if( data->cycleCount > 44100 ){
110 data->cycleCount = 0;
112 ++data->currentChannel;
113 if( data->currentChannel >= CHANNEL_COUNT )
114 data->currentChannel -= CHANNEL_COUNT;
122 int main(
int argc,
char* argv[])
132 printf(
"PortAudio Test: output a sine blip on each channel. SR = %d, BufSize = %d, Chans = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER, CHANNEL_COUNT);
135 if( err != paNoError )
goto error;
139 sscanf( argv[1],
"%d", &deviceIndex );
142 printf(
"using device id %d (%s)\n", deviceIndex,
Pa_GetDeviceInfo(deviceIndex)->name );
145 for( i=0; i<TABLE_SIZE; i++ )
147 data.sine[i] = (float) sin( ((
double)i/(
double)TABLE_SIZE) * M_PI * 2. );
151 data.currentChannel = 0;
154 outputParameters.
device = deviceIndex;
166 wmmeStreamInfo.flags = paWinMmeUseChannelMask;
167 wmmeStreamInfo.channelMask = PAWIN_SPEAKER_5POINT1;
172 printf(
"Pa_IsFormatSupported reports device will support %d channels.\n", CHANNEL_COUNT );
174 printf(
"Pa_IsFormatSupported reports device will not support %d channels.\n", CHANNEL_COUNT );
186 if( err != paNoError )
goto error;
189 if( err != paNoError )
goto error;
191 printf(
"Play for %d seconds.\n", NUM_SECONDS );
195 if( err != paNoError )
goto error;
198 if( err != paNoError )
goto error;
201 printf(
"Test finished.\n");
206 fprintf( stderr,
"An error occured while using the portaudio stream\n" );
207 fprintf( stderr,
"Error number: %d\n", err );
PaError Pa_Initialize(void)
PaHostApiTypeId hostApiType
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_IsFormatSupported(const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate)
PaError Pa_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
The portable PortAudio API.
WMME-specific PortAudio API extension header file.
PaSampleFormat sampleFormat
unsigned long PaStreamCallbackFlags
PaDeviceIndex defaultOutputDevice
const PaHostApiInfo * Pa_GetHostApiInfo(PaHostApiIndex hostApi)
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
#define paFormatIsSupported
const char * Pa_GetErrorText(PaError errorCode)
PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex(PaHostApiTypeId type)
PaError Pa_CloseStream(PaStream *stream)
PaError Pa_Terminate(void)