Exemplo n.º 1
0
 public static void Initialize(IntPtr handle)
 {
     // The user provide their own OpenAL Context
     // Therefore, this context should not be used
     if (_context != null)
     {
         _context.Dispose();
     }
 }
Exemplo n.º 2
0
        public void SetOptions(string deviceName)
        {
            if (IsInited)
            {
                Stop();
                _context.Dispose();
            }

            Initialize(deviceName);
        }
Exemplo n.º 3
0
 public void Init(Client tclient, ClientCVar cvar)
 {
     if (Context != null)
     {
         Context.Dispose();
     }
     TheClient = tclient;
     CVars     = cvar;
     Context   = new AudioContext(AudioContext.DefaultDevice, 0, 0, false, true);
     Context.MakeCurrent();
     try
     {
         if (Microphone != null)
         {
             Microphone.StopEcho();
         }
         Microphone = new MicrophoneHandler(this);
     }
     catch (Exception ex)
     {
         SysConsole.Output("Loading microphone handling", ex);
     }
     if (Effects != null)
     {
         foreach (SoundEffect sfx in Effects.Values)
         {
             sfx.Internal = -2;
         }
     }
     Effects    = new Dictionary <string, SoundEffect>();
     PlayingNow = new List <ActiveSound>();
     Noise      = LoadSound(new DataStream(Convert.FromBase64String(NoiseDefault.NoiseB64)), "noise");
 }
Exemplo n.º 4
0
        private void Initialize(string deviceName)
        {
            try
            {
                lock (_syncObject)
                {
                    _sources = new Dictionary <string, SourceDescription>();

                    if (string.IsNullOrEmpty(deviceName))
                    {
                        deviceName = AudioContext.DefaultDevice;
                    }

                    if (!AudioContext.AvailableDevices.Contains(deviceName))
                    {
                        deviceName = AudioContext.DefaultDevice;
                    }

                    _context = new AudioContext(deviceName);
                }
            }
            catch (Exception e)
            {
                if (_context != null)
                {
                    _context.Dispose();
                }

                _context = null;

                ClientModel.Logger.Write(e);
                throw new ModelException(ErrorCode.AudioNotEnabled, "Audio player do not initialized.", e, deviceName);
            }
        }
Exemplo n.º 5
0
        public void shutdown()
        {
            if (myIsInitialized)
            {
                myContext.MakeCurrent();

                foreach (AbstractAudio snd in myToRemovePlayingSounds)
                {
                    myPlayingSounds.Remove(snd);
                }
                myToRemovePlayingSounds.Clear();

                //stop any playing sounds
                foreach (AbstractAudio snd in myPlayingSounds)
                {
                    snd.stop();
                }
                myPlayingSounds.Clear();

                clearVoices();
                myCaptureDevice.Dispose();
                myContext.Dispose();

                myDevice        = IntPtr.Zero;
                myIsInitialized = false;
                myIsEnabled     = false;
            }
        }
Exemplo n.º 6
0
        public void DisposeAll()
        {
            AL.DeleteSources(mySources); // free Handles

            AL.DeleteBuffers(myBuffers); // free previously reserved Handles
            AC.Dispose();
        }
Exemplo n.º 7
0
        public void Dispose()
        {
            for (int i = 0; i < m_sound.Length; ++i)
            {
                var source = m_sound[i];
                source.Dispose();
            }
            for (int i = 0; i < m_music.Length; ++i)
            {
                var source = m_music[i];
                if (source != null)
                {
                    source.Dispose();
                }
            }
            for (int i = 0; i < m_custom.Length; ++i)
            {
                var source = m_custom[i];
                if (source != null)
                {
                    source.Dispose();
                }
            }
            m_context.Dispose();

            Instance = null;
        }
Exemplo n.º 8
0
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// game-specific content.
        /// </summary>
        protected override void UnloadContent()
        {
            this.Content.Unload();

            _audioInstance.Dispose();
            _audioContext.Dispose();
        }
Exemplo n.º 9
0
        public override void Dispose()
        {
            base.Dispose();
            context?.Dispose();

            context = null;
        }
Exemplo n.º 10
0
 internal static void DisposeSoundServices()
 {
     if (context != null)
     {
         context.Dispose();
         context = null;
     }
 }
