<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" 
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
	<channel>
<title>blog &#x7c; MacNeil</title><link>http://kennyswebsite.org/blogMacNeil/index.html</link><description>Kenny Smith&#x27;s blog.  Mostly iPhone software developer stuff.</description><dc:language>en</dc:language><dc:creator>kenny@theapporchard.com</dc:creator><dc:rights>Copyright 2009 Kenny Smith</dc:rights><dc:date>2009-07-29T08:56:37-05:00</dc:date><admin:generatorAgent rdf:resource="http://www.realmacsoftware.com/" />
<admin:errorReportsTo rdf:resource="mailto:kenny@theapporchard.com" /><sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
<lastBuildDate>Sat, 08 Aug 2009 22:00:16 -0500</lastBuildDate><item><title>Welcome to the blog MacNeil</title><dc:creator>kenny@theapporchard.com</dc:creator><category>First Post</category><dc:date>2009-07-30T16:23:13-05:00</dc:date><link>http://kennyswebsite.org/blogMacNeil/files/hello_and_welcome.html#unique-entry-id-1</link><guid isPermaLink="true">http://kennyswebsite.org/blogMacNeil/files/hello_and_welcome.html#unique-entry-id-1</guid><content:encoded><![CDATA[<div class="image-right"><a href="http://kennyswebsite.org" rel="self" title="Kenny says, &#34;Aloha amigo!&#34;"><img class="imageStyle" alt="Kenny in San Juan, PR, Nov. 2005" src="http://kennyswebsite.org/blogMacNeil/files/me-in-san-juan-2.png" width="171" height="200"/></a></div>Hello and welcome to my first ever blog -- the blog MacNeil.  If you'd like to learn more about me, here are links to my <a href="http://theapporchard.com" rel="self" title="The App Orchard">tiny company</a>, <a href="http://kennyswebsite.org" rel="self" title="kennyswebsite.org">personal website</a>, <a href="http://www.linkedin.com/pub/b/314/353" rel="self" title="http://www.linkedin.com/pub/b/314/353">LinkedIn page</a>, and <a href="http://theapporchard.com/kenny/resume/" rel="self" title="Résumé of Kenny Smith">r&eacute;sum&eacute;</a>.<br /><br />The blog's name comes from my distant ancestors who were members of the <a href="http://en.wikipedia.org/wiki/Clan_MacNeil" rel="self">Clan MacNeil</a>,  from the <a href="http://maps.google.com/maps?q=56.979228,-7.46521&sll=56.490671,-4.202646&sspn=6.573956,16.391602&hl=en&ie=UTF8&ll=56.973427,-7.47345&spn=0.176829,0.364952&z=12&iwloc=near" rel="self" title="Island of Barra - Google Maps">island of Barra</a> off the western coast of Scotland.  I have yet to visit Scotland, but my <a href="http://theapporchard.com/meg" rel="self" title="Meg&#39;s blog - A day in the country">lovely wife Meg</a> and I are saving our pennies and hoping to travel there soon.<br /><br />To start out, this blog will be a place for me to share programming experience and code with the iPhone developer community.  There have been many occasions when a useful piece of information in someone's blog helped get me over a programming hurdle.  Now that I have one iPhone app under my belt and I'm well into app number two, I have some code and insights of my own to give back.  So, my first few posts will be resuable code and tips for iPhone developers.  From there, I'm not sure where I'll take it.  Maybe some music chatter?  I don't have a drop of musical ability, but I inherited a great of love of music from my dad, who has the largest collection of LP's (and CD's) of anyone I've met.  Ever.  We're talking more music than your typical public library.<br /><br />Now that I've brought up music, there <em>is</em> something that's been on my mind.  It's a music history "what if."  I've been wondering how history would have unfolded if David Byrne and Billy Joel had crossed paths in a New York bar during their formative years?  What if they had hit it off and started a band?<br /><br />Have you ever heard someone say, "They could be the next Beatles."  It's generous praise to be sure, though it also seems like the kiss of death for a band when music critics start putting it in print.  Squeeze and Oasis come to mind.  Those bands were doing fine until they got saddled with the "next Beatles" moniker.  This got me wondering whether the whole idea of "the next Beatles" is a false premise.  Maybe there can be no such thing?  But then... what about the Police? (Similar to the Beatles, especially with the evolution/reinvention thing, but too quick to self-desctruct.)  What about U2?  (More like the Stones, hot and cold and built to last.)  So I've been thinking about the individual musical styles of John Lennon and Paul McCartney and the chemistry that took place between them.  Song credits on Beatles albums always say, "Lennon/McCartney," but it's not hard to tell which songs are Paul's (Hey Jude), which are John's (Across The Universe), and which bounce back and forth between the two of them (Happiness Is A Warm Gun or A Day In The Life).  When I listen to their solo work and think about how it relates it to the music they made together, it all gets so dang fascinating that Meg ends up grabbing my shoulders and yelling, "Snap out of it dude!"  <br /><br />So what's the point?  I guess it's just this.  The solo work of David Byrne, Billy Joel, John Lennon, and Paul McCartney has some distinct parallels.  A couple Brits and a couple Americans an ocean and almost a decade apart, but with the same basic chemistry.  Try imagining a music history in which the Beatles never happened -- just solo Lennon and solo McCartney.  Or better yet, imagine that you could sit a 21 year-old Billy Joel next to an 18-year old David Byrne sometime in the early Seventies, shortly after the Beatles broke up.  Just try not to say something dumb like, "You guys could be the next Beatles."<br /><br />But enough with the hypothetical hogwash.  Music is for later.  First it's all about code, gadgets and geekery.<br /><br />So... welcome again to the blog MacNeil.  If you find anything useful, or have any thoughts, suggestions or whatever, please post a comment!  I'd love to hear from you.]]></content:encoded></item><item><title>ShortSoundPlayer:  A simple&#x2c; short sound player class</title><dc:creator>kenny@theapporchard.com</dc:creator><category>Geekery</category><dc:date>2009-07-31T16:23:06-05:00</dc:date><link>http://kennyswebsite.org/blogMacNeil/files/short_sound_player.html#unique-entry-id-0</link><guid isPermaLink="true">http://kennyswebsite.org/blogMacNeil/files/short_sound_player.html#unique-entry-id-0</guid><content:encoded><![CDATA[<div class="image-right"><a href="http://theapporchard.com/bonmot/" rel="self"><img class="imageStyle" alt="bonmot_screenshot" src="http://kennyswebsite.org/blogMacNeil/files/bonmot_screenshot.png" width="362" height="252"/></a></div>My first iPhone app, <a href="http://theapporchard.com/bonmot" rel="self">Bon Mot!</a>, was the result of a collaboration with <a href="http://www.cochranaudio.com" rel="self" title="Cochran Audio - Bill&#39;s company">Bill Cochran</a>.  Bill came up with the idea for the game, recorded the audio and created the graphics with a little help from his son, Ian, who created the sky background.  Having a collaborator was great because it let me focus exclusively on programming the app.  Well, maybe not exclusively.  There was also starting <a href="http://theapporchard.com/about.html" rel="self" title="The App Orchard">a company</a>.  And building its <a href="http://theapporchard.com" rel="self" title="theapporchard.com">web site</a>.  Still, it would have been a long haul without Bill's help.  Thanks hombre!<br /><br />Like most games, Bon Mot has a bunch of sound effects that augment the game play.  Initally we considered having ambient background sounds, but we ditched that idea early on, figuring most people would rather listen to their own music while they play.  <br /><br />Without the need for continuous background audio in Bon Mot, I "simply" needed to play a bunch of short sound clips, all of them 30 seconds or less.  Additionally I wanted to let our users turn down the volume of the game's sounds so they could better hear their music.  If you're wondering why I put "simply" in quotes, well... you'll see.<br /><br />The first stop in my hunt for audio code was Apple's <strong>Metronome</strong> sample.  Metronome is a beautiful little app that behaves just like an old-school, mechanical metronome with a swinging, weighted arm.  At that time, Metronome used Apple's <strong>System Sound Services</strong> to play its "tick" and "tock" sounds (Note: since the release of iPhone OS 3.0, Metronome has been updated to use AVAudioPlayer instead).  Although Apple's documentation warns against using System Sound Services to play things like game sounds, I couldn't help notice that Apple's engineers were doing this very thing in Metronome.  More importantly, it was clear that System Sound Services was by far the simplest audio API for the iPhone.  I love simple.<br /><br /><div class="image-left"><img class="imageStyle" alt="metronome" src="http://kennyswebsite.org/blogMacNeil/files/metronome.png" width="168" height="250"/></div>It was a snap to get Bon Mot's sound clips playing with System Sound Services.  There was just one hitch.  SSS offered no control over the output volume of the sounds it played.  I was determined to let our users turn down the game sounds so they could better hear their music.  Apart from the volume issue though, my task appeared to be complete in less than a day of work.  Sweet!  I decided to ignore the volume thing for the time being.  Sometimes these things have a way of fixing themselves.<br /><br />Weeks passed with no magic fix.  We sent out our first beta version to everyone we knew with an iPhone.  The app was feature complete with one exception.  The "Quiet" setting for Bon Mot's <a href="http://theapporchard.com/bonmot/details.html#prefs" rel="self">Game Sounds preference</a> needed to be implemented and System Sound Services, while performing perfectly in every other way, refused to let me turn down the volume.  Ignoring the problem hadn't fixed it and it was time for me to come up with a Plan B.<br /><br />Plan B was Apple's promising, new (at the time) <strong>AVAudioPlayer</strong> class.  Without laboring the details, AVAudioPlayer turned out to be a major headache.  My understanding is that the iPhone OS 3.0 version of AVAudioPlayer is much improved.  However, if you need to target iPhone OS 2.x or earlier, then I recommend you avoid AVAudioPlayer.  I wasted a solid day or two trying to get it to work reliably, and I'm reasonably certain that the problems lay within AVAudioPlayer, not in my use of it.  A bit of Googling confirmed that before iPhone OS 3.0, AVAudioPlayer was long on promise and short on delivery.  Time to find a Plan C.<br /><br />Plan C was Apple's mature but complicated <strong>Audio Queue Services</strong> API.  I hate complicated.  I had been avoiding Audio Queue Services because I could see the complexity oozing from its pores.  But AQS had been around.  Lots of code had been built upon it.  It was no newcomer like AVAudioPlayer and was clearly up to the task of playing my sounds, letting me control the volume, and a ton of other stuff I didn't need.<br /><br />I took a deep breath, rolled up my sleeves and dove into AQS with the goal of creating a super simple wrapper around it so the rest of my code would never need to know the gnarlyness that lay within.  What I came up with is <strong>ShortSoundPlayer</strong>, a class that lets you play sounds that are <em>small enough to fit entirely in RAM</em>.  This last bit is important.  ShortSoundPlayer is not meant for playing long sounds that must be buffered a piece at a time.  However, if all you need to play is short sound clips (say, 30 seconds or less), then ShortSoundPlayer is worth a look.  It's simple.  And you can control the dang volume!<br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%">@interface ShortSoundPlayer : NSObject<br />{<br />	NSString* _fileName;<br />	NSString* _filePath;<br />	float	  _volume;<br />	bool	  _isPlaying;<br />	<br />	AudioQueueRef		_queue;<br />	AudioQueueBufferRef	_buffer;<br />}<br /><br />@property (nonatomic, readonly) NSString*	fileName;<br />@property (nonatomic, readonly) NSString*	filePath;<br />@property (nonatomic, assign)	float		volume; <span style="color:#AC00AF;">// 0.0 = silent, 1.0 = max volume.</span><br />@property (assign)		bool		isPlaying;<br /><br />- (id) initWithContentsOfFile: (NSString*) path;<br /><br />- (BOOL) prepareToPlay;		<span style="color:#AC00AF;">// Optional.  Happens automatically on play.  YES = success.</span><br />- (BOOL) play;			<span style="color:#AC00AF;">// Sound is played asynchronously.  YES = success.</span><br />@end</pre>Instead of getting long winded describing the implementation, I'll just zip it up and post it here:  <a href="http://theapporchard.com/downloads/ShortSoundPlayer.zip" rel="self">ShortSoundPlayer.zip</a>.  Hopefully you'll find that the code speaks for itself.  If not, post a comment and let me know.<br /><br />There is one little caveat to be aware of.  I routinely blend Objective-C and C++ in my code, which has led me to use the .mm extension for all of my source files.  If you prefer to avoid C++, then you may want to rename ShortSoundPlayer.mm to be ShortSoundPlayer.m before adding it to your Xcode project.  This because this particular class doesn't use C++.<br /><br />If you find any bugs, or make improvements to ShortSoundPlayer... please, Please, PLEASE post a comment and let me know! ]]></content:encoded></item></channel>
</rss>
