Play just a part of the sound (both in and out) with OpenAL (iOS)? - iphone

I have a recording that has some unuseful voices at the beginning, and at the end.
How can I play just the middle part of the sound?
I have AL_SEC_OFFSET, that is suitable for the entry point, I already use it, but what about the endpoint?
Is there any smart OpenAL settings for this? Hopeso.
Thanks.

There could be a workaround that fires a timer that stops playing before end.
Any simplier?

OpenAL doesn't have built-in support for stopping playback at a specific sample point. A timer is your best bet in this case, even though it will be somewhat inaccurate.
If you want sample-perfect stopping, you could just load the middle part of the audio file into an ALBuffer rather than the entire thing. I have some code which does that here:
https://github.com/kstenerud/ObjectAL-for-iPhone/blob/master/ObjectAL/ObjectAL/Support/OALAudioFile.m#L188

Related

Looping audio on iOS with explicit loop-in and loop-out points

I am developing an iOS application which resembles a musical instrument.
I am trying to loop the sound samples to make them last infinitely. Simple looping is not sufficient in this case, as the samples have an "attack" section: Each sample has a part at the beginning which should not be looped. Therefore, I need some way to loop only a certain part of the sound sample.
I found a few iOS sound libraries (e.g. ObjectAL), but they all seem to support only simple looping, without an option to set loop-in and loop-out points.
Are they any iOS audio libraries which support this feature? Otherwise, what would be the best method to implement it? (Audio units? Audio queues? Some other trick with existing libraries?)
Thanks!
I can't say if it's the best solution, but for my loops that have an intro / outro... I use multiple .caf files that blend together: one for the intro, one for the loop, and one for the outro.
After the intro, the loop starts and plays until an event fires that makes the sound stop looping and finish, and then the outro immediately plays once the loop sound finishes.
I use Audacity to edit the sound files to make sure that they blend together perfectly.
Edit:
My application uses cocos2d, so I'm using the cocosDehension audio library since it is built in to cocos2d. As long as the sound file has been properly edited, it loops cleanly with no clicks or pops.
Here's a link to the technique that I used in Audacity to make sure the file looped without clicks:
http://forum.audacityteam.org/viewtopic.php?f=13&t=2820#p11073

AudioServices (Easy), AVAudioPlayer (Medium), OpenAL (Hard & Overkill?)

I need to play sounds (~5 seconds each) throughout my iphone application. When they're triggered, they need to play immediately.
For the moment I'm using AudioServices and (as you probably know) the first time you play a sound it lags, then every time there after it's perfect. Is there some code available that's clever enough to preload an AudioServices sound (by playing it silently maybe?). I've read adjusting the system volume programmatically will get your app rejected, so that's not an option. Seems AudioServices isn't made for volume correction from what I can see.
I've looked into OpenAL and while feasible seems a little over kill. AVAudioPlayer seems like a little bit of a better option, I'm using that for background music at present. Extending my music player to handle a 'sound board' might be my last resort.
On the topic of OpenAL, does anyone know of a place with a decent (app store friendly) OpenAL wrapper for the iPhone?
Thanks in advance
Finch could be perfect for you. It’s a tiny wrapper around OpenAL with very low latency and simple API. See also all SO questions tagged ‘Finch’.
If you use an AVAudioPlayer, you can call prepareToPlay when you initialize the object to reduce the delay between calling play and having the audio start.

Preload sounds played via iPhone AudioServices

I built an iPhone app using AudioServices to play short sounds. The first time a sound is played, there's a delay of half a second or so while the sound loads before it plays. This definitely makes for an awkward user experience.
Is there a way to preload sounds for AudioServices to play, or do I need to switch to audioQueues or some other method of playing sounds?
Thanks,
Maha
This is a well known problem. Everything in AudioServices is initialized lazily.
I think that your best choice is between Core Audio or OpenAL. OpenAL might be overkill, but it has a simple API. The oalTouch example is a good place to start.
Core Audio is a bit more raw, but it's well documented. The iPhone's OpenAL SDK is built on top of it.

iPhone MPMusicPlayerController playback starting position

I'm using Media Player Framework to access the user's music library on iPhone. I would like to set the playback starting position so that I can start playing a song from 30 second mark, for example.
I have trouble finding out how to do this. The MPMediaPlayerController only offers beginSeekingForward but that's not quite what I'm looking for as it simply accelerates the playback speed.
There is probably something really simple that I'm missing.
MPMusicPlayerController's property currentPlaybackTime is a writeable property, so adjusting the playback starting point can be done with player.currentPlaybackTime = 30.0
You can use player.currentPlaybackTime to set the time, before you start playing and playback will start at your desired point.
UPDATE
2009 me had some real problems. He didn't really understand properties and missed the fact that MPMusicPlayerController.currentPlaybackTime is writable! And he was angry. Angry because iOS3.0 had promised iPod Library "Access" and instead delivered MPMusicPlayerController. He had been hoping for speedy access to the music packet data upon which he would have built many fascinating and magical audio applications. Luckily, iOS4.1's AVAssetReader came along 1 year later and he was finally able to stop hating.
WRONG 2009 ANSWER
Nope, this API is deliberately crippled, which is why you don't see any functions for
opening, or streaming from, the media file.
Your only hope is lowering the volume and calling beginSeekingForward until currentPlaybackTime returns >= 30s.
Enjoy!

How can Play Audio file in loop without any interruption?

I am trying to develop a simple iPhone app. I need to play sound within a loop.
How can Play Audio file in loop without any interruption ?
Take a look at the new AVAudioPlayer class in the 2.2 release:
http://developer.apple.com/iphone/library/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html
It has functionality for looping sounds.
I really don't know the iPhone SDK at all, but this should be quick: try making the sound itself looping. That way, you should be able to play it with just a single call, and won't need to worry about timing the repeat properly to restart it at the exact right moment.
For instance, WAV files have very flexible support for looping, and any decent audio editor should let you set looping points.
The AVAudioPlayer has numberOfLoops property where you can specify the number of times you want the audio to loop.