<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mobile Perspectives &#187; OpenAL</title>
	<atom:link href="http://www.BluMtnWerx.com/blog/tag/openal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.BluMtnWerx.com/blog</link>
	<description>Computing at the Edge!</description>
	<lastBuildDate>Tue, 27 Jul 2010 23:43:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Taming SoundEngine Processor Utilization</title>
		<link>http://www.BluMtnWerx.com/blog/2009/07/taming-soundengine-processor-utilization/</link>
		<comments>http://www.BluMtnWerx.com/blog/2009/07/taming-soundengine-processor-utilization/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 22:26:22 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[iPunt]]></category>
		<category><![CDATA[OpenAL]]></category>

		<guid isPermaLink="false">http://www.BluMtnWerx.com/blog/?p=224</guid>
		<description><![CDATA[Here's a simple modification to SoundEngine that cures performance problems with looping effects having long preambles (or attack buffers.)]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using the SoundEngine example code from Apple for OpenAL sounds on iPhone, I have a tip for you.  I ran into a serious processor utilization problem when using SoundEngine_LoadLoopingEffect() to load a sound effect that had a long preamble and then transitioned into a steady-state loop.  At first glance, this function looks ideal for such a thing because it will allow you to load a sound to be played when the effect starts, then a sound that is looped, then a sound that is played when the effect is stopped.  What I found was that, while the preamble (called the <em>AttackBuffer</em> in SoundEngine) is playing, SoundEngineEffect::PlaybackProc() hogs the processor.  This led to serious frame rate issues in <a title="iPunt iPhone game web page." href="http://www.blumtnwerx.com/iPunt.html" target="_blank" title="iPunt iPhone game web page.">iPunt</a> .</p>
<p>The cause is the following code in SoundEngineEffect::PlaybackProc()</p>
<pre>  if (THIS-&gt;HasAttackBuffer())
  {
    ALint numBuffersProcessed = 0;
    while (numBuffersProcessed &lt; 1)
    {
       alGetSourcei(THIS-&gt;GetEffectID(), AL_BUFFERS_PROCESSED, &amp;numBuffersProcessed);
         AssertNoOALError(&quot;Error getting processed buffer number&quot;, end)
    }</pre>
<p>While the attack buffer is playing, you&#8217;re in a tight polling loop waiting for it to complete.  This is no problem if the preamble is really short, but for OpenGL games, it&#8217;s going to cause problems for any sound longer than a fraction of a frame.</p>
<p>The fix, fortunately, is simple.  Sleep this thread for a few milliseconds each iteration of the polling loop in order to give the rest of your application a chance to run.</p>
<p>The modified code is:</p>
<pre>  if (THIS-&gt;HasAttackBuffer())
  {
    ALint numBuffersProcessed = 0;
    while (numBuffersProcessed &lt; 1)
    {
       alGetSourcei(THIS-&gt;GetEffectID(), AL_BUFFERS_PROCESSED, &amp;numBuffersProcessed);
         AssertNoOALError(&quot;Error getting processed buffer number&quot;, end)
       usleep(5000);  // Sleep for 5 mS each polling loop
    }</pre>
<p>This little change makes all the difference for this bit of code and makes it suitable for long (&gt; 1second) preambles.</p>
<p>I&#8217;ve found SoundEngine to work pretty well, although I have had to make a number of modifications to it for my specific application.  However, I think I&#8217;m at the point where I need to write my own OpenAL sound processing class library.  I&#8217;d be interested to hear from some of you to see what you&#8217;re using for game sound.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.BluMtnWerx.com/blog/2009/07/taming-soundengine-processor-utilization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing Audio on the iPhone</title>
		<link>http://www.BluMtnWerx.com/blog/2009/06/playing-audio-on-the-iphone/</link>
		<comments>http://www.BluMtnWerx.com/blog/2009/06/playing-audio-on-the-iphone/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 05:51:56 +0000</pubDate>
		<dc:creator>deans</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[AudioSession]]></category>
		<category><![CDATA[AVAudioPlayer]]></category>
		<category><![CDATA[iPhone Dev Tools]]></category>
		<category><![CDATA[OpenAL]]></category>
		<category><![CDATA[SoundEngine]]></category>

		<guid isPermaLink="false">http://www.BluMtnWerx.com/blog/?p=151</guid>
		<description><![CDATA[The iPhone SDK has a rich set of support services for playing audio.&#160;  Sometimes the challenge is selecting the best fit for a particular situation.]]></description>
			<content:encoded><![CDATA[<p>Almost everything covered in this post is available in Apple&#8217;s excellent developer documentation, but many of us don’t seem to have the patience to &#8220;go to the source,&#8221; so I&#8217;ll try to extract some of the choice bits out here.</p>
<p>One of the questions that I&#8217;ve faced myself, and that I&#8217;ve now tried to answer many times for others, is, &#8220;Which method should I use to play sounds for my app?&#8221;</p>
<p>Here&#8217;s the overview, right from Apple&#8217;s <a href="http://developer.apple.com/iphone/library/referencelibrary/GettingStarted/GS_AudioVideo_iPhone/index.html" title="iPhone Reference Library:&nbsp;  Audio and Video">Getting Started with Audio &#038; Video</a> document:</p>
<blockquote><p><em><strong>Playing Audio and Invoking Vibration</strong><br />
Depending on your needs, you play audio in iPhone OS using System Sound Services, the AVAudioPlayer class, Audio Queue Services, OpenAL, or the I/O audio unit.</p>
<ul>
<li>To play alerts and user-interface sound effects, or to invoke vibration, use System Audio Services. This technology can play .caf, .wav, and .aif files containing sounds with durations of 30 seconds or less. Refer to “<a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AudioandVideoTechnologies/AudioandVideoTechnologies.html#//apple_ref/doc/uid/TP40007072-CH19-SW3" title="iPhone OS Programming Guide:  Audio and Visual Technologies">Using Sound in iPhone OS</a>” in <a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/index.html#//apple_ref/doc/uid/TP40007072" title="iPhone OS Programming Guide">iPhone Application Programming Guide</a> and to <a href="http://developer.apple.com/iphone/library/documentation/AudioToolbox/Reference/SystemSoundServicesReference/index.html#//apple_ref/doc/uid/TP40007916" title="Audio ToolBox Reference:  System Sound Services Reference">System Sound Services Reference</a>.</li>
<li>To play sounds of any duration, to play multiple sounds simultaneously [dgs- see comments on this below], or to play sounds with level control, use the AVAudioPlayer class. This technology can play any audio format supported in iPhone OS including MP3, AAC, ALAC (Apple Lossless), IMA4, linear PCM, and others. See <a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/index.html#//apple_ref/doc/uid/TP40007072" title="iPhone OS Programming Guide">iPhone Application Programming Guide</a> and <a href="http://developer.apple.com/iphone/library/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/index.html#//apple_ref/doc/uid/TP40008067" title="AVFoundation:  AVAudioPlayer Class Reference">AVAudioPlayer Class Reference</a>.</li>
<li>To play sounds with precise control—such as for synchronization—or to play audio captured from an Internet stream, use Audio Queue Services. See <a href="http://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/index.html#//apple_ref/doc/uid/TP40005343" title="Music and Audio:  AudioQueue Programming Guide">Audio Queue Services Programming Guide</a> and <a href="http://developer.apple.com/iphone/library/documentation/MusicAudio/Reference/AudioQueueReference/index.html#//apple_ref/doc/uid/TP40005117" title="Music and Audio:  AudioQueue Reference">Audio Queue Services Reference</a>. For sample code, see <a href="http://developer.apple.com/iphone/library/samplecode/SpeakHere/index.html#//apple_ref/doc/uid/DTS40007802" title="Sample Code:  SpeakHere">SpeakHere</a>.</li>
<li>To play positional audio, especially if your application is a game, use OpenAL, an open source technology documented at <a href="http://openal.org">http://openal.org</a>. See <a href="http://developer.apple.com/iphone/library/technotes/tn2008/tn2199.html#//apple_ref/doc/uid/DTS40007999" title="Technical Note TN2199:  OpenAL FAQ for iPhone OS">OpenAL FAQ for iPhone OS</a> for important information on using this technology in iPhone OS. For sample code, see <a href="http://developer.apple.com/iphone/library/samplecode/oalTouch/index.html#//apple_ref/doc/uid/DTS40007769" title="Sample Code:  oalTouch">oalTouch</a>.</li>
<li>To play sounds with lowest I/O latency, or to provide simultaneous audio input and output, use the I/O audio unit. See the <a href="http://developer.apple.com/iphone/library/samplecode/aurioTouch/index.html#//apple_ref/doc/uid/DTS40007770" title="Sample Code:  aurioTouch">aurioTouch sample.</a></li>
</ul>
<p></em></p></blockquote>
<p>Some details that are left out of this overview, including:</p>
<p><strong>Compressed Formats on the iPhone</strong> &mdash; The bottom line here is that the higher level frameworks on the iPhone will only play one highly compressed sound at a time.&nbsp;  This is due to limitations in the processing available to decompress sounds in the audio pipeline.&nbsp;  You might be able to get around this by implementing your own decoder and feeding the resulting uncompressed audio to either OpenAL, or AudioQueue, but that&#8217;s beyond my interests at this point.&nbsp;  Apple&#8217;s statement above regarding AVAudioPlayer could be a bit misleading, because AVAudioPlayer will <strong>not</strong> play multiple MP3 sounds simultaneously.&nbsp;  Here&#8217;s the section from <a href="http://developer.apple.com/iphone/library/codinghowtos/AudioAndVideo/" title="Coding How-Tos: Audio and Video">Coding How-Tos: Audio and Video</a>:</p>
<blockquote><p><em>The following limitations pertain for simultaneous sounds in iPhone OS, depending on the audio data format:</p>
<ul>
<li>AAC, MP3, and ALAC (Apple Lossless) audio: no simultaneous playback; one sound at a time.</li>
</ul>
<p></em>
</p></blockquote>
<p><strong>Can I Play an MP3 with SystemAlerts?</strong>  &mdash; No.&nbsp;  SystemAudioServices only plays sounds in linear PCM or IMA4 (IMA/ADPCM) format, packaged as a .caf, .aif, or .wav file.&nbsp;  AVAudioPlayer, on the other hand, supports the playback of any audio format available in the iPhone OS.&nbsp;  This is documented in the <a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AudioandVideoTechnologies/AudioandVideoTechnologies.html#//apple_ref/doc/uid/TP40007072-CH19-SW24" title="iPhone Application Programming Guide: Multimedia Support">iPhone Application Programming Guide: Multimedia Support</a></p>
<p><strong>Why not just stick with AVAudioPlayer?</strong> &mdash; AVAudioPlayer is fine, if you don&#8217;t need <a href="http://en.wikipedia.org/wiki/3D_audio_effect" title="Wikipedia:  3D Audio Effect">positional audio</a> and if you&#8217;re not worried about some <a href="http://www.blumtnwerx.com/blog/2009/05/adventures-in-sound-land/" title="Adventures in Sound Land">significant delays</a> in starting up each player.&nbsp;  This latter bit can be especially important if you&#8217;re trying to fire off sounds in a tight loop, or if you need to synchronize effects in a multi-threaded environment.</p>
<p><strong>What I you recommend?</strong> &mdash; Use <strong><em>SystemAudioServices</em></strong> if your sounds are short and available in the proper formats.&nbsp;  It&#8217;s by far the simplest player and, within its constraints, it pretty much handles everything for you.&nbsp;  Use <strong><em>AVAudioPlaye</em>r</strong> for operations like playing songs or recorded speech.&nbsp;  Unfortunately, Apple doesn&#8217;t sanction SoundEngine anymore, but I&#8217;ve become a big fan of using <strong><em>SoundEngine</em></strong> on top of <strong><em>OpenAL</em></strong> for games.&nbsp;  This combination hides some of the complexities of OpenAL while still giving you access to most of the standard stuff.&nbsp;  Also, it&#8217;s easy to <a href="http://www.blumtnwerx.com/blog/2009/05/adventures-in-sound-land/" title="Adventures in Sound Land">extend</a> SoundEngine to get at pretty much any OpenAL functionality you need.&nbsp;  We downloaded the source for SoundEngine from the <a href="http://oolongengine.com/" title="Oolong Game Engine">Oolong site</a>, but it might be a bit easier to grab it directly from <a href="http://code.google.com/p/cocos2d-iphone/source/browse/tags/release-0.2.1/AudioSupport/" title="cocos2d-iphone:  AudioSupport">coocos2d.</a></p>
<p>A final word.&nbsp;  With pretty much everything beyond SystemAudioServices, you&#8217;ll want to seriously consider managing the <strong><em>Audio Session</em></strong> yourself.&nbsp;  As always, Apple provides excellent <a href="http://developer.apple.com/iphone/library/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html" title="iPhone Reference Library:  Audio Session Programming Guide">documentation</a>.&nbsp;  Even Apple encourages you to take care of this detail:</p>
<blockquote><p><em>Each iPhone OS application gets an audio session object, usually called an audio session. This object comes with some default behavior that you can use to get started in development. Except for certain special cases, however, the default behavior is unsuitable for a shipping application.</em></p></blockquote>
<p>You don&#8217;t need to instantiate an AudioSession object.&nbsp;  The iPhone OS provides every app with a singleton AudioSession when the app launches.&nbsp;  However, you do have to initialize the AudioSession.&nbsp;  You may also need to set properties, and you&#8217;ll probably want to Activate/Deactivate the session.</p>
<p>Happy sounds!</p>
<p>&nbsp;  </p>
<p>&#8212;&#8212;&#8211;<br />
Technorati Tags:&nbsp; <a href="http://technorati.com/tag/iPhone" rel="tag">iPhone</a>, <a href="http://technorati.com/tag/iPod+Touch" rel="tag">iPod Touch</a>, <a href="http://technorati.com/tag/Apple" rel="tag">Apple</a>, <a href="http://technorati.com/tag/mobile" rel="tag">mobile</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.BluMtnWerx.com/blog/2009/06/playing-audio-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>But I Want to Play That Same Sound Again, Right Now</title>
		<link>http://www.BluMtnWerx.com/blog/2009/05/but-i-want-to-play-that-same-sound-again-right-now/</link>
		<comments>http://www.BluMtnWerx.com/blog/2009/05/but-i-want-to-play-that-same-sound-again-right-now/#comments</comments>
		<pubDate>Sat, 23 May 2009 05:01:23 +0000</pubDate>
		<dc:creator>deans</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[AudioSession]]></category>
		<category><![CDATA[AVAudioPlayer]]></category>
		<category><![CDATA[iPhone Dev Tools]]></category>
		<category><![CDATA[OpenAL]]></category>
		<category><![CDATA[SoundEngine]]></category>

		<guid isPermaLink="false">http://www.BluMtnWerx.com/blog/?p=132</guid>
		<description><![CDATA[One of the most interesting challenges that I ran into in our sound heavy application (still waiting App Store approval) was figuring out how to play a second, third, etc. instance of a sound while the original was still playing.]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in an <a href="http://www.blumtnwerx.com/blog/2009/05/adventures-in-sound-land/" title="Post:&nbsp;  Adventures in SoundLand">earlier post</a>, I&#8217;ve been dipping my toes into the deep waters of iPhone sound.&nbsp;  One of the challenges that I ran into recently involved figuring out the best way to play a sound again, while the previous instance of the same sound was still playing.&nbsp;  Although our current application features several (OK, sixteen) distinct sounds, the app often attempts to play a sound that is already playing.&nbsp;  With <code>AudioServicesPlaySystemSound</code> this just works.&nbsp;  The subsequent attempts to play a sound simply play right along.&nbsp;  Unfortunately, neither SoundEngine, nor AVAudioPlayer, work this way.&nbsp;  If you try to start a SoundEngine effect, or an AVAudioPlayer, again, while it is already playing, nothing happens.&nbsp;  It doesn&#8217;t queue; it just doesn&#8217;t play.</p>
<p>Before I go any further, I should share some of the details of the sounds for this app.&nbsp;  They are all relatively short (roughly 2 seconds, or less).&nbsp;  Their intensity peaks early, tapers quickly to a relatively low level, then trails off very gently for most of their duration.&nbsp;  Their time domain plot looks something like a question mark rotated -90 degrees, then mirrored across the x-axis.</p>
<p>Since, as <a href="http://www.blumtnwerx.com/blog/2009/05/adventures-in-sound-land/" title="Why I Could Not Use AudioServices">previously discussed</a>, I couldn&#8217;t use AudioServices, I had to figure out a way to make either SoundEngine/OpenAL, or AVAudioPlayer (which was later rejected for a different reason), work.&nbsp;  Some of my less embarrassing attempts to solve this included:</p>
<p>The first tactic that I tried was to simply stop the currently playing effect/player (for the sake of simplicity, I&#8217;ll just refer to both as <em>players</em> for the rest of this post) and start it again.&nbsp;  Unfortunately, this introduced a distinct, and very unpleasant, click when the stop/start happened.&nbsp;  If your app is a shooter, with lots of sharp explosions and weapon reports, this might not be a problem, but it was a showstopper for us.</p>
<p>The next thing that I tried was gradually reducing the volume of the current player before stopping it.&nbsp;  That didn&#8217;t help, much.</p>
<p>With AVAudioPlayer, I also tried just setting the player back to the beginning, instead of stopping it. <code>[myPlayer setCurrentTime:0.0]</code> &#8211; the results were actually worse than a stop/restart.</p>
<p>At that point, I decided to try a combination approach.&nbsp;  If the subsequent attempt to play came early in the original player&#8217;s span, I just skipped the later attempt.&nbsp;  If the attempt came well into the original, I gradually reduced the volume of the original, stopped it and then started the player again.&nbsp;  This was better, because there were fewer stop/starts, but it still wasn&#8217;t perfect.&nbsp;  Which leads us to the solution that I ended up implementing&#8230;</p>
<p>In the end, I went with a backup player technique.&nbsp;  I have two players set up to play each sound (I used players here to be consistent.&nbsp;  They&#8217;re really effects, since I&#8217;m using SoundEngine/OpenAL).&nbsp;  If the first one is busy, I use the second one.&nbsp;  If both are busy, I skip playing the sound.&nbsp;  I was all set to go even deeper, to three, or even four, players for each sound.&nbsp;  Fortunately, two gave good results, and the code was straightforward, so I stuck with a single level of backup.</p>
<p>I probably should have tried this first, but I was worried about both the memory and the execution overhead of having multiple players for each sound.&nbsp;  My concern was not warranted.&nbsp;  With the current implementation, the overhead is negligible, and the results are great.</p>
<p>&nbsp;  </p>
<p>&#8212;&#8212;&#8211;</p>
<p>Technorati Tags:&nbsp; <a href="http://technorati.com/tag/iPhone" rel="tag">iPhone</a>, <a href="http://technorati.com/tag/iPod+Touch" rel="tag">iPod Touch</a>, <a href="http://technorati.com/tag/Apple" rel="tag">Apple</a>, <a href="http://technorati.com/tag/mobile" rel="tag">mobile</a>, <a href="http://technorati.com/tag/SoundEngine" rel="tag">SoundEngine</a>, <a href="http://technorati.com/tag/AVAudio" rel="tag">AVAudio</a>, <a href="http://technorati.com/tag/AudioServices" rel="tag">AudioServices</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.BluMtnWerx.com/blog/2009/05/but-i-want-to-play-that-same-sound-again-right-now/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adventures in Sound Land</title>
		<link>http://www.BluMtnWerx.com/blog/2009/05/adventures-in-sound-land/</link>
		<comments>http://www.BluMtnWerx.com/blog/2009/05/adventures-in-sound-land/#comments</comments>
		<pubDate>Tue, 12 May 2009 01:18:33 +0000</pubDate>
		<dc:creator>deans</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[AudioSession]]></category>
		<category><![CDATA[AVAudioPlayer]]></category>
		<category><![CDATA[iPhone Dev Tools]]></category>
		<category><![CDATA[OpenAL]]></category>
		<category><![CDATA[SoundEngine]]></category>

		<guid isPermaLink="false">http://www.BluMtnWerx.com/blog/?p=117</guid>
		<description><![CDATA[Who would have imagined that getting the sound to work even close to the way that we wanted would be much harder than writing the app?&#160;  Maybe I can help you avoid some of the pitfalls.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new App for much longer than we&#8217;d budgeted.&nbsp;  The sad part is that the real coding has been complete for several days.&nbsp;  Instead of submitting this app and getting on with the next one, I&#8217;ve spent the time trying to iron out sound issues.&nbsp;  This isn&#8217;t a complicated app, but it does, on occasion, play multiple short (&lt;2 sec) sounds simultaneously.&nbsp;  The sounds are not complex, and I was initially hoping to skate by with the AudioServices system sounds.&nbsp;  I know that that&#8217;s not the recommended practice, but it was the easiest to code, so I started there.</p>
<p>The problem with that approach quickly became apparent.&nbsp;  There was a noticeable distortion when more than 2-3 sounds were playing at the same time.&nbsp;  The unpleasant effect was kind of a stuttering static, sort of like one might hear if one over-drives speakers.&nbsp;  This, unfortunately, pretty much ruined the effect of the app, so <a href="http://www.blumtnwerx.com/BMWTeam.html#Paul">Paul</a> suggested lowering the volume of the sounds.&nbsp;  Sadly, one can&#8217;t do that for an AudioServices system sound.</p>
<p>At that point, I switched the app over to using AVAudioPlayer.&nbsp;  This seemed like it was going to be a good solution, so I wrote a utility app to help me test the individual sound volume settings and spent quite a bit of time experimenting to find the &#8220;right&#8221; level for each possible combination of sounds.&nbsp;  I really thought that I was in the home stretch until I fired up the app and found that the motion went from butter smooth to unacceptably jerky.&nbsp;  Since actual playback of AVAudioPlayer is asynchronous with regards to the main thread, the last thing that I looked at (after wasting more time than I should have on optimization) was the actual call to [myAVAudioPlayer play].&nbsp;  Big mistake.</p>
<p>After eliminating everything else, I bracketed the [myAVAudioPlayer play] calls with a timer and was amazed to discover that the calls were taking 0.04 &#8211; 0.05 seconds, on the calling thread, just to get started.&nbsp;  After that, the player went along asynchronously, as expected.&nbsp;  Since my simulation loop was running in increments of 0.0167 seconds, having each call to [myAVAudioPlayer play] block for 3x that amount made for a very unhappy user experience.&nbsp;  My next thought was to bounce right to OpenAL, but I decided that the (apparently) no longer sanctioned <em>(at least it&#8217;s not available from Apple anymore)</em> SoundEngine might give me most of what I needed, without my having to worry about managing buffers and sources.  </p>
<p>Unfortunately, SoundEngine lacked some OpenAL functionality that I really needed (being able to find out if a given effect is currently playing and also to find out how far along the effect is).&nbsp;  I ended up implementing extensions to SoundEngine to get at the OpenAL stuff, and, so far, everything is working.&nbsp;  The most recent discovery was that the SoundEngine/OpenAL combination does not initialize and properly configure an AudioSession.&nbsp;   This means that our app stopped when the device went into Auto-Lock.&nbsp;  Not necessarily a good thing for a &#8220;lifestyle&#8221; app.&nbsp;  Once I took care of that, I&#8217;m back to calibrating the sound levels and doing more testing on the functionality.&nbsp;  I constantly have my fingers crossed that I don&#8217;t encounter any more problems that will force me to abandon the extended SoundEngine.</p>
<p>I may do a longer post on the perils of using compressed audio formats in the future, but let&#8217;s wrap this bit up with a warning.&nbsp;  While compression can really help with your download times, you may want to be careful about choosing when to employ compressed formats.&nbsp;  There are a couple of reasons for this.&nbsp;  First, some of the iPhone SDK playback options support only a limited subset of the compressed formats.&nbsp;  Second, the device won&#8217;t play the highly compressed formats simultaneously.&nbsp;  If you plan to play multiple sounds at the same time, highly compressed formats might not be an option.</p>
<p>Most of the points covered here are well documented in the <a href="http://developer.apple.com/iphone/library/referencelibrary/GettingStarted/GS_AudioVideo_iPhone/index.html" title="iPhone Developer Connection Document">Getting Started with Audio &amp; Video</a> document.&nbsp;  If I&#8217;d had the discipline to read the whole thing before I started down this path, the trip would have been much less frustrating.</p>
<p>Technorati Tags:&nbsp; <a href="http://technorati.com/tag/iPhone" rel="tag">iPhone</a>, <a href="http://technorati.com/tag/iPod+Touch" rel="tag">iPod Touch</a>, <a href="http://technorati.com/tag/Apple" rel="tag">Apple</a>, <a href="http://technorati.com/tag/mobile" rel="tag">mobile</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.BluMtnWerx.com/blog/2009/05/adventures-in-sound-land/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
