Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Change playback speed with Audio Units

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        |
       -------------------------              -------------------------
like image 315
Tom Ilsinszki Avatar asked Jul 24 '10 18:07

Tom Ilsinszki


People also ask

Can you change playback speed on iPhone music?

The ‌Apple Music‌ app itself does not let users change playback speed, but popular App Store apps like Perfect Tempo offer users that ability.

How do you change playback speed on iPhone?

Go to a video. Tap the video once, then tap More . Tap Playback Speed. Select the speed at which you'd like the video to play.

Is it possible to speed up a video on iPhone?

To speed up a video on your iPhone, you can use iMovie or the Photos app. You can adjust the speed of a video in iMovie by using the Speed button in the video editing toolbar. You can also speed up a Slo-mo video in Photos by dragging the vertical bars below the frame viewer.


1 Answers

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.

like image 125
Tom Ilsinszki Avatar answered Sep 22 '22 16:09

Tom Ilsinszki