I've got an AUGraph demo with three units (AURemoteIO bus 1, AUSampler, and AUFilePlayer) going into a mixer and then through a chain of effects before going to the AURemoteIO bus 0 for output to h/w.
A UISwitch lets you set the kAudioUnitProperty_BypassEffect on the effect units.
All the effects default to non-bypass (ie, the effect is active). When I bypass the effect, I stop hearing the distortion or whatever, and that's great. But when I set kAudioUnitProperty_BypassEffect back to 0, the effect stops processing sound and the app goes quiet. And when I bypass again, the sound goes through (w/out the effect, naturally). So what I have is an effect that works so long as I never bypass it.
In other words, by state, with just the distortion effect: 0 (default): Switch ON, bypass off, sound distorted 1: Switch OFF, bypass on, sound non-distorted 2: Switch ON, bypass off, no sound 3: Switch OFF, bypass on, sound non-distorted [repeat states 2 and 3]
Is there some other cleanup I have to do after setting BypassEffect? Trying AudioUnitReset didn't do anything.
Here's the relevant code:
-(IBAction)handleEffectEnabledSwitchValueChange:(id)sender { UInt32 bypassed = self.effectEnabledSwitch.on ? 0 : 1; NSLog (@"setting bypassed to %ld", bypassed); CheckError(AudioUnitSetProperty (self.audioUnit, kAudioUnitProperty_BypassEffect, kAudioUnitScope_Global, 0, &bypassed, sizeof(bypassed)), "Couldn't set bypassed status"); // does noting // CheckError(AudioUnitReset(self.audioUnit, kAudioUnitScope_Global, 0), // "Couldn't reset audio unit"); }
("CheckError" is the same function as in the Core Audio book: check the return against noErr, pretty print and exit if there's an error)
I can put my project on my Dropbox if anyone wants to look… this is for my Core Audio talk at VTM:iOS next weekend in Boston, so I'll eventually be putting the finished version there in any case (i.e., don't ask me to post the buggy version now just because you don't think you'll never get it otherwise)
--Chris
|