Continuous recording in PortAudio (from mic or output)

Update:

What is the purpose of this code?

        if((err = Pa_GetStreamReadAvailable(stream)) != paNoError)
            break;

It seems to me like this is causing your (latest) problem. Why do you need to retrieve (and then discard) the number of frames that can be read from the stream without waiting, which would presumably be zero since stream is a callback stream?


Previous answer:

This seems highly suspicious:

static void* data;
/* ... */
static int recordCallback(const void* inputBuffer, void* outputBuffer, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void* userData){
    testData* data = (testData*)userData;
    /* ... */
}

Firstly, why are there two variables named data? That's just silly... Can you think of more appropriate identifiers?

Secondly, you're passing a &data (a void **) to Pa_OpenStream. Presumably, Pa_OpenStream passes that same value on to your callback function, where you treat that pointer to void * as though it points to a testData *. That's undefined behaviour.

Remove static void* data;. That's not necessary, here. Declare a new testData data = { 0 }; inside main, right at the very top. Now you're passing a testData * (converted to void *) to Pa_OpenStream, Pa_OpenStream will pass that on to your callback where you can safely convert it back to a testData * as you are. You might want to set the members of data before calling Pa_OpenStream...

Tags:

C

Audio

Portaudio