PortAudio: how to get a recording from a microphone (get data)

I try to use portaudio (cross platform capability), read from a microphone, then I want to put this data through FFT, but I'm not sure how to do it. Many people told me: 1.Download data, 2.apply fft, but the problem is that I'm not sure how to get the data, portaudio does not have a lot of tutorials on capturing microphone input, if you know any code, tutorials or any other resource, that would be great. I have been looking for this for a while. Please, help

+4
source share
1 answer

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

 /* 1 */ data.recordedSamples = (SAMPLE *) malloc( numBytes ); /* 2 */ err = Pa_OpenStream( &stream, &inputParameters, NULL, /* &outputParameters, */ SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff, recordCallback, &data ); /* 3, in recordCallBack with rptr the input data and wptr our buffer */ for( i=0; i<framesLeft; i++ ) { *wptr++ = *rptr++; /* left */ if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ } 

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.

+4
source

All Articles