The portaudio distribution has documentation in the form of examples of C programs. They are located in the test directory and are usually called patest_... There is a lot of good material there, and the documents contain an overview with a very brief description ,
The one you want to watch is patest_record , which performs asynchronous write through a callback. This is the way if you want to do something serious, IMHO. But there is also patest_read_record.c that does synchronous (blocking) IO.
The code is actually very simple, here are the relevant parts (a lot of things left): 1 / you malloc buffer 2 / you set the callback 3 / in the callback, you copy the data to the buffer
data.recordedSamples = (SAMPLE *) malloc( numBytes ); err = Pa_OpenStream( &stream, &inputParameters, NULL, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff, recordCallback, &data ); for( i=0; i<framesLeft; i++ ) { *wptr++ = *rptr++; if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; }
Again, this is simplified, but you get the idea. There is a fair amount of bookkeeping available, and the sample code is not the cleanest, but it easily adapts to your goals.
source share