Esempio n. 1
0
        /// <summary>
        /// Triggers a new 3D sound
        /// </summary>
        /// <remarks>
        /// In order to free up unnecessary memory usage, the played cue is automatically destroyed
        /// when it stops playing.
        /// </remarks>
        /// <exception cref="GoblinException">Throws exception if this is called before Initialize(..)</exception>
        /// <param name="cueName">The name of the cue of a sound</param>
        /// <param name="emitter">An IAudioEmitter object that defines the properties of the sound
        /// including position, and velocity.</param>
        /// <returns></returns>
        public Cue Play3D(String cueName, IAudioEmitter emitter)
        {
            if (!initialized)
            {
                throw new GoblinException("Sound engine is not initialized. Call Sound.Initialize(..) first");
            }

            Cue3D cue3D;

            if (cuePool.Count > 0)
            {
                // If possible, reuse an existing Cue3D instance.
                cue3D = cuePool.Pop();
            }
            else
            {
                // Otherwise we have to allocate a new one.
                cue3D = new Cue3D();
            }

            // Fill in the cue and emitter fields.
            cue3D.Cue     = soundBank.GetCue(cueName);
            cue3D.Emitter = emitter;

            // Set the 3D position of this cue, and then play it.
            Apply3D(cue3D);

            cue3D.Cue.Play();

            // Remember that this cue is now active.
            activeCues.Add(cue3D);

            return(cue3D.Cue);
        }
Esempio n. 2
0
        /// <summary>
        /// Triggers a new 3D sound.
        /// </summary>
        public Cue Play3DCue(string cueName, IAudioEmitter emitter)
        {
            Cue3D cue3D;

            if (cuePool.Count > 0)
            {
                // If possible, reuse an existing Cue3D instance.
                cue3D = cuePool.Pop();
            }
            else
            {
                // Otherwise we have to allocate a new one.
                cue3D = new Cue3D();
            }

            // Fill in the cue and emitter fields.
            cue3D.Cue     = soundBank.GetCue(cueName);
            cue3D.Emitter = emitter;

            // Set the 3D position of this cue, and then play it.
            Apply3D(cue3D);

            cue3D.Cue.Play();

            // Remember that this cue is now active.
            activeCues.Add(cue3D);

            return(cue3D.Cue);
        }
Esempio n. 3
0
        /// <summary>
        /// Plays a sound.
        /// </summary>
        /// <param name="soundManager">The sound manager.</param>
        /// <param name="name">The name of the sound to play.</param>
        /// <param name="source">The source of the sound.</param>
        /// <returns>
        /// True if the sound was successfully played; otherwise false.
        /// </returns>
        public static bool Play(this ISoundManager soundManager, string name, IAudioEmitter source)
        {
            var info = soundManager.GetSoundInfo(name);

            if (info == null)
            {
                return(false);
            }

            return(soundManager.Play(info.ID, source));
        }
Esempio n. 4
0
        /// <summary>
        /// Triggers a new 3D sound
        /// </summary>
        /// <remarks>
        /// In order to free up unnecessary memory usage, the played cue is automatically destroyed
        /// when it stops playing.
        /// </remarks>
        /// <exception cref="GoblinException">Throws exception if this is called before Initialize(..)</exception>
        /// <param name="soundEffectName">The name of the sound effect to play</param>
        /// <param name="emitter">An IAudioEmitter object that defines the properties of the sound
        /// including position, and velocity.</param>
        /// <returns></returns>
        public SoundEffectInstance PlaySoundEffect3D(string soundEffectName, IAudioEmitter emitter)
        {
            if (!soundEffects.ContainsKey(soundEffectName))
            {
                SoundEffect effect = State.Content.Load <SoundEffect>(soundEffectName);
                effect.Name = soundEffectName;

                soundEffects.Add(soundEffectName, effect);
            }

            return(PlaySoundEffect3D(soundEffects[soundEffectName], emitter));
        }
