播放使用RemoteIO和音频单元的音频文件

问题描述:

我在看苹果的aurioTouch为iPhone的例子,我想发挥MP3或WAV,而不是使用内置的麦克风。我是很新的iPhone编程的音频部分,但我想我需要修改SETU premoteIO(...)和替换功能命名为补偿与扮演一个文件的自定义AudioComponent的AudioComponent。基本上我想该应用功能完全相同的原,但是与音频文件作为输入来代替麦克风。

I am looking at Apple's 'aurioTouch' example for the iPhone and I would like to play an mp3 or wav instead of using the built in mic. I am very new to the audio portion of iPhone programming, but I think I need to modify the SetupRemoteIO(...) function and replace the AudioComponent named 'comp' with a custom AudioComponent that plays a file. Basically I want the app to function exactly the same as the original, but with an audio file as the input instead of the mic.

您只需要您的音频文件转换为PCM数据,然后播放回调过程中养活数据到RemoteIO接口。

You just need to convert your audio file to pcm data and then feed that data to the RemoteIO interface during the playback callback.

要读你的音频文件,你会希望使用ExtAudioFileOpenURL和ExtAudioFileRead。另外,还要确保与ExtAudioFileSetProperty设置您的音频格式转换到目标PCM格式(这应包装,有符号整数PCM数据)。

To read your audio file in, you will want to use ExtAudioFileOpenURL and ExtAudioFileRead. Also make sure to set your audio format with ExtAudioFileSetProperty to convert to your target pcm format (which should be packed, signed integer PCM data).

播放只涉及响应RemoteIO回调(这应该是相同的aurioTouch的例子)和喂养它,你装了PCM数据。

Playback simply involves responding to the RemoteIO callback (which should be identical to aurioTouch's example) and feeding it the PCM data you loaded up.

其他唯一棘手的部分是,加载整个MP3文件作为PCM会占用大量的内存。您可能需要编写一个装载线程,这样就可以只加载MP3的您的相关大块留在你的内存需求。

The only other tricky part is that loading an entire mp3 file as PCM can take up a ton of memory. You might have to write a loading thread so that you can stay under your memory requirements by only loading your relevant chunk of the mp3.