Handling Multichannel Audio

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?

Answered by theanalogkid in 28184022

Looks like a legitimate issue that's scheduled to be fixed in a future release - you will most likely see the bug come back to you to verify on a specific seed when appropriate. Please do so and let us know if it's fixed or still busted. Thanks for filing the issue, most helpful!

Could you file a bug report with your test case so we can take a look. Please include information that indicates which version(s) of iOS / OSX you're using to reproduce this error. We didn't see that information in your post and Core Audio engineering have fixed some issues in this area recently.


Regarding the example code snippet itself, the file is not actually scheduled on the player, so this will result in the playback of silence. However, this is independent of your original error/exception.

Will do that. Yes, I did not schedule the file yet, because of the exception. I used the same file and played it with AVPlayer on the same 6 channel audio device, which works just fine.


rdar://21832375

Accepted Answer

Looks like a legitimate issue that's scheduled to be fixed in a future release - you will most likely see the bug come back to you to verify on a specific seed when appropriate. Please do so and let us know if it's fixed or still busted. Thanks for filing the issue, most helpful!

Awesome. Thanks.

iOS 9.1 and tvOS 9 have just been released. I still can't seem to make an AVAudioFormat of more than 2 channels. Is there a workaround? I'd like to do some audio processing on tvOS and pump it out via 5.1 audio systems attached to the AppleTV.

Handling Multichannel Audio
 
 
Q