<?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>voyce &#187; caf</title>
	<atom:link href="http://www.voyce.com/index.php/tag/caf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Wed, 11 Aug 2010 03:56:45 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sound formats for iPhone development</title>
		<link>http://www.voyce.com/index.php/2009/01/06/sound-formats-for-iphone-development/</link>
		<comments>http://www.voyce.com/index.php/2009/01/06/sound-formats-for-iphone-development/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 23:10:48 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[caf]]></category>
		<category><![CDATA[endian]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[libsndfile]]></category>
		<category><![CDATA[wav]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=58</guid>
		<description><![CDATA[Ahh, back to work today. It&#8217;s pretty tough getting back into the swing of things after what turned out to be a long break this year. While I was off I finally got to spend some time working on an iPhone game. After getting hold of the SDK a while back, it&#8217;s only now that [...]]]></description>
			<content:encoded><![CDATA[<p>Ahh, back to work today. It&#8217;s pretty tough getting back into the swing of things after what turned out to be a long break this year. While I was off I finally got to spend some time working on an iPhone game. After getting hold of the SDK a while back, it&#8217;s only now that I&#8217;ve gotten around to doing something with it.</p>
<p>One of the things that seemed a little odd about the SDK is it&#8217;s use of CAF-format audio files, detailed <a href="http://developer.apple.com/documentation/MusicAudio/Reference/CAFSpec/CAF_intro/chapter_1_section_1.html">here</a>. I got hold of a few very nice audio samples from the <a href="http://www.freesound.org">freesound</a> site, but needed to convert them from WAVs to CAFs.</p>
<p>I thought ffmpeg might be up to the job, but the version I had didn&#8217;t list it as an avaliable output format using <code>ffmpeg -formats</code>. However after a bit of digging I discovered that it is supported by <a href="http://www.mega-nerd.com/libsndfile/">libsndfile</a>, so set about installing it using <a href="http://www.macports.org">MacPorts</a>:</p>
<blockquote><p><code>sudo port install libsndfile</code></p></blockquote>
<p>Then I used the included libsndfile-convert app to convert my file:</p>
<blockquote><p><code>libsndfile-convert file.wav file.caf</code></p></blockquote>
<p>The output format is inferred from the file extension, so you don&#8217;t have to specify it. However, when I rebuilt and ran my iPhone app using the new file, it didn&#8217;t play back. I suspected there may be something wrong with the format of the file, so I took a look to see what <a href="http://en.wikipedia.org/wiki/File_(Unix)">file</a> reported. For the original WAV file I got</p>
<blockquote><p><code>file.wav: RIFF <strong>(little-endian)</strong> data, WAVE audio, Microsoft PCM, 16 bit, mono 44100 Hz</code></p></blockquote>
<p>Unfortunately file doesn&#8217;t work on .CAF files, but you can open them using QuickTime Player, and using the Movie Inspector window you can see that the file has the following format:</p>
<blockquote><p><code>16-bit Integer <strong>(Big Endian)</strong>, Mono, 44.100 kHz</code></p></blockquote>
<p>So it looks like the problem may be libsndfile-convert changing the endian-ness of the file contents, from the x86-style little-endian to Motorola-ish (i.e. pre-x86 Mac) big-endian, which is a bit of a pain. According to the docs, the libsndfile API supports endian-ness manipulation, so it&#8217;s probably just the case that the helper app is doing the wrong thing automatically. I&#8217;ll look at putting together a small command line app to use the API directly and enable me to batch process .WAV files correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/01/06/sound-formats-for-iphone-development/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