Esempio n. 5
0
        /// <summary>
        /// Plays a sound by the given <see cref="SoundID"/>.
        /// </summary>
        /// <param name="id">The ID of the sound to play.</param>
        /// <param name="source">The <see cref="IAudioEmitter"/> that the sound is coming from.</param>
        /// <returns>
        /// True if the sound played successfully; otherwise false.
        /// </returns>
        public bool Play(SoundID id, IAudioEmitter source)
        {
            // Create the sound instance
            ISoundInfo info;
            var        snd = InternalCreateSound(id, true, out info);

            if (snd == null)
            {
                return(false);
            }

            // Set the sound up and start playing it
            SoundInstance si;

            try
            {
                snd.Position = new Vector3(source.Position, 0f);
                si           = new SoundInstance(info, snd, source);
                snd.Play();
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to play sound `{0}`: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, info, ex);
                }

                try
                {
                    snd.Dispose();
                }
                catch (Exception ex2)
                {
                    const string errmsg2 = "Failed to dispose sound that failed to play `{0}`: {1}";
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat(errmsg2, info, ex2);
                    }
                }

                return(false);
            }

            // Add to the list of active sounds
            _soundInstances.Add(si);

            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Triggers a new 3D sound
        /// </summary>
        /// <remarks>
        /// In order to free up unnecessary memory usage, the played cue is automatically destroyed
        /// when it stops playing.
        /// </remarks>
        /// <exception cref="GoblinException">Throws exception if this is called before Initialize(..)</exception>
        /// <param name="soundEffect">The loaded sound effect</param>
        /// <param name="emitter">An IAudioEmitter object that defines the properties of the sound
        /// including position, and velocity.</param>
        /// <returns></returns>
        public SoundEffectInstance PlaySoundEffect3D(SoundEffect soundEffect, IAudioEmitter emitter)
        {
            SoundEffectInstance ei = soundEffect.CreateInstance();

            Sound3D sound3D = new Sound3D();

            sound3D.Sound   = ei;
            sound3D.Emitter = emitter;

            sound3Ds.Add(sound3D);
            Apply3D(sound3D);

            ei.Play();

            return(ei);
        }
Esempio n. 7
0
        // <summary>
        /// Triggers a new 3D sound.
        /// </summary>
        public SoundEffectInstance Play3DSound(string soundName, bool isLooped, IAudioEmitter emitter)
        {
            ActiveSound activeSound = new ActiveSound();

            // Fill in the instance and emitter fields.
            activeSound.Instance          = soundEffects[soundName].CreateInstance();
            activeSound.Instance.IsLooped = isLooped;

            activeSound.Emitter = emitter;

            activeSound.Instance.Play();

            // Remember that this sound is now active.
            //activeSounds.Add(activeSound);

            return(activeSound.Instance);
        }
Esempio n. 8
0
        /// <summary>
        /// Triggers a new 3D sound.
        /// </summary>
        public SoundEffectInstance Play3DSound(string soundName, bool isLooped, IAudioEmitter emitter)
        {
            ActiveSound activeSound = new ActiveSound();

            // Fill in the instance and emitter fields.

            activeSound.Instance = soundEffects[soundName].CreateInstance();
            activeSound.Instance.IsLooped = isLooped;

            activeSound.Emitter = emitter;

            // Set the 3D position of this sound, and then play it.
            Apply3D(activeSound);

            activeSound.Instance.Play();

            // Remember that this sound is now active.
            activeSounds.Add(activeSound);

            return activeSound.Instance;
        }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SoundInstance"/> struct.
 /// </summary>
 /// <param name="soundInfo">The sound info.</param>
 /// <param name="sound">The sound.</param>
 /// <param name="audioEmitter">The audio emitter.</param>
 public SoundInstance(ISoundInfo soundInfo, Sound sound, IAudioEmitter audioEmitter)
 {
     _sound        = sound;
     _soundInfo    = soundInfo;
     _audioEmitter = audioEmitter;
 }
Esempio n. 10
0
 /// <summary>
 /// Plays a sound.
 /// </summary>
 /// <param name="soundManager">The sound manager.</param>
 /// <param name="info">The <see cref="ISoundInfo"/> to play.</param>
 /// <param name="source">The source.</param>
 /// <returns>
 /// True if the sound played successfully; otherwise false.
 /// </returns>
 public static bool Play(this ISoundManager soundManager, ISoundInfo info, IAudioEmitter source)
 {
     return(soundManager.Play(info.ID, source));
 }
