Example #1
0
        //public float Volume
        //{
        //    set { SoundManager.Volume(sourceIndex, value); }
        //}

        private Sound(string file, bool destroyOnGameEnd)
        {
            filePath = file;

            foreach (Sound loadedSound in loadedSounds)
            {
                if (loadedSound.filePath == file)
                {
                    oggSound = loadedSound.oggSound;
                }
            }

            if (oggSound == null && !SoundManager.Disabled)
            {
                try
                {
                    DebugConsole.Log("Loading sound " + file);
                    oggSound = OggSound.Load(file);
                }
                catch (Exception e)
                {
                    DebugConsole.ThrowError("Failed to load sound " + file + "!", e);
                }
                ALHelper.Check();
            }

            this.destroyOnGameEnd = destroyOnGameEnd;

            loadedSounds.Add(this);
        }
Example #2
0
        public void Remove()
        {
            //sound already removed?
            if (!loadedSounds.Contains(this))
            {
                return;
            }

            loadedSounds.Remove(this);

            if (alSourceId > 0 &&
                (SoundManager.IsPlaying(alSourceId) || SoundManager.IsPaused(alSourceId)))
            {
                SoundManager.Stop(alSourceId);
                ALHelper.Check();
            }

            foreach (Sound s in loadedSounds)
            {
                if (s.oggSound == oggSound)
                {
                    return;
                }
            }

            SoundManager.ClearAlSource(AlBufferId);
            ALHelper.Check();

            if (oggSound != null)
            {
                oggSound.Dispose();
                oggSound = null;
            }
        }