title: Which audio API available in iOS/Cocos2d is best for a complex sound mix?
body: <p>I am developing a cinematic iPad app using cocos2d and I want more control than most high level audio APIs provide. Within cocos2d and the iOS SDK, I have access to CocosDension (which is really three APIs with slightly different features) and CoreAudio (which also contains multiple APIs of varying levels and features). I am trying to figure out which API(s) will support the features I need, and I could use some help.</p>
  
  <ul>
  <li>My app needs 4 tracks of audio, each with a separate playback volume that can be controlled by the user:
  <ul>
  <li>Background Music</li>
  <li>Ambient Sound</li>
  <li>Narration</li>
  <li>Sound Effects</li>
  </ul></li>
  </ul>
  
  <p>Music and Ambient tracks need to play stereo loops from disk which are 1-4 minutes long.
  I need to be able to preload, start/stop, loop, fade in/out, and adjust playback volume of these tracks.
  Pausing is not important for these two tracks since they will continue to play in the background when menus are up.</p>
  
  <p>Narration track needs to play one mono file at a time, of 30-60 seconds length, panned center.
  Effects track needs to play multiple mono files of 1-5 seconds simultaneously mixed into a stereo sound stage.
  Each clip being played should be able to be preloaded, started/stopped, and have its pitch, gain, and pan adjusted.
  These two tracks' playback should be able to be paused/resumed.</p>
  
  <p>If I use CocosDension::<a href="http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_simple_audio_engine.html" rel="nofollow">SimpleAudioEngine</a>, I believe I can do exactly half of what I want. That is to say, if I just had Music and Effects tracks I could adjust their volumes separately and use the appropriate methods to play background music and effects with all the options I want. The same is true if I only had Ambient and Narration tracks, making me wonder if it's possible to bypass the singleton architecture of SimpleAudioEngine so I could have two instances, thus two pairs of BG/FX tracks. </p>
  
  <p>If it's possible to play two background audio tracks at once, I could sacrifice the ability to adjust the music/ambient volumes separately and merge the narration track into the effects (controlling its volume at the sound clip level). I really would like to keep music and ambient sound adjustable by the user with separate volume knobs though. Is there a way to make this happen in CocosDension?</p>
  
  <p>If I use CoreAudio, the Multichannel Mixer AudioUnit seems like the perfect thing to accomplish my volume control goals. However, utilizing it seems to require I set up an awful lot of low-level buffer and audio signal path code. Unless I'm wrong, in order to support all the stuff I get for free in CocosDension (32 simultaneous fx playing with pan, pitch, and gain control + background music) I'd need to construct an Audio Processing Graph something like:</p>
  
  <pre><code>[Custom Audio Rendering Code ]   [Multichannel Mixer Unit]----&gt;[Output Unit]
   | musicRenderCallback()----|----&gt;| bus 0: "Music"      |
   | ambientRenderCallback()--|----&gt;| bus 1: "Ambient"    |
   | narrationRenderCallback()|----&gt;| bus 2: "Narration"  |
   +~~~~~~~~~~~~~~~~~~~~~~~~~~+     | bus 3: "Effects"    |&lt;----+
   |                                +---------------------+     |
   |                                                            |
   +~~~~~~~~~~~~~~~~~~~~~~~~~~+    [Multichannel Mixer Unit]----+
   | effectsRenderCallback0()-|----&gt;| bus 0: "Effects0"   |
   | effectsRenderCallback1()-|----&gt;| bus 1: "Effects1"   |
   | ...                      |     | ...                 |
   | effectsRenderCallback31()|----&gt;| bus 31: "Effects31" |
   +~~~~~~~~~~~~~~~~~~~~~~~~~~+     +---------------------+
   | audioQueueBuffers[35]    |
   +--------------------------+
  </code></pre>
  
  <p>This seems fairly complex from an implementation standpoint. Is there an easier way to do it, possibly mixing CocosDenshion and CoreAudio APIs together? Do they play well in the same pool?</p>