2
votes

I am new to PortAudio. My intention is to continuously capture data from the line-in input on my pc and process the data in real time.

I am using the sample rate of 44100 and buffer size (frameCount) of 11025. I am successfully able to do this, but I am doing all of my processing inside the callback function which the portAudio engine calls. The common prototype for this callback function:

int recordCallback(const void* inputBuffer, void* outputBuffer, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void* userData);

Is it bad to do all of my processing of the audio data inside this callback?

I am also loosing data because of the time taken to execute my callback function.

I thought about implementing a global circular buffer of a suitable size so that the callback fills this buffer continuously and sets a flag when it is ready. My main function can poll this flag and then do the processing in the main function instead.

My concern however is, is it possible for the callback to be writing to this ring buffer while my main function would be also reading from it at a different part.

Does anyone have a better solution for what i'm trying to achieve? Many thanks in advance

1
Hi @Engineer999 , were you able to get a solution to this? Acually I am facing the same issue and I am unable to find a good solution for this.Ashish K

1 Answers

0
votes

Is it bad to do all of my processing of the audio data inside this callback?

I am also loosing data because of the time taken to execute my callback function.

I think you answered your own question just there. Try pushing it to a buffer, and then have another thread do your post processing (beware - if you don't process it fast enough you'll have to dump it to disk else you'll end up running out of memory)

You said you were concerned about concurrency - which is reasonable, but give it a try and then post another question about that specific issue when you've given it a try.