0

In a nutshell: Is there a way to capture/manipulate all audio produced by an app using RemoteIO?

I can get render callbacks which allow me to send audio to the speaker by hooking into RemoteIO's output bus for the input scope. But my input buffer in that callback does not contain the sound being produced elsewhere in the app by an AVPlayer. Is manipulating all app audio even possible?

Here is my setup:

-(void)setup
{
    OSStatus status = noErr;

    AudioComponentDescription remoteIODesc;
    fillRemoteIODesc(&remoteIODesc);
    AudioComponent inputComponent = AudioComponentFindNext(NULL, &remoteIODesc);

    AudioComponentInstance remoteIO;
    status = AudioComponentInstanceNew(inputComponent, &remoteIO);
    assert(status == noErr);

    AudioStreamBasicDescription desc = {0};
    fillShortMonoASBD(&desc);

    status = AudioUnitSetProperty(remoteIO,
                                  kAudioUnitProperty_StreamFormat,
                                  kAudioUnitScope_Input,
                                  0,
                                  &desc,
                                  sizeof(desc));
    assert(status == noErr);

    AURenderCallbackStruct callback;
    callback.inputProc = outputCallback;
    callback.inputProcRefCon = _state;

    status = AudioUnitSetProperty(remoteIO,
                                  kAudioUnitProperty_SetRenderCallback,
                                  kAudioUnitScope_Input,
                                  0,
                                  &callback,
                                  sizeof(callback));
    assert(status == noErr);

    status = AudioUnitInitialize(remoteIO);
    assert(status == noErr);

    status = AudioOutputUnitStart(remoteIO);
    assert(status == noErr);
}
4

1 回答 1

2

简短的回答:不,不幸的是,它不是那样工作的。您将无法对通过 AVFoundation 生成的音频添加任意处理(从 iOS 6 开始)。

您误解了 RemoteIO 单元的用途。RemoteIO 让您可以访问两件事:音频输入硬件和音频输出硬件。如中,您可以使用 RemoteIO 从麦克风获取音频,或将音频发送到扬声器。RemoteIO 单元不会让您抓取应用程序的其他部分(例如 AVFoundation)发送到硬件的音频。无需过多讨论,这是因为 AVFoundation 不使用与 RemoteIO 一起使用的相同音频路径。

要在您想要的级别上操作音频,您将不得不比 AVFoundation 更深入。音频队列服务是下一层,它可以让您以音频队列处理水龙头的形式访问音频。这可能是开始处理音频的最简单方法。不过,还没有太多关于它的文档。目前最好的来源可能是标题AudioToolbox.framework/AudioQueue.h注意,这仅在 iOS 6 中引入。

比这更深的是Audio Units。这就是 RemoteIO 单元所在的位置。您可以使用 AUFilePlayer 从音频文件中产生声音,然后将该音频提供给其他音频单元进行处理(或自己处理)。这将比 AVFoundation(轻描淡写)更加棘手/冗长,但是如果您已经设置了 RemoteIO 单元,那么您可能可以处理它。

于 2012-10-29T17:44:48.707 回答