从端口音频捕获写入输出音频设备的音频输出

Catch Audio Output written to Output Audio Device from Port Audio

我有一个端口音频回调,它采用输入声音缓冲区并对缓冲区执行 fft 以供应用程序的其他部分使用。输出缓冲区未修改。我想捕捉其他应用程序写入默认输出音频设备的声音。但是,在使用输出设备作为输入初始化流时,端口音频会引发错误 'invalid number of channels'。是否可以使用端口音频捕获写入输出设备的所有音频?流初始化代码如下:

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));
}

端口音频不支持此功能。解决方案是使用现有的 OS 音频环回设备并将此设备设置为 OS 的默认输出设备。环回设备然后可以用作端口音频中的输入流源,最终声音可以从端口音频回调路由到所需的输出设备。