int main(int argc, char* argv[]) { PaStream *stream; PaError err; patest1data data; int i; int inputDevice = Pa_GetDefaultInputDeviceID(); int outputDevice = Pa_GetDefaultOutputDeviceID(); /* initialise sinusoidal wavetable */ for( i=0; i<100; i++ ) data.sine[i] = sin( ((double)i/100.) * M_PI * 2. ); data.phase = 0; data.sampsToGo = 44100 * 4; // 20 seconds /* initialise portaudio subsytem */ Pa_Initialize(); err = Pa_OpenStream( &stream, inputDevice, 2, /* stereo input */ paFloat32, /* 32 bit floating point input */ NULL, outputDevice, 2, /* stereo output */ paFloat32, /* 32 bit floating point output */ NULL, 44100., // 22050, /* half second buffers */ // 4, /* four buffers */ 512, /* half second buffers */ 0, /* four buffers */ paClipOff, /* we won't output out of range samples so don't bother clipping them */ patest1Callback, &data ); if( err == paNoError ) { err = Pa_StartStream( stream ); // printf( "Press any key to end.\n" ); // getc( stdin ); //wait for input before exiting // Pa_AbortStream( stream ); printf( "Waiting for stream to complete...\n" ); while( Pa_StreamActive( stream ) ) Pa_Sleep(1000); /* sleep until playback has finished */ err = Pa_CloseStream( stream ); } else { fprintf( stderr, "An error occured while opening the portaudio stream\n" ); if( err == paHostError ) fprintf( stderr, "Host error number: %d\n", Pa_GetHostError() ); else fprintf( stderr, "Error number: %d\n", err ); } Pa_Terminate(); printf( "bye\n" ); return 0; }
int main(void) { PaError err; paTestData data; long totalFrames; long numBytes; long i; printf("patest_record.c\n"); fflush(stdout); data.frameIndex = 0; data.samplesPerFrame = 2; data.maxFrameIndex = totalFrames = NUM_SECONDS*SAMPLE_RATE; printf("totalFrames = %d\n", totalFrames ); fflush(stdout); data.numSamples = totalFrames * data.samplesPerFrame; numBytes = data.numSamples * sizeof(SAMPLE); data.recordedSamples = (SAMPLE *) malloc( numBytes ); if( data.recordedSamples == NULL ) { printf("Could not allocate record array.\n"); exit(1); } for( i=0; i<data.numSamples; i++ ) data.recordedSamples[i] = 0; err = Pa_Initialize(); if( err != paNoError ) goto error; for( i=0; i<2; i++ ) { err = TestRecording( &data ); if( err != paNoError ) goto error; err = TestPlayback( &data ); if( err != paNoError ) goto error; } free( data.recordedSamples ); Pa_Terminate(); return 0; error: Pa_Terminate(); fprintf( stderr, "An error occured while using the portaudio stream\n" ); fprintf( stderr, "Error number: %d\n", err ); fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); if( err == paHostError ) { fprintf( stderr, "Host Error number: %d\n", Pa_GetHostError() ); } return -1; }
int main(void) { PaError err; paTestData data = { 0 }; long i; double rate; const PaDeviceInfo *pdi; PortAudioStream *outputStream; PortAudioStream *inputStream; err = Pa_Initialize(); if( err != paNoError ) goto error; pdi = Pa_GetDeviceInfo( INPUT_DEVICE_ID ); printf("Input device = %s\n", pdi->name ); pdi = Pa_GetDeviceInfo( OUTPUT_DEVICE_ID ); printf("Output device = %s\n", pdi->name ); /* Open input stream. */ err = Pa_OpenStream( &inputStream, INPUT_DEVICE_ID, SAMPLES_PER_FRAME, /* stereo input */ PA_SAMPLE_TYPE, NULL, paNoDevice, 0, PA_SAMPLE_TYPE, NULL, INPUT_SAMPLE_RATE, FRAMES_PER_BUFFER, /* frames per buffer */ NUM_REC_BUFS, /* number of buffers, if zero then use default minimum */ paClipOff, /* we won't output out of range samples so don't bother clipping them */ recordCallback, &data ); if( err != paNoError ) goto error; err = Pa_OpenStream( &outputStream, paNoDevice, 0, /* NO input */ PA_SAMPLE_TYPE, NULL, OUTPUT_DEVICE_ID, SAMPLES_PER_FRAME, /* stereo output */ PA_SAMPLE_TYPE, NULL, OUTPUT_SAMPLE_RATE, FRAMES_PER_BUFFER, /* frames per buffer */ 0, /* number of buffers, if zero then use default minimum */ paClipOff, /* we won't output out of range samples so don't bother clipping them */ playCallback, &data ); if( err != paNoError ) goto error; /* Record and playback multiple times. */ for( i=0; i<2; i++ ) { printf("Measuring INPUT ------------------------- \n"); err = MeasureStreamRate( inputStream, &data, &rate ); if( err != paNoError ) goto error; ReportRate( rate, INPUT_SAMPLE_RATE ); printf("Measuring OUTPUT ------------------------- \n"); err = MeasureStreamRate( outputStream, &data, &rate ); if( err != paNoError ) goto error; ReportRate( rate, OUTPUT_SAMPLE_RATE ); } /* Clean up. */ err = Pa_CloseStream( inputStream ); if( err != paNoError ) goto error; err = Pa_CloseStream( outputStream ); if( err != paNoError ) goto error; if( err != paNoError ) goto error; Pa_Terminate(); printf("Test complete.\n"); fflush(stdout); return 0; error: Pa_Terminate(); fprintf( stderr, "An error occured while using the portaudio stream\n" ); fprintf( stderr, "Error number: %d\n", err ); fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); if( err == paHostError ) { fprintf( stderr, "Host Error number: %d\n", Pa_GetHostError() ); } return -1; }