I’m a Unity dev and need to help out colleagues with doing this natively in Obj-C. In Unity it’s no big deal :
1)samples are stored in memory as a List of float[]
2)A helper function returns float[] of n size for any given sample, at any given offset
3)Another helper function fades the data if needed
4)An AudioClip object is created with the right size to accomodate all cut samples, and is then filled at appropriate offsets.
5)The AudioClip is assigned to a player component(AudioSource).
6)AudioSource.Play(ulong offsetInSamples), plays at a sample accurate time in the future. Looping is also just a matter of setting the AudioSource object’s loop parameter.
I would very much appreciate if someone could point me towards the right classes to achieve similar results in Obj-C, for iOS devices. I’m pretty sure a lot of iOS audio newbies would be intersted too. Many thanks in advance!
Gregzo
A good overview of the relevant audio APIs available in iOs is here
The highest level framework that makes sense for patching together audio clips, setting their volume levels, and playing them back in your case is probably
AVFoundation.It will involve creating
AVAssets, adding them toAVPlayerItems, possibly putting them intoAVMutableCompositions to merge multiple items together and adjust their volumes (audioMix), and them playing them back withAVPlayer.AVFoundation works with AVAsset, for converting between relevant formats and lower level bytes you’ll want to have a look at
AudioToolbox(I can’t post more than two links yet).For an somewhat simpler API with less control have a look at
AVAudioPlayer. If you need greater control (eg: games – real time / low latency) you might need to use OpenAL for playback.