views:

2080

answers:

3

Hi,

is there a way to adjust the speed of the playback of an audio while playing in Objective C for the iPhone/iPod touch?

Also would be interesting if playing a file backwards would be possible.

Thanks

Tom

+1  A: 

AVAudioPlayer doesn't give you speed control, but it does let you set the position, so you could do a poor man's speed up/reverse the same way QuickTime Player does: by jumping through the file and playing small snippets at normal speed.

Or you decompress the samples yourself with an offline AudioQueue and do whatever rate you want. That's what I do.

Rhythmic Fistman
Hi Rhythmic Fistman,thanks for your reply! Could you send me an email to [email protected] I like to ask you a question...ThanksTom
crashtesttommy
Why not ask it as a question on Stack Overflow?
Rhythmic Fistman
+3  A: 

A cheesy way to do it is to tweak the sample rate when you send it to the playback engine (Audio Queue, Remote I/O Unit, OpenAL). For PCM -- and I'm not sure this would work for anything other than PCM (so you'd have to decompress an MP3 or AAC with Audio Converter Services first) -- you could speed up your audio by adjusting the AudioStreamBasicDescription like this:

audioStreamDesc.mSampleRate = audioStreamDesc.mSampleRate * 1.2;

Note that this also changes the pitch of your audio: not only is it faster, it's also higher pitched. The Mac has a system-supplied audio unit that allows you to change playback speed without changing pitch, but it seems to be absent on iPhone.

invalidname
Hi,thanks for your reply. Yes I did this and this is working fine, but I am not able to change the speed while playing. Or can I? And playing backwards is also not possible, or is it?ThanksTom
crashtesttommy
I don't think Audio Converters work with MP3/AAC on the iPhone. Unless it's been fixed in 3.0, you have to use an offline Audio Queue.
Rhythmic Fistman
A: 

Hey, Do you mind telling me how you actually got to change the sample rate? I am using AudioQueue and had no luck setting (fooling the AudioQueue object) sample rate to change playback speed Are you using AudioUnits? Basically my question is where do you set this property?

Thanks, Ata

Ata