Losing sight of land

On a few of my books, most notably QuickTime for Java: A Developer’s Notebook, I reached a point where I’d google for background knowledge, alternative opinions, or just help on some API and only find stuff I’d written and posted myself, or find nothing at all.

On one hand, it’s bad news, because it means I have to tough it out myself. On the other hand, it also means that the book is going to be able to deliver real value, since it’s going to offer knowledge that isn’t already readily available. The worst kind of books are the ones that just rehash official documentation; material like that is as miserable to write as it is useless to buy and read.

Anyways, in this case, the query in question (ooh, avoid awkward alliteration always…) is the constant kAudioFileGlobalInfo_AvailableStreamDescriptionsForFormat, which appears to have 200 Google hits, but actually only has about two pages and a total of 16 hits once all the duplicates of posts to coreaudio-api are removed.

And what is this constant for? There’s an interesting function in Audio File Services, AudioFileGetGlobalInfo(), that instead of dealing with a specific file, returns properties of Core Audio’s file handling in general. You can use it to figure out what filename extensions, MIME types, and HFS type codes go with various formats. In chapter 3, after discussing container formats, audio data formats, and the AudioStreamBasicDescription, we can use the kAudioFileGlobalInfo_AvailableStreamDescriptionsForFormat property to make some discoveries about CA-supported formats. Quoting from the property’s documentation:

Returns an array of audio stream basic description structures, which contain all the formats for a particular file type and format ID. The audio stream basic description structures have the following fields filled in: mFormatID, mFormatFlags, and mBitsPerChannel for writing new files.

In other words, we pass in a AudioFileTypeAndFormatID struct, setting the mFileType to kAudioFileAIFFType and the mFormatID to kAudioFormatLinearPCM and it will pass back ASBDs that tell us some interesting things about the limits of AIFF files: that they can’t handle more than 32 bits per sample, and that they only support big-endian integer samples. Change the mFileType to kAudioFileCAFType and you’ll find you have a lot more freedom (because you can put audio in pretty much any CA-supported format into a CAF file).

The Core Audio book can’t help but be hard; it’s the nature of the source material. But I think we’re doing pretty well in the intro chapters to demystify the core concepts and provide the tools for finding your way around the many APIs.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.