录制时ios音频单元remoteIO播放 [英] ios audio unit remoteIO playback while recording

查看:128
本文介绍了录制时ios音频单元remoteIO播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被指控将VOIP添加到游戏中(跨平台,因此不能使用Apple游戏套件来执行此操作)。

I have been charged to add VOIP into an game (cross-platform, so can't use the Apple gamekit to do it).

3或4现在,我正试图让我的脑袋绕着音频单元和remoteIO ...
我忽略了几十个例子等等,但每次它只是将一个简单的算法应用到输入PCM并播放它回到扬声器上。
根据Apple的文档,为了做VOIP,我们应该使用kAudioSessionCategory_PlayAndRecord。

For 3 or 4 days now, i'm trying to get my head wrap around audio unit and remoteIO... I have overlooked tens of examples and such, but every time it is only applying a simple algorithm to the input PCM and play it back on the speaker. According to Apple's documentation in order to do VOIP we should use kAudioSessionCategory_PlayAndRecord.

UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;

        status = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, 
                                         sizeof(audioCategory), 
                                         &audioCategory);
        XThrowIfError(status, "couldn't set audio category");

1)但似乎(对我而言)playAndRecord将始终播放来自麦克风的内容(或更令人兴奋的是PerformThru回调// aurioTouch ),我错了吗?

1) But it seems (to me) that playAndRecord will always play what coming from the mic (or more excatly the PerformThru callback // aurioTouch), am I wrong ?

我有最简单的回调,除了AURender之外什么都不做

I have the simplest callback, doing nothing but AURender

static OSStatus PerformThru(
                            void                        *inRefCon, 
                            AudioUnitRenderActionFlags  *ioActionFlags, 
                            const AudioTimeStamp        *inTimeStamp, 
                            UInt32                      inBusNumber, 
                            UInt32                      inNumberFrames, 
                            AudioBufferList             *ioData)
{
OSStatus err = AudioUnitRender(THIS->rioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
    if (err) 
       printf("PerformThru: error %d\n", (int)err);
    return err
}

从该回调我打算发送数据到同行(当然不是直接的,但数据会来自它)...

From that callback I'm intending to send data to the peer (Not directly of course, but data will come from it)...

我看不出我怎么能输出不同于输入的输出,除了有2个单元,一个录音,一个播放,但它似乎不是苹果的意图(仍然是文件)。

I do not see how I can play different output than the input, except maybe with 2 units, one recording, one playing, but it doesn't seems to be what Apple intended to (still accroding to the documentation).

当然,我找不到任何关于它的文档,音频单元仍然没有记录......

And of course, I cannot find any documentation about it, audio unit is still pretty much un-documented...

任何人都会知道最好的方法是什么?

Anyone would have an idea on what would be the best way to do it ?

推荐答案

我没有使用过VOIP或kAudioSessionCategory_PlayAndRecord。但是,如果您想录制/传输从麦克风中拾取的语音并播放来自网络包的传入数据:这里是一个很好的样本,包括麦克风和播放。此外,如果您还没有从Apple阅读此文档,我强烈建议这个

I have not used VOIP or kAudioSessionCategory_PlayAndRecord. But if you want to record/transmit voice picked up from the mic and play back incoming data from network packages: Here is a good sample which included both mic and playback. Also if you have not read this doc from Apple, I would strongly recommend this.

简而言之:您需要创建一个AudioUnits实例。在其中,配置两个回调:一个用于麦克风,一个用于回放。回调麦克风功能将为您提供从麦克风中拾取的数据。然后,您可以使用任何选择的网络协议转换并传输到其他设备。播放回调功能是您从其他网络设备提供传入数据以进行播放的地方。

In short: You need to create an AudioUnits instance. In it, configure two callbacks: one for mic and one for playback. The callback mic function will supply you the data that was picked up from the mic. You then can convert and transmit to other devices with whatever chosen network protocol. The playback callback function is where you supply the incoming data from other network devices to play back.

这篇关于录制时ios音频单元remoteIO播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