Esempio n. 11
0
        /// <summary>
        /// Plays a sound.
        /// </summary>
        /// <param name="soundManager">The sound manager.</param>
        /// <param name="name">The name of the sound to play.</param>
        /// <param name="source">The source of the sound.</param>
        /// <returns>
        /// True if the sound was successfully played; otherwise false.
        /// </returns>
        public static bool Play(this ISoundManager soundManager, string name, IAudioEmitter source)
        {
            var info = soundManager.GetSoundInfo(name);
            if (info == null)
                return false;

            return soundManager.Play(info.ID, source);
        }
Esempio n. 12
0
 /// <summary>
 /// Plays a sound.
 /// </summary>
 /// <param name="soundManager">The sound manager.</param>
 /// <param name="info">The <see cref="ISoundInfo"/> to play.</param>
 /// <param name="source">The source.</param>
 /// <returns>
 /// True if the sound played successfully; otherwise false.
 /// </returns>
 public static bool Play(this ISoundManager soundManager, ISoundInfo info, IAudioEmitter source)
 {
     return soundManager.Play(info.ID, source);
 }
Esempio n. 13
0
 public APU(Gameboy gameboy)
 {
     _gameboy = gameboy;
     Emitter  = _gameboy.ConstructEmitter();
     Reset();
 }
Esempio n. 14
0
        /// <summary>
        /// Triggers a new 3D sound.
        /// </summary>
        public Cue Play3DCue( string cueName, IAudioEmitter emitter, float volume )
        {
            Cue3D cue3D;

              if ( cuePool.Count > 0 )
              {
            // If possible, reuse an existing Cue3D instance.
            cue3D = cuePool.Pop();
              }
              else
              {
            // Otherwise we have to allocate a new one.
            cue3D = new Cue3D();
              }

              // Fill in the cue and emitter fields.
              cue3D.Cue = soundBank.GetCue( cueName );
              cue3D.Emitter = emitter;

              // Set the 3D position of this cue, and then play it.
              Apply3D( cue3D );

              float volScale = GameCore.Instance.SoundEffectsVolume;
              // Set volume of cue
              /**/
              if ( volume <= 0 )
            cue3D.Cue.SetVariable( VarVolume, -96 );
              else
            cue3D.Cue.SetVariable( VarVolume, MathHelper.Clamp( 10f * (float)Math.Log10( volume * volScale ), -96, 6 ) );
              /*/
              cue3D.Cue.SetVariable( varVolume, XACTHelper.GetDecibels( volume * volScale ) );
              /**/

              cue3D.Cue.Play();

              // Remember that this cue is now active.
              activeCues.Add( cue3D );

              return cue3D.Cue;
        }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SoundInstance"/> struct.
 /// </summary>
 /// <param name="soundInfo">The sound info.</param>
 /// <param name="sound">The sound.</param>
 /// <param name="audioEmitter">The audio emitter.</param>
 public SoundInstance(ISoundInfo soundInfo, Sound sound, IAudioEmitter audioEmitter)
 {
     _sound = sound;
     _soundInfo = soundInfo;
     _audioEmitter = audioEmitter;
 }
Esempio n. 16
0
        /// <summary>
        /// Plays a sound by the given <see cref="SoundID"/>.
        /// </summary>
        /// <param name="id">The ID of the sound to play.</param>
        /// <param name="source">The <see cref="IAudioEmitter"/> that the sound is coming from.</param>
        /// <returns>
        /// True if the sound played successfully; otherwise false.
        /// </returns>
        public bool Play(SoundID id, IAudioEmitter source)
        {
            // Create the sound instance
            ISoundInfo info;
            var snd = InternalCreateSound(id, true, out info);
            if (snd == null)
                return false;

            // Set the sound up and start playing it
            SoundInstance si;
            try
            {
                snd.Position = new Vector3(source.Position, 0f);
                si = new SoundInstance(info, snd, source);
                snd.Play();
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to play sound `{0}`: {1}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, info, ex);

                try
                {
                    snd.Dispose();
                }
                catch (Exception ex2)
                {
                    const string errmsg2 = "Failed to dispose sound that failed to play `{0}`: {1}";
                    if (log.IsWarnEnabled)
                        log.WarnFormat(errmsg2, info, ex2);
                }

                return false;
            }

            // Add to the list of active sounds
            _soundInstances.Add(si);

            return true;
        }