Multi-Channel Audio
Delivering forty channel audio using QuickTime APIs to adjust movie files.
A little while ago, Oliver (Watershed's ICT Co-ordinator) , asked me to write a small command line tool to set the audio output channels of a QuickTime movie. Oliver was writing software for Dream Director, a project that plays audio to people sleeping in pods in response to rapid eye movement.
A Mac mini plays back the audio to up to twenty pods (containing sleeping people) through a collection of M-Audio Firewire410 boxes. As the audio-out hardware units have been aggregated into a single virtual device with forty available channels, it was just a case of playing back a stereo file through a selected pair of channels.
QuickTime movies will save the audio channel mapping inside the file, so the requirement was to build a tool that would set the selected channels in a movie and save the file to disk. The source listing is for a Cocoa command-line Tool, using QTKit, to open an audio file, set the track mapping and save as a QuickTime movie.
QuickTime now uses Core Audio to handle the audio channel mapping and I thought this may be of some use to people. The partial listing below shows the code needed to map audio channels using QuickTime and a link to the source file of the tool is below the listing. Sorry about the wrapped source listing.
Movie qtMovie = [movie quickTimeMovie];Track audioTrack = GetMovieIndTrack(qtMovie,1);AudioChannelLayout* trackChannelLayout = NULL;OSStatus err = noErr;UInt32 trackChannelLayoutSize;// Allocate a layout of the required sizetrackChannelLayoutSize = fieldOffset(AudioChannelLayout, mChannelDescriptions[2]);trackChannelLayout = (AudioChannelLayout*)calloc(1, trackChannelLayoutSize);trackChannelLayout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;trackChannelLayout->mNumberChannelDescriptions = 2;// Adjust the channel Assignment so that for an index we get a pair of channel// allocations. The index starts at 1// index channelA channelB// -----------------------------// 1 discreet0 discreet1// 2 discreet2 discreet3// 3 discreet4 discreet5// 4 discreet6 discreet7// ... and so onchannelAssignment = (channelAssignment-1)*2;#warning This will break if Apple change the CoreAudio's Channel Layout internalstrackChannelLayout->mChannelDescriptions[0].mChannelLabel = (1L<<16) | channelAssignment;trackChannelLayout->mChannelDescriptions[1].mChannelLabel = (1L<<16) | (channelAssignment + 1);// Set the track layouterr = QTSetTrackProperty(audioTrack, kQTPropertyClass_Audio, kQTAudioPropertyID_ChannelLayout, trackChannelLayoutSize, trackChannelLayout);if (err != noErr) {NSLog(@"**Error** QuickTime SetPropertyError: %i", err);return 1;}
Download the full source code.