Most performant audio layer? - iphone

I'm curious as to which of the available audio layers is the most performant, out of the ones available on the iPhone. Currently I've used the SystemSoundID method, and the AVAudioPlayer method, and I'm wondering if it's worth investigating AudioQueue or OpenAL...are there significant performance gains to be had?
Thanks!

Audio is a complex issue, and most of it is done by hardware, so there is no performance gains in changing APIs.
The different APIs are for different tasks:
SystemSound is for short notification sounds (max 10 sec)
AudioQueue is for everything longer than a SystemSound
AVAudioPlayer is just an Objective-C layer above AudioQueue, and you don't lose any performance for this layer. (So if AVAudioPlayer is working for you, stay with it!)
OpenAL is for sound effects.

What about FMOD for the iPhone? It's mostly used for game development and availible for various platforms.

I've been reading about very low level and very low latency audio using RemoteIO. Take a look at this article and subsequent (long) discussion : Using RemoteIO audio units. I wouldn't recommend going down this path unless the higher level libraries completely fail for your application. The author found very distinct performance differences between the different approaches - some quite unexpected. YMMV

Related

Sound Engine with good memory management (iPhone/iPad)

I'm looking for simple sound engine without advanced effects but with good management of buffers memory. At least it must track all playing sounds, unload not used sound buffers (but keep all currently playing), adjust gain for sound groups. Support of input streaming and compressed formats would be advantage.
PS: FMOD and BASS are good engines but too expensive for these low requirements.
I have couple of references those should be helpful to you:
The Kowalski Engine is a real time audio engine written in C, based on a hierarchical mix bus system.
http://kowalski.sourceforge.net/
The CLUNK C++ library provides support for real-time 3D(binaural) sound generation. It puts virtually no limitations on the developer
http://sourceforge.net/projects/clunk/
Easy Objective-C interface to OpenAL, AVAudioPlayer, and audio session management.
https://github.com/kstenerud/ObjectAL-for-iPhone
I believe this should be helpful to get the solution with the great memory management in place.
I've found CocosDenshion (part of Cocos2d) to be easy to use and to have a simple memory management.
Have you tried STK? It can interface with core-audio for iOS. I strongly recommend it, it has all the main important building blocks for sound synthesis, without any additional stuff (like CLAM), is very lightweight and highly portable.
I'm using SoundMaster engine.
It's super simple and has good memory management.

Real-Time Audio Loop Switching for iPhone

I'm trying to find the best way to play a seamless loop of audio, that the user can switch out for another at the shortest possible notice, with a decent number (30-150) of very short loops being available. Will OpenAL be sufficient for this, or do I need to delve into Audio Units? The Apple Documentation says that for real-time feedback like an instrument, Audio Units is the right choice.
I just want to get the community's opinion on this, and any links and sample projects would be greatly appreciated.
You can use AVAudioPlayer to seamlessly loop a compressed audio file (numberOfLoops = -1). I suggest using IMA4-encoded CAF files, as these are rumored to benefit from hardware decompression (saving CPU cycles for other things).
To keep file size down, you can lower the bit rate (try 96 kbps) and/or use mono.
Note that AVAudioPlayer does not allow you to change the tempo or frequency of playback.
this probably doesn't really answer your question, but have you ever looked at Finch?
Just looking at the source might provide some pointers.
Johannes
If you need to be able to switch to another audio sample with no playback delay, you'll need to use OpenAL. AVAudioPlayer has a delay before it starts playing.
You can minimize that delay by calling prepareToPlay, but it won't always eliminate the delay completely. As well, if you have 30 to 150 samples that the user selects for playback, you won't know beforehand which samples need to be preloaded.
Here's a rundown of the pros and cons between OpenAL and AVAudioPlayer: http://kstenerud.github.com/ObjectAL-for-iPhone/documentation/index.html#choosing_sec
I ended up using Cocos2D's audio library for this, and it was far more performant than I'd expected. AVAudioPlayer ended up being a good bit lower-level than I'd needed.

Which audio playback technology do I need for this?

