Rewind 30 seconds audio and play 2X speed - iphone

I have a Query regarding playing audio: Can I rewind the audio 30 secs and Play with 2X speed? Is that possible like in Podcasts in iPhone?
Thanks

If you want to speed up sound without making the pitch high and squeaky, then you may need to license a commercial DSP time-pitch stretch library such as Dirac, et.al. (There may be some open source code to do this in Audacity, but I am unaware of a working iOS port of such).

Related

a good way to preaload audio files using openAL in iOS

I'm making a game for iOS platform and i want to use openAL for playing audio effects in the game (except the background music). I want to have for example 20-30 sounds with duration of 1-3 seconds each. Because i want these sounds to be played with no delay i have to load from file, decompress and store in the memory. But decompressed audio (as i understand) uses a lot of memory. So am I on the right way? Or there is another way ? Thanks
Loading sounds does incur a delay, and can cause the rest of the app to jitter. For best performance you definitely want to preload sound effects.
Memory use is a concern, but as long as you're not loading too much audio data into memory at a time, you'll be OK.
44KHz mono audio data will occupy 88,000 bytes per second when uncompressed. Stereo is double that, but usually for sound effects you don't want stereo anyway. So if you had 30 sounds loaded, each of 3 second duration, you'd have 90 seconds of sound using 7.5MB of memory. You can of course halve that memory usage by using a 22050 Hz source before compressing it to AAC (which preserves the source sample rate).
What I do is maintain a cache of audio buffers that I can flush when the app starts to use too much memory like so: https://github.com/kstenerud/ObjectAL-for-iPhone/blob/master/ObjectAL/ObjectAL/OALSimpleAudio.m#L441
For the lowest latency sound effects, you will want to play uncompressed audio already in memory. 2 or 3 MBytes is not a lot of memory to allocate for low latency sound effects.

Access an mp3 in Cocos2D

I am playing a song in Cocos2D iphone using this line.
[[SimpleAudioEngine sharedEngine] playEffect:#"song.mp3"];
Suppose the mp3 is 1 min long, I want to play the song from 10 sec to 20 sec. Is it possible in Cocos2D iphone. Please help.
I don't think it is possible to "play the song from 10 sec to 20 sec" using the audio engine of cocos2d-iphone (which is named CocosDeshion).
SimpleAudioEngine is the main interface to CocosDeshion. Basically in cocos2d development we use audio files in two way - sound effect (short) and background music (long and usually loop). playEffect: is for the short ones, while playBackgroundMusic: and playBackgroundMusic:loop: is for the long ones. preloadBackgroundMusic: provides you the ability to cache the music in memory to avoid lag while playing, since they are often in compressed format.
As you can see in the documentation of SimpleAudioEngine (link above), there isn't such method for you to play a part of an audio file. Even the underlying class CDAudioManager doesn't support this.
I suggest to extract the 0:10 - 0:20 part as a separate audio file. But if you have a special reason to do this, you may want to use audio playback interfaces (such as AVAudioPlayer) in iOS SDK directly. Please refer to: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html

Reduce audio playback latency in iphone

I want to play a simple audio file on tapping buttons(think of a piano kind of app).I could play the audio but it has high latency(takes a sec or two to play). Is there a way to decrease the latency?. Please help.

MPMusicPlayerController Speed Adjustment

HI,
Is there any way to adjust the speed of the song being played by the MPMusicPlayerController?
I've searched everywhere but didn't find anything useful. If there is no way to do it where can I find an example which does it with other components? Some say OpenAL, but I can't find any clear way to use the iPod library with this and change the speed of the song...
Mainly the thing I need is:
The user chooses a song from the iPod library trough MPMusicPlayerController
You have 2 buttons: Slow Down & Speed Up
If the user presses "Slow Down" the speed of the song is slowed down by lets say 5% or something. "Speed Up" visa-versa.
I really hope someone can help me with this!
Thanks in advance!
You could do this as of iOS 3.2 and later -
[musicPlayer play];
[musicPlayer setCurrentPlaybackRate:2.0];
Ref: https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMediaPlayback_protocol/Reference/Reference.html#//apple_ref/occ/intfp/MPMediaPlayback/currentPlaybackRate
You can use AVAudioPlayer and AVPlayer for the above purpose.
They have a rate property which can set the speed of the song.
[AVPlayer setRate:1.25]; // 25% faster
However, AVPlayer cannot change the speed by 5% but 25% and AVAudioPlayer works for iOS 5 and above.
If you wish to go for other alternative then Dirac is the best option. Try DIRAC 3 LE which is free.
Use this Link to get an idea on how to use Dirac. For more information, let me know.
#girish_vr
No, you can't do this using only the MPMusicPlayerController.
If you don't mind the pitch going up and down proportional to the speed changes, then you can use the OpenAL resampler after converting your sound file to raw PCM sample files or buffers.
If you don't want the pitch to change, what you are looking for is DSP time pitch stretching/modification/correction techniques. OpenAL can't do this, but there are commercial DSP libraries (DIRAC may be one) available that can do this on iOS. You could also try writing your own phase vocoder, but this is non-trivial digital signal processing code.

How can I speed up or slow down a background music track with iPhone SDK?

Is there an easy way to control the playback speed/tempo of a sound file loop played using Audio Queue Services? For example, if a game is playing background music, I want to make the BGM speed up as time runs out, but without changing the pitch of the music. Thx!
There's no trivial way to do this that I know of. On the Mac, you'd presumably use Audio Units to do this, but I think the support for those is limited on the iPhone SDK.
You can do some processing during your AudioQueue playback callback, between AudioFileReadPackets() and AudioQueueEnqueueBuffer() but I think speed-shifting without changing the tone will require rather a lot of CPU time.
It'd probably be easier to have more than one recording of the music, and switch files during a silent passage of the music.