Exemplo n.º 1
0
        void ConnectParametersToControls()
        {
            var parameterTree = playEngine.AudioUnit?.ParameterTree;

            if (parameterTree == null)
            {
                return;
            }

            var audioUnit = playEngine.AudioUnit as AUv3FilterDemo;

            filterDemoViewController.AudioUnit = audioUnit;

            cutoffParameter    = (AUParameter)parameterTree.ValueForKey((NSString)"cutoff");
            resonanceParameter = (AUParameter)parameterTree.ValueForKey((NSString)"resonance");

            parameterTree.CreateTokenByAddingParameterObserver((address, value) => DispatchQueue.MainQueue.DispatchAsync(() => {
                if (address == cutoffParameter.Address)
                {
                    UpdateCutoff();
                }
                else if (address == resonanceParameter.Address)
                {
                    UpdateResonance();
                }
            }));

            UpdateCutoff();
            UpdateResonance();
        }
        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;
        }
Exemplo n.º 3
0
        void ConnectViewWithAU()
        {
            var au = AudioUnit;

            if (au == null)
            {
                return;
            }

            var paramTree = au.ParameterTree;

            if (paramTree == null)
            {
                return;
            }

            cutoffParameter    = (AUParameter)paramTree.ValueForKey(cutoffKey);
            resonanceParameter = (AUParameter)paramTree.ValueForKey(resonanceKey);

            parameterObserverToken = paramTree.CreateTokenByAddingParameterObserver((address, value) =>
                                                                                    DispatchQueue.MainQueue.DispatchAsync(() => {
                if (address == cutoffParameter.Address)
                {
                    filterView.Frequency = value;
                    frequencyLabel.Text  = cutoffParameter.GetString(null);
                }
                else if (address == resonanceParameter.Address)
                {
                    filterView.Resonance = value;
                    resonanceLabel.Text  = resonanceParameter.GetString(null);
                }

                UpdateFilterViewFrequencyAndMagnitudes();
            })
                                                                                    );

            filterView.Frequency = cutoffParameter.Value;
            filterView.Resonance = resonanceParameter.Value;
        }
Exemplo n.º 4
0
        public MyAudioUnit(AudioComponentDescription description, AudioComponentInstantiationOptions options, out NSError error)
            : base(description, options, out error)
        {
            // Create parameter objects.
            AUParameter param1 = AUParameterTree.CreateParameter(
                "param1",
                "Parameter 1",
                0, 0, 100,
                AudioUnitParameterUnit.Percent,
                string.Empty,
                0, null, null
                );

            // Initialize the parameter values.
            param1.Value = .5f;

            // Create the parameter tree.
            parameterTree = AUParameterTree.CreateTree(new[] { param1 });

            // Create the input and output busses.
            // Create the input and output bus arrays.

            // A function to provide string representations of parameter values.
            parameterTree.ImplementorStringFromValueCallback = (AUParameter param, ref float?value) =>
            {
                switch (param.Address)
                {
                case 0:
                    return((NSString)value?.ToString());

                default:
                    return(new NSString("?"));
                }
            };

            MaximumFramesToRender = 512;
        }
Exemplo n.º 5
0
        void ConnectParametersToControls()
        {
            var parameterTree = playEngine.AudioUnit?.ParameterTree;
            if (parameterTree == null)
                return;

            var audioUnit = playEngine.AudioUnit as AUv3FilterDemo;
            filterDemoViewController.AudioUnit = audioUnit;

            cutoffParameter = (AUParameter)parameterTree.ValueForKey ((NSString)"cutoff");
            resonanceParameter = (AUParameter)parameterTree.ValueForKey ((NSString)"resonance");

            parameterTree.CreateTokenByAddingParameterObserver ((address, value) => DispatchQueue.MainQueue.DispatchAsync (() => {
                if (address == cutoffParameter.Address)
                    UpdateCutoff ();
                else if (address == resonanceParameter.Address)
                    UpdateResonance ();
            }));

            UpdateCutoff ();
            UpdateResonance ();
        }
		void ConnectViewWithAU ()
		{
			var au = AudioUnit;
			if (au == null)
				return;
			
			var paramTree = au.ParameterTree;
			if (paramTree == null)
				return;

			cutoffParameter = (AUParameter)paramTree.ValueForKey (cutoffKey);
			resonanceParameter = (AUParameter)paramTree.ValueForKey (resonanceKey);
		
			parameterObserverToken = paramTree.CreateTokenByAddingParameterObserver ((address, value) =>
				DispatchQueue.MainQueue.DispatchAsync (() => {
					if (address == cutoffParameter.Address) {
						filterView.Frequency = value;
						frequencyLabel.Text = cutoffParameter.GetString (null);
					} else if (address == resonanceParameter.Address) {
						filterView.Resonance = value;
						resonanceLabel.Text = resonanceParameter.GetString (null);
					}

					UpdateFilterViewFrequencyAndMagnitudes ();
				})
			);

			filterView.Frequency = cutoffParameter.Value;
			filterView.Resonance = resonanceParameter.Value;
		}