简体   繁体   English

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

[英]Catch Audio Output written to Output Audio Device from Port Audio

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. 我有一个端口音频回调,该回调接受输入声音缓冲区并对该缓冲区执行fft以便在应用程序的其他部分中使用。 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));
}

Port Audio does not support this functionality. Port Audio不支持此功能。 The solution is to use an existing OS audio loopback device and set this device as the default output device from the OS. 解决方案是使用现有的OS音频回送设备,并将该设备设置为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. 然后可以将回送设备用作端口音频中的输入流源,并且可以将最终的声音从端口音频回调中路由到所需的输出设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM