How to use an AU3DMixer with The Amazing Audio Engine?
I am using the (indeed!) Amazing Audio Engine to play some tracks (with an AUFilePlayer
, each in a separate AEAudioChannel
), which works quite nicely.
Now, I would like to add the 3D Mixer Audio Unit kAudioUnitSubType_AU3DMixerEmbedded
, but after searching high and low, I can't find any information about how this could be done.
I have also a basic understanding of how the 3D mixer should work and followed all examples I could find, eg Apple's TN2112
Here's how I'm trying to add the 3D Mixer to a channel:
- (BOOL)add3DMixerToTrack:(NSURL*)track {
NSError *err;
AudioComponentDescription spatialMixerDescription = AEAudioComponentDescriptionMake(kAudioUnitManufacturer_Apple, kAudioUnitType_Mixer, kAudioUnitSubType_AU3DMixerEmbedded);
AEAudioUnitFilter *mixer = [[AEAudioUnitFilter alloc]
initWithComponentDescription:spatialMixerDescription
audioController:self.audioController
useDefaultInputFormat:YES
error:&err];
AudioUnitSetParameter(mixer.audioUnit, k3DMixerParam_Azimuth, kAudioUnitScope_Input, 1, 90, 0);
AudioUnitSetParameter(mixer.audioUnit, k3DMixerParam_Distance, kAudioUnitScope_Input, 1, 10, 0);
AEAudioUnitChannel *channel = [self getChannelForTrack:track];
if(channel) {
if(![self.audioController.channels containsObject:channel]) {
[self.audioController addChannels:@[channel]];
}
[self.audioController addFilter:mixer toChannel:channel];
return YES;
} else {
return NO;
}
}
The audio is playing (so I assume everything is set up okay-ish). However, none of the parameters seem to do something. An azimuth of 90° and a distance of 10 m should definitely result in a panned output.
After fiddling around a couple of more unproductive hours, I decided to completely move over to just using AudioUnits and getting rid of the Amazing Audio Engine (with the nice side effect that my whole project also got smaller and easier to handle).
It turned out to be not that complicated: connecting a couple of AudioUnits in an AUGraph
is pretty straightforward, when you look at it from the AUGraph API perspective (no rendering buffer handlers and such).
It's basically as easy as:
AUGraph
AUNodes
in this graph (all AudioUnits): These links and documents were very helpful (in this order):