alexbw / novocaine

Painless high-performance audio on iOS and Mac OS X
http://alexbw.github.com/novocaine/
MIT License
2.23k stars 274 forks source link

On the fly channel mapping for readers and writers #11

Closed alexbw closed 10 years ago

alexbw commented 12 years ago

Should be able to automatically (using channel maps) change the channel count of audio coming or going to a file.

Did this at one point, a long time ago. It looked roughly like this:

// If there's only single-channel input, set up a channel map to record to both channels
if (self.numChannels == 1) {
    // Get the underlying AudioConverterRef
    UInt32 size = sizeof(AudioConverterRef);
    AudioConverterRef conv = NULL;
    XThrowIfError( ExtAudioFileGetProperty(outputFileRef, kExtAudioFileProperty_AudioConverter, &size, &conv), "Could not get underlying converter for ExtAudioFile");
    if (conv)
    {
        // This should be as large as the number of output channels,
        // each element specifies which input channel's data is routed to that output channel
        SInt32 channelMap[] = { 0, 0 };
        XThrowIfError( AudioConverterSetProperty(conv, kAudioConverterChannelMap, 2*sizeof(SInt32), channelMap), "Could not set up mono->stereo channel map");
    }
}
alexbw commented 10 years ago

I once was ambitious