Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SoundInstance"/> class using a dynamic sound source.
        /// </summary>
        /// <param name="engine">The audio engine that will be used to play this instance</param>
        /// <param name="listener">The listener of this instance</param>
        /// <param name="dynamicSoundSource">The source from where the PCM data will be fetched</param>
        /// <param name="sampleRate">The sample rate of this audio stream</param>
        /// <param name="mono">Set to true if the souce is mono, false if stereo</param>
        /// <param name="spatialized">If the SoundInstance will be used for spatialized audio set to true, if not false, if true mono must also be true</param>
        /// <param name="useHrtf">If the engine should use Hrtf for spatialization</param>
        /// <param name="directionalFactor"></param>
        /// <param name="environment"></param>
        public SoundInstance(AudioEngine engine, AudioListener listener, DynamicSoundSource dynamicSoundSource, int sampleRate, bool mono, bool spatialized = false, bool useHrtf = false, float directionalFactor = 0.0f, HrtfEnvironment environment = HrtfEnvironment.Small)
        {
            Listener         = listener;
            this.engine      = engine;
            this.spatialized = spatialized;
            soundSource      = dynamicSoundSource;

            if (engine.State == AudioEngineState.Invalidated)
            {
                return;
            }

            Source = AudioLayer.SourceCreate(listener.Listener, sampleRate, dynamicSoundSource.MaxNumberOfBuffers, mono, spatialized, true, useHrtf, directionalFactor, environment);
            if (Source.Ptr == IntPtr.Zero)
            {
                throw new Exception("Failed to create an AudioLayer Source");
            }

            ResetStateToDefault();
        }
Exemplo n.º 2
0
        public override void Initialize()
        {
            base.Initialize();

            lock (AudioEngineStaticLock)
            {
                if (audioEngineSingleton == null)
                {
                    var settings = Services.GetService <IGameSettingsService>()?.Settings?.Configurations?.Get <AudioEngineSettings>();
                    audioEngineSingleton = AudioEngineFactory.NewAudioEngine(RequestedAudioDevice, settings != null && settings.HrtfSupport ? AudioLayer.DeviceFlags.Hrtf : AudioLayer.DeviceFlags.None);
                }
                else
                {
                    ((IReferencable)audioEngineSingleton).AddReference();
                }

                AudioEngine = audioEngineSingleton;
            }

            Game.Activated   += OnActivated;
            Game.Deactivated += OnDeactivated;
        }
Exemplo n.º 3
0
        public AudioListener(AudioEngine engine)
        {
            if (engine.State == AudioEngineState.Invalidated)
            {
                return;
            }

#if XENKO_PLATFORM_IOS
            if (engine.DefaultListener == null)
            {
                Listener = AudioLayer.ListenerCreate(engine.AudioDevice);
                AudioLayer.ListenerEnable(Listener);
            }
            else
            {
                Listener = engine.DefaultListener.Listener;
            }
#else
            Listener = AudioLayer.ListenerCreate(engine.AudioDevice);
            AudioLayer.ListenerEnable(Listener);
#endif
        }
Exemplo n.º 4
0
 private void OnDeactivated(object sender, EventArgs e)
 {
     // pause the audio
     AudioEngine.PauseAudio();
     AudioEngine.Update(); // force the update of the audio to pause the Musics
 }
Exemplo n.º 5
0
 private void OnActivated(object sender, EventArgs e)
 {
     // resume the audio
     AudioEngine.ResumeAudio();
 }
Exemplo n.º 6
0
 public override void Update(GameTime gameTime)
 {
     AudioEngine.Update();
 }