public SimplePlayEngine (Action componentsFoundCallback = null)
		{
			PresetList = new AUAudioUnitPreset [0];
			this.componentsFoundCallback = componentsFoundCallback;
			engine.AttachNode (player);

			var fileUrl = NSBundle.MainBundle.GetUrlForResource ("drumLoop", "caf");
			if (fileUrl == null)
				throw new NullReferenceException ("drumploop.caf file not found");

			SetPlayerFile (fileUrl);

			if (componentsFoundCallback != null) {
				UpdateEffectsList ();
				AUAudioUnit.Notifications.ObserveAudioComponentRegistrationsChanged ((sender, e) => UpdateEffectsList ());
			}

			var error = AVAudioSession.SharedInstance ().SetCategory (AVAudioSessionCategory.Playback);
			if (error != null)
				throw new NSErrorException(error);

			AUAudioUnit.Notifications.ObserveAudioComponentInstanceInvalidation ((sender, e) => {
				var crashedAU = e.Notification.Object as AUAudioUnit;
				if (AudioUnit == crashedAU)
					SelectEffectWithComponentDescription (null, null);
			});
		}
Exemple #2
0
        public void SelectEffectWithComponentDescription(AudioComponentDescription?componentDescription, Action completionHandler)
        {
            if (isPlaying)
            {
                player.Pause();
            }

            if (effect != null)
            {
                engine.DisconnectNodeInput(effect);
                engine.DisconnectNodeInput(engine.MainMixerNode);

                engine.Connect(player, engine.MainMixerNode, file.ProcessingFormat);

                engine.DetachNode(effect);

                effect     = null;
                AudioUnit  = null;
                PresetList = new AUAudioUnitPreset[0];
            }

            if (componentDescription.HasValue)
            {
                AVAudioUnit.FromComponentDescription(componentDescription.Value, AudioComponentInstantiationOptions.OutOfProcess, (avAudioUnitEffect, AVError) => {
                    if (AVError != null || avAudioUnitEffect == null)
                    {
                        Console.WriteLine("SelectEffectWithComponentDescription error!");
                        return;
                    }

                    effect = avAudioUnitEffect;
                    engine.AttachNode(avAudioUnitEffect);

                    engine.DisconnectNodeInput(engine.MainMixerNode);

                    engine.Connect(player, avAudioUnitEffect, file.ProcessingFormat);
                    engine.Connect(avAudioUnitEffect, engine.MainMixerNode, file.ProcessingFormat);

                    AudioUnit  = avAudioUnitEffect.AUAudioUnit;
                    PresetList = avAudioUnitEffect.AUAudioUnit.FactoryPresets ?? new AUAudioUnitPreset[0];
                    Done(completionHandler);
                });
            }
            else
            {
                Done(completionHandler);
            }
        }
Exemple #3
0
        public SimplePlayEngine(Action componentsFoundCallback = null)
        {
            PresetList = new AUAudioUnitPreset [0];
            this.componentsFoundCallback = componentsFoundCallback;
            engine.AttachNode(player);

            var fileUrl = NSBundle.MainBundle.GetUrlForResource("drumLoop", "caf");

            if (fileUrl == null)
            {
                throw new NullReferenceException("drumploop.caf file not found");
            }

            SetPlayerFile(fileUrl);

            if (componentsFoundCallback != null)
            {
                UpdateEffectsList();
                AUAudioUnit.Notifications.ObserveAudioComponentRegistrationsChanged((sender, e) => UpdateEffectsList());
            }

#if __IOS__
            var error = AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback);
            if (error != null)
            {
                throw new NSErrorException(error);
            }
#endif

            AUAudioUnit.Notifications.ObserveAudioComponentInstanceInvalidation((sender, e) => {
                var crashedAU = e.Notification.Object as AUAudioUnit;
                if (AudioUnit == crashedAU)
                {
                    SelectEffectWithComponentDescription(null, null);
                }
            });
        }
		public void SelectEffectWithComponentDescription (AudioComponentDescription? componentDescription, Action completionHandler)
		{
			if (isPlaying)
				player.Pause ();

			if (effect != null) {
				engine.DisconnectNodeInput (effect);
				engine.DisconnectNodeInput (engine.MainMixerNode);

				engine.Connect (player, engine.MainMixerNode, file.ProcessingFormat);

				engine.DetachNode (effect);

				effect = null;
				AudioUnit = null;
				PresetList = new AUAudioUnitPreset[0];
			}

			if (componentDescription.HasValue) {
				AVAudioUnit.FromComponentDescription (componentDescription.Value, AudioComponentInstantiationOptions.OutOfProcess, (avAudioUnitEffect, AVError) => {
					if (AVError != null || avAudioUnitEffect == null) {
						Console.WriteLine ("SelectEffectWithComponentDescription error!");
						return;
					}

					effect = avAudioUnitEffect;
					engine.AttachNode (avAudioUnitEffect);

					engine.DisconnectNodeInput (engine.MainMixerNode);

					engine.Connect (player, avAudioUnitEffect, file.ProcessingFormat);
					engine.Connect (avAudioUnitEffect, engine.MainMixerNode, file.ProcessingFormat);

					AudioUnit = avAudioUnitEffect.AUAudioUnit;
					PresetList = avAudioUnitEffect.AUAudioUnit.FactoryPresets ?? new AUAudioUnitPreset[0];
					Done (completionHandler);
				});
			} else {
				Done (completionHandler);
			}
		}