Exemplo n.º 11
0
        protected override void OnUnload(EventArgs e)
        {
            base.OnUnload(e);

            engine.Terminate();

            AC.Dispose();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initialize the sound engine.
        /// </summary>
        /// <param name="tclient">The backing client.</param>
        public void Init(GameEngineBase tclient)
        {
            if (AudioInternal != null)
            {
                AudioInternal.Shutdown();
            }
            if (Context != null)
            {
                Context.Dispose();
            }
            Client  = tclient;
            Context = new AudioContext(AudioContext.DefaultDevice, 0, 0, false, true);
            if (Client.EnforceAudio)
            {
                AudioInternal = new AudioEnforcer();
                AudioInternal.Init(Context);
                Context = null;
            }
            else
            {
                Context.MakeCurrent();
            }

            /*try
             * {
             *  if (Microphone != null)
             *  {
             *      Microphone.StopEcho();
             *  }
             *  Microphone = new MicrophoneHandler(this);
             * }
             * catch (Exception ex)
             * {
             *  SysConsole.Output("Loading microphone handling", ex);
             * }*/
            if (Effects != null)
            {
                foreach (SoundEffect sfx in Effects.Values)
                {
                    sfx.Internal = -2;
                }
            }
            Effects    = new Dictionary <string, SoundEffect>();
            PlayingNow = new List <ActiveSound>();
            //DeafLoop = GetSound("sfx/ringing/earring_loop");
        }
Exemplo n.º 13
0
 private void Release_Resources(object sender, EventArgs e)
 {
     AL.SourceStop(_source);
     AL.DeleteSource(_source);
     AL.DeleteBuffer(_buffer);
     Alc.MakeContextCurrent(ContextHandle.Zero);
     _context.Dispose();
 }
Exemplo n.º 14
0
 public void Init(Client tclient, ClientCVar cvar)
 {
     if (AudioInternal != null)
     {
         AudioInternal.Shutdown();
     }
     if (Context != null)
     {
         Context.Dispose();
     }
     TheClient = tclient;
     CVars     = cvar;
     Context   = new AudioContext(AudioContext.DefaultDevice, 0, 0, false, true);
     if (TheClient.CVars.a_enforce.ValueB)
     {
         AudioInternal = new AudioEnforcer();
         AudioInternal.Init(Context);
         Context = null;
     }
     else
     {
         Context.MakeCurrent();
     }
     try
     {
         if (Microphone != null)
         {
             Microphone.StopEcho();
         }
         Microphone = new MicrophoneHandler(this);
     }
     catch (Exception ex)
     {
         SysConsole.Output("Loading microphone handling", ex);
     }
     if (Effects != null)
     {
         foreach (SoundEffect sfx in Effects.Values)
         {
             sfx.Internal = -2;
         }
     }
     Effects    = new Dictionary <string, SoundEffect>();
     PlayingNow = new List <ActiveSound>();
     DeafLoop   = GetSound("sfx/ringing/earring_loop");
 }
Exemplo n.º 15
0
 public void Dispose()
 {
     if (_context == null)
     {
         return;
     }
     _context.Dispose();
 }
Exemplo n.º 16
0
 public static void StopAudio()
 {
     if (_audioContext != null)
     {
         _audioContext.Dispose();
         _audioContext = null;
     }
 }
Exemplo n.º 17
0
        /// <inheritdoc />
        public void Dispose()
        {
            foreach (var source in _sources)
            {
                source.Dispose();
            }

            _context.Dispose();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Stop Audio playback
        /// </summary>
        public void StopPlayBack()
        {
            for (int i = 0; i < sources.Length; i++)
            {
                StopPlayBack(sources[i]);
            }

            audio_context.Dispose();
        }
 public override void Dispose()
 {
     base.Dispose();
     if (context != null)
     {
         context.Dispose();
     }
     context = null;
 }
Exemplo n.º 20
0
 /// <summary>
 /// (Internal) Stops all sounds, clears the sound cache and destroys the OpenAL context.
 /// </summary>
 internal void Destroy()
 {
     if (!Enabled)
     {
         return;           // This AudioPlayer was not enabled, nothing to clear or destroy
     }
     ClearCache();
     Context.Dispose();
 }
Exemplo n.º 21
0
 public override void Close()
 {
     if (!_Initialized)
     {
         return;
     }
     base.Close();
     _Context.Dispose();
     _Context = null;
 }
Exemplo n.º 22
0
        internal static void DisposeSoundServices()
        {
#if !PORTABLE
            if (context != null)
            {
                context.Dispose();
                context = null;
            }
#endif
        }
Exemplo n.º 23
0
 /// <summary>
 /// This is called when the game exits.
 /// </summary>
 public override void Close()
 {
     // Cleans up all none entity bound audio
     for (int i = 0; i < SoundEffects.Count; i++)
     {
         SoundEffects[i].Close();
     }
     // Closes the audio context
     audioContext.Dispose();
 }
Exemplo n.º 24
0
 public void Dispose()
 {
     foreach (var sound in _sounds)
     {
         sound.Value.Stream.Stop();
         sound.Value.Stream.Dispose();
     }
     _context.Dispose();
     _streamer.Dispose();
 }
Exemplo n.º 25
0
 void DestroyContext()
 {
     EAGLContext.SetCurrentContext(_glContext);
     GL.DeleteRenderbuffers(1, ref _db);
     GL.DeleteRenderbuffers(1, ref _cb);
     GL.DeleteFramebuffers(1, ref _fb);
     _db = _cb = _fb = 0;
     _glContext.Dispose();
     _alContext.Dispose();
 }
Exemplo n.º 26
0
        public static void Dispose()
        {
            if (_context != null)
            {
                _context.Dispose();
                _context = null;

                IsDisposed = true;
            }
        }
Exemplo n.º 27
0
        public static void Close()
        {
            foreach (SoundEntry entry in soundEntries)
            {
                AL.SourceStop(entry.Source);
                AL.DeleteSource(entry.Source);
                AL.DeleteBuffer(entry.Buffer);
            }

            context.Dispose();
        }
Exemplo n.º 28
0
 public void Destroy()
 {
     AL.SourceStop(sourceName);
     AL.Source(sourceName, ALSourcei.Buffer, 0);
     for (int i = 0; i < activeBuffers.Count; i++)
     {
         AL.DeleteBuffer(activeBuffers[i]);
     }
     AL.DeleteSource(sourceName);
     AC.Dispose();
 }
Exemplo n.º 29
0
 internal static void Dispose()
 {
     if (_audioContext == null)
     {
         return;
     }
     StopAllSounds();
     AL.DeleteSources(_source);             //delete multiple sources
     AL.DeleteBuffers(_buffer);             //delete multiple buffers
     _audioContext.Dispose();
 }
Exemplo n.º 30
0
        public static void Initialize(ApplicationOptions options)
        {
#if iOS
            AVAudioSession.SharedInstance().Init();
            interruptionNotification = AVAudioSession.Notifications.ObserveInterruption((sender, args) => {
                if (args.InterruptionType == AVAudioSessionInterruptionType.Began)
                {
                    AVAudioSession.SharedInstance().SetActive(false);
                    // OpenALMob can not continue after session interruption, so destroy context here.
                    if (context != null)
                    {
                        foreach (var c in channels)
                        {
                            c.DisposeOpenALResources();
                        }
                        context.Dispose();
                        context = null;
                    }
                    Active = false;
                }
                else if (args.InterruptionType == AVAudioSessionInterruptionType.Ended)
                {
                    // Do not restore the audio session here, because incoming call screen is still visible. Defer it until the first update.
                    audioSessionInterruptionEnded = true;
                }
            });
            context = new AudioContext();
#elif ANDROID
            // LoadLibrary() ivokes JNI_OnLoad()
            Java.Lang.JavaSystem.LoadLibrary(Lib);
            context = new AudioContext();
#else
            bool isDeviceAvailable = !String.IsNullOrEmpty(AudioContext.DefaultDevice);
            if (isDeviceAvailable && !CommandLineArgs.NoAudio)
            {
                context = new AudioContext();
            }
#endif
            var err = AL.GetError();
            if (err == ALError.NoError)
            {
                for (int i = 0; i < options.NumChannels; i++)
                {
                    channels.Add(new AudioChannel(i));
                }
            }
            if (options.DecodeAudioInSeparateThread)
            {
                streamingThread = new Thread(RunStreamingLoop);
                streamingThread.IsBackground = true;
                streamingThread.Start();
            }
        }
Exemplo n.º 31
0
    private void Initialize(string deviceName)
    {
      try
      {
        lock (syncObject)
        {
          sources = new Dictionary<string, SourceDescription>();

          if (string.IsNullOrEmpty(deviceName))
            deviceName = AudioContext.DefaultDevice;

          if (!AudioContext.AvailableDevices.Contains(deviceName))
            deviceName = AudioContext.DefaultDevice;

          context = new AudioContext(deviceName);
        }
      }
      catch (Exception e)
      {
        if (context != null)
          context.Dispose();

        context = null;

        ClientModel.Logger.Write(e);
        throw new ModelException(ErrorCode.AudioNotEnabled, "Audio player do not initialized.", e, deviceName);
      }
    }