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

发布于 2024-09-11 02:55:34 字数 398 浏览 5 评论 0原文

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

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

我当前的设置:

<前><代码> ------------------------- ------------------- ------ |搅拌机| -----------> | IO单元| ------------------------ ------------------------

What are the different ways to change the playback speed of audio on the iPhone, when using Audio Units? What are the advantages / disadvantages of each solution?

I have a mixer unit and an IO unit. Do I need to add another unit (eg. converter unit)? What audio unit parameters should I set, on which (input or output) bus on which audio unit(s)?

My current setup:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-09-18 02:55:34

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

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

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

3D 混合器单元:使用 3D 混合器单元代替多通道混合器单元,并在输入范围上设置 k3DMixerParam_PlaybackRate。

优点: k3DMixerParam_PlaybackRate 可以在播放音频时实时设置,没有任何削波声音或其他副作用。一旦您有了音频单元,实施起来也很容易。

缺点:影响音频的音调,但如果您只需将播放速率改变 +/- 8%,音调的差异并不明显。

解决方案#2

更改采样率:更改混音器单元输出总线上的采样率。更改采样率的工作方式与添加和删除样本非常相似。

优点:如果您想将播放速度乘以整数的一小部分(例如 1.2x),效果很好。

缺点:无法即时设置更改混音器输出的采样率;仅在初始化混音器单元时。影响音频的音高,但如果您只需要将播放速率改变 +/- 8%,则音高的差异并不明显。

audioDescriptionMixerOutput.mSampleRate = 1.2*kGraphSampleRate;

解决方案#3

添加/删除样本:仅将第二个、第三个……音频样本传递到渲染回调函数中的音频单元(在我的例子中是混合器单元)的输入。

优点:如果您想将音频播放速度加快或减慢 2 倍、3 倍、4 倍等,则效果很好。而且也很容易实现。

缺点:您只能将播放速度乘以整数倍。例如,通过添加或删除样本不可能将音频播放速度提高 1.2 倍。影响音频的音高。

All of the below solutions will alter the pitch of your audio (along with the playback speed). To correct the pitch of your audio after the playback speed has been changed you'll need to use a 3rd party audio library (such as SoundTouch, which has an LGPL license, so you can use it in your app, without making it open-source, or DiracLE or the free smbPitchShift). There is an audio unit (AUPitch), that can change the pitch of your audio, but it's not available for iPhone; only for Mac.

All of the solutions below are tested, and work...

Solution #1 [Best solution]

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%.

Solution #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;

Solution #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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文