iOS版:样品code可同时录制和回放 [英] iOS: Sample code for simultaneous record and playback

查看:256
本文介绍了iOS版:样品code可同时录制和回放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计概念的简单证明多轨录音机。

I'm designing a simple proof of concept for multitrack recorder.

明显的起点是从文件A.caf发挥到耳机,同时记录麦克风输入文件B.caf

Obvious starting point is to play from file A.caf to headphones while simultaneously recording microphone input into file B.caf

这个问题 - 录制和播放音频同时 - 指出,有三个级别的,我可以工作:

This question -- Record and play audio Simultaneously -- points out that there are three levels at which I can work:


  • AVFoundation API(AVAudioPlayer + AVAudioRecorder)

  • 音频队列API

  • 音频单元API(RemoteIO)

什么是最好的工作水平?显然,通用的答案是那个能够完成任务的最高水平,这将是AVFoundation工作。

What is the best level to work at? Obviously the generic answer is to work at the highest level that gets the job done, which would be AVFoundation.

但我承担从别人这个工作谁给了因延迟问题(他居然也得到了文件之间的延时0.3秒),所以也许我需要在一个较低的水平,努力避免这些问题?

But I'm taking this job on from someone who gave up due to latency issues (he was getting a 0.3sec delay between the files), so maybe I need to work at a lower level to avoid these issues?

此外,什么来源$ C ​​$ c是可从跳板?我一直在寻找SpeakHere样品(<一个href=\"http://developer.apple.com/library/ios/#sample$c$c/SpeakHere/Introduction/Intro.html\">http://developer.apple.com/library/ios/#sample$c$c/SpeakHere/Introduction/Intro.html )。如果我不能找到一些简单的,我会​​用这个。

Furthermore, what source code is available to springboard from? I have been looking at SpeakHere sample ( http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html ). if I can't find something simpler I will use this.

但是,任何人都可以提出一些更简单/别的吗?我宁可不使用C ++ code的工作,如果我能避免它。

But can anyone suggest something simpler/else? I would rather not work with C++ code if I can avoid it.

是任何人都知道,使用AVFoundation做一些这方面的公共code的?

Is anyone aware of some public code that uses AVFoundation to do this?

编辑:AVFoundation这里的例子:<一href=\"http://www.iphoneam.com/blog/index.php?title=using-the-iphone-to-record-audio-a-guide&more=1&c=1&tb=1&pb=1\">http://www.iphoneam.com/blog/index.php?title=using-the-iphone-to-record-audio-a-guide&more=1&c=1&tb=1&pb=1

AVFoundation example here: http://www.iphoneam.com/blog/index.php?title=using-the-iphone-to-record-audio-a-guide&more=1&c=1&tb=1&pb=1

编辑(2):很多更好看的一个在这里:<一href=\"http://www.switchonthe$c$c.com/tutorials/create-a-basic-iphone-audio-player-with-av-foundation-framework\">http://www.switchonthe$c$c.com/tutorials/create-a-basic-iphone-audio-player-with-av-foundation-framework

EDIT(2): Much nicer looking one here: http://www.switchonthecode.com/tutorials/create-a-basic-iphone-audio-player-with-av-foundation-framework

编辑(3):<一href=\"http://stackoverflow.com/questions/1010343/how-do-i-record-audio-on-iphone-with-avaudiorecorder\">How我在iPhone上录制音频与AVAudioRecorder?

推荐答案

的建议通过的Viraj,这里就是答案。

As suggested by Viraj, here is the answer.

是的,你可以实现使用AVFoundation很好的效果。首先,你需要注意的事实,同时为播放机和录像机,激活他们的是两个步骤。

Yes, you can achieve very good results using AVFoundation. Firstly you need to pay attention to the fact that for both the player and the recorder, activating them is a two step process.

首先,你贷了。

然后你玩了。

所以,首要的一切。然后发挥了一切。

So, prime everything. Then play everything.

这将得到您的等待时间下降到约70ms的。我通过记录一个节拍器打勾,然后打回通过扬声器同时按住iPhone到扬声器和同时记录测试。

This will get your latency down to about 70ms. I tested by recording a metronome tick, then playing it back through the speakers while holding the iPhone up to the speakers and simultaneously recording.

第二记录有一个明确的回应,我认为是〜70ms的。我可以在分析的无畏的信号,以得到一个确切的偏移量。

The second recording had a clear echo, which I found to be ~70ms. I could have analysed the signal in Audacity to get an exact offset.

因此​​,为了样样在行了,我只是performSelector:X withObject:Y afterDelay:70.0 / 1000.0

So in order to line everything up I just performSelector:x withObject: y afterDelay: 70.0/1000.0

有可能是隐藏的断枝,例如延迟可以从设备的不同而不同的设备。它甚至可以根据设备的活动不同。线程可以被打断/启动播放器,并开始刻录机之间的重组,甚至可能。

There may be hidden snags, for example the delay may differ from device to device. it may even differ depending on device activity. It is even possible the thread could get interrupted/rescheduled in between starting the player and starting the recorder.

但它的工作原理,以及比用音频队列/单位乱搞整洁了不少。

But it works, and is a lot tidier than messing around with audio queues / units.

这篇关于iOS版:样品code可同时录制和回放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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