iPhone:使用音频单元更改播放速度

标签 iphone audio core-audio audiounit

使用音频单元时,有哪些不同方法可以更改 iPhone 上音频的播放速度?每种解决方案的优点/缺点是什么?

我有一个混频器单元和一个 IO 单元。我需要添加另一个单元(例如转换器单元)吗?我应该在哪个音频单元的哪个(输入或输出)总线上设置哪些音频单元参数?

我当前的设置:

       -------------------------              -------------------------
       |      mixer unit       | -----------> |        IO unit        |
       -------------------------              -------------------------

最佳答案

以下所有解决方案都会改变音频的音高(以及播放速度)。要在更改播放速度后更正音频的音高,您需要使用第 3 方音频库(例如 SoundTouch ,它具有 LGPL许可证,这样您就可以在您的应用程序中使用它,而无需将其开源,或 DiracLE 或免费的 smbPitchShift )。有一个音频单元 (AUPitch),可以改变音频的音调,但它不适用于 iPhone;仅适用于 Mac。

下面的所有解决方案都经过测试,并且有效...

解决方案#1 [最佳解决方案]

3D Mixer Unit: Instead of a Multichannel Mixer unit use a 3D Mixer unit and set the k3DMixerParam_PlaybackRate on the input scope.

Advantages: k3DMixerParam_PlaybackRate can be set real-time, while you are playing audio, without any clipping sounds or other side effects. It's also easy to implement once you have audio units going.

Disadvantages: Affects the pitch of your audio, but the difference in pitch is not really noticeable if you only need to alter the playback rate by +/- 8%.

解决方案#2

Changing sample rate: Change the sample rate on the output bus of the mixer unit. Changing the sample rate works very similarly to adding and removing samples.

Advantages: Works well if you want to multiply the playback speed by a fraction of an integer (1.2x for example).

Disadvantages: Changing the sample rate of the mixer output can't be set on the fly; only when initializing the mixer unit. Affects the pitch of your audio, but the difference in pitch is not really noticeable if you only need to alter the playback rate by +/- 8%.

audioDescriptionMixerOutput.mSampleRate = 1.2*kGraphSampleRate;

解决方案#3

Add/remove samples: Only pass every second, third, ... audio sample to the input of your audio unit (mixer unit in my case) in your render callback function.

Advantages: Works well if you want to speed up or slow down your audio playback by 2x, 3x, 4x, etc. It's also easy to implement.

Disadvantages: You can only multiply the playback speed by an integer factor. Speeding up audio playback by 1.2x for example is not possible by adding or removing samples. Affects the pitch of your audio.

关于iPhone:使用音频单元更改播放速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3326259/

相关文章:

ios - 在 aac 流中检测信号/标志的最佳实践

javascript - 从 javascript webapp 使用 NSUserDefaults

iphone - 针对服务而非内容的 iOS 定期订阅政策

ios - 开发一个iPhone应用程序,就像地址簿的简化版本

machine-learning - 是否有关于检测乐器是否演奏正确音符的论文或模型?

objective-c - 可以使用CoreAudio获取音频流数据到系统输出设备吗?

iphone - 新 iPhone 型号发布后的整页背景图像尺寸 (Xcode)

python-3.x - scipy.io.wavfile.read()返回什么?

javascript - setTimeOut 在函数中未按预期工作

ios - 可以使用 AudioUnit (CoreAudio) 将音频编码为 AAC 或 MP3 吗?