public AUv3FilterDemo(AudioComponentDescription description, AudioComponentInstantiationOptions options, out NSError error) : base(description, options, out error) { var defaultFormat = new AVAudioFormat(44100.0, 2); Kernel.Init((int)defaultFormat.ChannelCount, defaultFormat.SampleRate); AUParameter cutoffParam = AUParameterTree.CreateParameter( "cutoff", "Cutoff", 0, 12, 2000, AudioUnitParameterUnit.Hertz, null, 0, null, null ); AUParameter resonanceParam = AUParameterTree.CreateParameter( "resonance", "Resonance", 1, -20, 20, AudioUnitParameterUnit.Decibels, null, 0, null, null ); cutoffParam.Value = 400f; resonanceParam.Value = -5.0f; Kernel.SetParameter((ulong)FilterParam.Cutoff, cutoffParam.Value); Kernel.SetParameter((ulong)FilterParam.Resonance, resonanceParam.Value); ParameterTree = AUParameterTree.CreateTree( new [] { cutoffParam, resonanceParam } ); inputBus.Init(defaultFormat, 8); NSError err; outputBus = new AUAudioUnitBus(defaultFormat, out err); inputBusArray = new AUAudioUnitBusArray(this, AUAudioUnitBusType.Input, new [] { inputBus.Bus }); outputBusArray = new AUAudioUnitBusArray(this, AUAudioUnitBusType.Output, new [] { outputBus }); var filterKernel = Kernel; ParameterTree.ImplementorValueObserver = (param, value) => filterKernel.SetParameter(param.Address, value); ParameterTree.ImplementorValueProvider = param => filterKernel.GetParameter((nuint)param.Address); ParameterTree.ImplementorStringFromValueCallback = (AUParameter param, ref float?value) => { switch (param.Address) { case (ulong)FilterParam.Cutoff: return(param.Value.ToString()); case (ulong)FilterParam.Resonance: return(param.Value.ToString()); default: return("?"); } }; MaximumFramesToRender = 512; }
public void Init(AVAudioFormat defaultFormat, uint maxChannels) { MaxFrames = 0; pcmBuffer = null; OriginalAudioBufferList = null; MutableAudioBufferList = null; NSError error; Bus = new AUAudioUnitBus(defaultFormat, out error) { MaximumChannelCount = maxChannels }; }