2

I've written a program to open an audio stream using PortAudio, take a buffer of data, and FFT that data using the FFTW3 library. In the full program the FFT data is then processed and the program repeats itself until the user stops. The only way that I've been able to get PortAudio and FFTW working together was to convert the PortAudio data (signed 16 bit int, paInt16) to double as such:

    /* Create left and right array -- int to double */
    k = 0;
    for ( i=0; i<data.maxFrameIndex*2; i++ ) {
        myData.inL[k] = data.recordedSamples[i]; // myData is type double
        i++;
        myData.inR[k] = data.recordedSamples[i];
        k++;
    }

Since the process repeats continuously and speed is pretty imperative, I was wondering if anyone had ideas on a more efficient method of conversion, or, more preferably, not converting at all. Since the FFTW requires that you pre-allocate an input / output buffer and create a FFT plan, my original idea was to just give PortAudio the address of the input buffer, but PortAudio does not have a double input type.

I'm also looking for a more efficient way of recording the audio. The current process is calling PaStartStream( stream ), waiting for a buffer to fill, calling PaStopStream( stream ), process and repeat. It would seem more efficient to leave the stream open and just call the callback function as necessary. You tell me!

Thank you for your help, please let me know if more information would be beneficial.

jonwooding
  • 39
  • 6

1 Answers1

1

Converting short ints to doubles will be pretty quick. Have you profiled this? Do you know if it's a bottleneck?

Pa_ReadStream may be more what you want, rather than using the callback. Then you can just fill the buffer and process it in place.

Brian Armstrong
  • 326
  • 2
  • 14