file unit callback shows stereo channels in buffer, but the file loaded was 6 channel

I want to generate a sample withAudioFilePlayerUnit to play 6 channel audio file. The issue here is that, the AudioFilePlayerUnit callback shows stereo channel in buffer, but the file loaded to the fileUnit was of 6 channels. I have tried setting the input and output format for the fileUnit to that of file's stream format(6 channels), but still the callback shows stereo channels in buffer. I have added my code snippet below.

OSStatus error = AudioFileOpenURL(audioFileURL, kAudioFileReadPermission, 0, &_audioInputFileId);

UInt32 dataSize = sizeof(AudioStreamBasicDescription); AudioFileGetProperty(_audioInputFileId, kAudioFilePropertyDataFormat, &dataSize, &_fileStreamDescription);

setting the input and outputFormat for the unit : UInt32 propertySize = sizeof(_fileStreamDescription);

AudioUnitScope scope = kAudioUnitScope_Input; OSStatus err = AudioUnitSetProperty(filePlayerUnit, kAudioUnitProperty_StreamFormat, scope, 0, &_fileStreamDescription, propertySize);

OSStatus err = AudioUnitSetProperty(filePlayerUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &_fileStreamDescription, propertySize);

here setting the input and output format also throws error.

I have added the callback using AudioUnitRenderNotify method to the fileUnit but when check the buffer in the callback I can see it returning as stereo channels.

We are trying to play an 5.1 (6 channels) AAC audio file using AUGraph. We also tried using AVAudioEngine. We have connected to 5.1 surround sound output device (Sony Speakers). The file is played as stereo file. All the channels are played in Left and Right front speakers.

  • we are setting the file’s AudioStreamBasicDescription (which is 6 channels) to the file unit.(as shown in the above post)
  • we registered for render callback for file unit. It shows number of buffers as 2 and each buffer has 1 channel, indicates stereo data.
AudioUnitAddRenderNotify(filePlayerUnit, fileUnitRenderCallback, (__bridge void*)self);
static OSStatus fileUnitRenderCallback(void *  inRefCon,AudioUnitRenderActionFlags * ioActionFlags, const AudioTimeStamp *inTimeStamp,UInt32 inBusNumber, UInt32  inNumberFrames, AudioBufferList *ioData){}
  • we registered for render callback for output unit. It shows number of buffers as 1 and each buffer has 2 channel. Indicates stereo data.
AudioUnitAddRenderNotify(outputUnit, outputUnitRenderCallback, (__bridge void*)self);
static OSStatus outputUnitRenderCallback(void *  inRefCon,AudioUnitRenderActionFlags * ioActionFlags, const AudioTimeStamp *inTimeStamp,UInt32 inBusNumber, UInt32  inNumberFrames, AudioBufferList *ioData){}
  • We will not be able to use Apple’s built-in players like AVPlayer. Because, we need to connect some of the audio units to apply Audio-Effects.

Could you please suggest on how we can achieve 5.1 playback support.

file unit callback shows stereo channels in buffer, but the file loaded was 6 channel
 
 
Q