I have trouble choosing the right audio playback technology. There's a ton of technologies to use on the iPhone, it's so confusing.
What I need to do is this:
start playing short sounds ranging between 0.1 and 2 seconds
high quality playback, no crackle (I heard some of the iPhone audio playback technologies do a crackle sound on start or end, which is bad!)
ability to start playback of a sound, while there's already another one playing right now (two, three or more sounds at the same time)
What would you suggest here, and why? Thanks :-)
There are basically four options for playing audio on the iPhone:
Audio Toolbox. Easy, but only good for playing sound effects in applications (sample code).
Audio Queue Services. Very powerful, can do anything. C API, pretty messy to work with. Callbacks, buckets, pain.
AVAudioPlayer. About the easiest option. Can play compressed audio, with a simple wrapper you can easily play multiple instances of the same sample at once (non-compressed audio only, as there is only one HW audio decoder). Starting to play a sound with AVAudioPlayer seems to lag about 20 ms, could be a problem.
OpenAL. Decent compromise between complexity and features. Sounds do not lag, you can play multiple sounds just fine, but you have to do a lot of the work yourself. I’ve written a sound engine called Finch that can help you.
Don’t know much about cracking, never experienced it. I think there were some issues with playing seamless compressed loops with AVAudioPlayer, can be overcome by saving the loop without compression.

What's the most suitable sound/audio framework for iPhone OpenGL-ES games?

I'm writing a game for iPhone/iPod.
My engine is using OpenGL-ES, and this means game requires some performance.
(realtime games, not a static board-game like games.)
I looked at basic sound framework in iPhone, there're several frameworks,(Core Audio, Audio Toolbox, OpenAL...) but I cannot determine differences of them in detail.
I think OpenAL will gain best performance, but it's just a guess with no clue. And iPhone/iPod is a music player hardware, I cannot know in-depth features of iPhone/iPod.
I'm new to all of those framework, so I have to study one of them. And now I'm choosing one.
The features required for me is:
Delay-less playback. Sound effect should be a realtime feedback.
Streamed long music playback with very small memory footprint.
Volume control per playback of sound effect.
Mixing. Multiple difference sound effect can be played at same time. (around 4 or more)
Other feature required for games.
Hardware acceleration (if exists)
Realtime filtering effect (reverb, echo, 3D, ...) if possible.
...
Can you recommend a framework for my game? And some explanation about each framework also will be very appreciated.
You can do everything you want with OpenAL. It's what I'd recommend for a game.
Plus, it's the only framework for 3D positional audio which often goes hand-in-hand with a 3D game.
OpenAL, Core Audio, AudioToolbox etc. are wrappers around the same things: namely, Apple’s own audio processing features. OpenAL is just a different interface but has the same performance as Core Audio, as it sends commands to the same things.
There are several other “audio engines” out there that are just wrappers.
At risk of tooting my own horn, Superpowered is the only audio SDK that outperforms Apple’s Core Audio on mobile devices. It’s specifically designed to outperform every single one of those, with lower memory footprint, CPU load and battery usage. For example, the Superpowered reverb is 5x faster than Apple’s. See http://superpowered.com/reverb/

Sounds effects in iPhone game

I'm making an opengl game for iPhone. And I'm about to start adding sound effects to the app. I wonder what's the best framework for this purpose.
Is AV foundation my best option? Any others I'm missing, like Open AL perhaps?
General strength/weakness summary of iPhone sound APIs from a game perspective:
AVFoundation: plays long compressed files. No low-level access, high latency. Good for theme song or background music. Bad for short-lived effects.
System sounds: plays short (think 0-5 sec) sounds. Must be PCM or IMA4 in .aif, .wav, or .caf. Fire-and-forget (can't stop it once it starts). C-based API. Appropriate for short sound effects (taps, clicks, bangs, crashes)
OpenAL: 3D spatialized audio. API resembles OpenGL and is a natural accompaniment to it. Easy to mix multiple sources. Audio needs to be PCM (probably loaded by Core Audio's "Audio File Services"). Pretty significant low-level access. Potentially very low latency.
Audio Queue: stream playback from a source you provide (reading from file, from network, software synthesis, etc.). C-based. Can be fairly low-latency. Not really ideal for a lot of game tasks: background music is better suited to AVFoundation, shorter sounds to system sounds, and mixing to OpenAL or Audio Units. Can record from mic.
Audio Units: lowest public level of Core Audio. Extremely low latency (< 30 ms). C, and hard-core C at that. Everything must be PCM. Multi-channel mixer unit lets you mix sources. Can record.
Be sure you set up your audio session appropriately, meaning you declare a category that indicates how you interact with the rest of audio on the device (allow/disallow iPod playback in the background, honor/ignore ring/silent switch, etc.). AV Foundation has the Obj-C version of this, and Core Audio has somewhat more powerful equivalents.
Kowalski is another game oriented sound engine that runs on the iPhone/iPad (and OSX and Windows).
You might want to check out Finch, an OpenAL sound effect engine writter exactly with games in mind.