I am currently in the middle of reproducing the Handling Multichannel Audio example of Session 507 at WWDC15. I created a 6 channel wav file and tried to play it with my 6 channel audio output hardware (HDMI connected to a 5.1 AV receiver). Quicktime Player can play the 6 channel wav file without any problems. So, I created the following test case:
- (void) play
{
self.audioEngine = [[AVAudioEngine alloc] init];
AVAudioOutputNode* outputNode = self.audioEngine.outputNode;
AVAudioFormat* outputHWFormat = [outputNode outputFormatForBus:0];
AVAudioChannelLayout* hwChannelLayout = outputHWFormat.channelLayout;
AudioChannelLayout* hwLayout = hwChannelLayout.layout;
AudioChannelLayoutTag hwLayoutTag = hwChannelLayout.layoutTag;
AudioStreamBasicDescription* hwStreamDescription = outputHWFormat.streamDescription;
AVAudioChannelCount hwChannelCount = hwChannelLayout.channelCount;
AVAudioMixerNode* mainMixer = self.audioEngine.mainMixerNode;
mainMixer.outputVolume = 1;
[self.audioEngine connect:mainMixer to:outputNode format:outputHWFormat];
NSURL* url = [[NSBundle mainBundle] URLForResource:@"seg01" withExtension:@"wav"];
NSError* error = nil;
AVAudioFile* audioFile = [[AVAudioFile alloc] initForReading:url error:&error];
AVAudioFormat* fileAudioFormat = audioFile.processingFormat;
AVAudioChannelLayout* fileChannelLayout = fileAudioFormat.channelLayout;
AudioChannelLayout* fileLayout = fileChannelLayout.layout;
AudioChannelLayoutTag fileLayoutTag = fileChannelLayout.layoutTag;
AudioStreamBasicDescription* fileStreamDescription = fileAudioFormat.streamDescription;
AVAudioChannelCount fileChannelCount = fileChannelLayout.channelCount;
AVAudioPlayerNode* player = [[AVAudioPlayerNode alloc] init];
player.volume = 1;
player.pan = 0;
[self.audioEngine attachNode:player];
[self.audioEngine connect:player to:mainMixer format:fileAudioFormat];
error = nil;
[self.audioEngine startAndReturnError:&error];
}
Upon startAndReturnError: in line 37, I get the following error logged into the console:
required condition is false: nil != channelLayout && channelLayout.channelCount == asbd.mChannelsPerFrame
I checked everything, but I can't find the problem myself.
fileChannelCount == 6 and hwChannelCount == 6
fileStreamDescription->mChannelsPerFrame == 6 and hwStreamDescription->mChannelsPerFrame == 6
Actually fileStreamDescription and hwStreamDescription have the same values in all fields.
Now, ChannelLayout is a bit different. The hwLayout contains 6 AudioChannelDescriptions and a channelTag of 0 and fileLayout contains 1 AudioChannelDescription and fileLayoutTag is kAudioChannelLayoutTag_MPEG_5_1_A, but I don't know if that's the problem. Does anybody have an idea?