0
votes

I have a port audio callback which takes an input sound buffer and performs an fft on the buffer for use in other portions of the application. The output buffer is not modified. I would like to catch the sound written to the default output audio device by other applications. However, when initializing a stream with the output device as input, port audio throws an error 'invalid number of channels'. Is it possible to catch all audio written to an output device using port audio? The stream initialization code is below:

PaStreamParameters inputParams;
inputParams.device = Pa_GetDefaultOutputDevice();
inputParams.channelCount = 2;
inputParams.sampleFormat = paFloat32;
const PaDeviceInfo * inputInfo = Pa_GetDeviceInfo(inputParams.device);
inputParams.suggestedLatency = inputInfo->defaultLowOutputLatency;
inputParams.hostApiSpecificStreamInfo = NULL;

error = Pa_OpenStream( &_pInputStream,
                      &inputParams,
                      NULL,
                             inputInfo->defaultSampleRate,
                             paFramesPerBufferUnspecified,
                             0,
                             coreAudioCallback,
                             this);
if( error != paNoError ){
    printf("Port audio error = %s", Pa_GetErrorText(error));
}
1

1 Answers

0
votes

Port Audio does not support this functionality. The solution is to use an existing OS audio loopback device and set this device as the default output device from the OS. The loopback device can then be used as an input stream source in Port Audio, and the final sound can be routed to the desired output device from the port audio callback.