Пример #1
0
        /// <summary>
        /// Adds a sound to this sound pool.
        /// </summary>
        public virtual SoundPoolEntry AddSound(string par1Str, string par2File)
        {
            try
            {
                string s = par1Str;
                par1Str = par1Str.Substring(0, par1Str.IndexOf("."));

                if (IsGetRandomSound)
                {
                    for (; char.IsDigit(par1Str[par1Str.Length - 1]); par1Str = par1Str.Substring(0, par1Str.Length - 1))
                    {
                    }
                }

                par1Str = par1Str.Replace("/", ".");

                if (!NameToSoundPoolEntriesMapping.ContainsKey(par1Str))
                {
                    NameToSoundPoolEntriesMapping[par1Str] = new List <SoundPoolEntry>();
                }

                SoundPoolEntry soundpoolentry = new SoundPoolEntry(s, par2File);
                NameToSoundPoolEntriesMapping[par1Str].Add(soundpoolentry);
                AllSoundPoolEntries.Add(soundpoolentry);
                NumberOfSoundPoolEntries++;
                return(soundpoolentry);
            }
            catch (Exception malformedurlexception)
            {
                Utilities.LogException(malformedurlexception);

                throw malformedurlexception;
            }
        }
Пример #2
0
        /// <summary>
        /// Plays a sound. Args: soundName, x, y, z, volume, pitch
        /// </summary>
        public void PlaySound(string par1Str, float par2, float par3, float par4, float par5, float par6)
        {
            if (!Loaded || Options.SoundVolume == 0.0F)
            {
                return;
            }

            SoundPoolEntry soundpoolentry = SoundPoolSounds.GetRandomSoundFromSoundPool(par1Str);

            if (soundpoolentry != null && par5 > 0.0F)
            {
                LatestSoundID = (LatestSoundID + 1) % 256;
                string s = (new StringBuilder()).Append("sound_").Append(LatestSoundID).ToString();
                float  f = 16F;

                if (par5 > 1.0F)
                {
                    f *= par5;
                }

                /*
                 *              SndSystem.newSource(par5 > 1.0F, s, soundpoolentry.SoundUrl, soundpoolentry.SoundName, false, par2, par3, par4, 2, f);
                 *              SndSystem.setPitch(s, par6);
                 */
                if (par5 > 1.0F)
                {
                    par5 = 1.0F;
                }

                /*
                 *              SndSystem.setVolume(s, par5 * Options.SoundVolume);
                 *              SndSystem.play(s);*/
            }
        }
Пример #3
0
        /// <summary>
        /// Plays a sound effect with the volume and pitch of the parameters passed. The sound isn't affected by position of
        /// the player (full volume and center balanced)
        /// </summary>
        public void PlaySoundFX(string par1Str, float par2, float par3)
        {
            if (!Loaded || Options.SoundVolume == 0.0F)
            {
                return;
            }

            SoundPoolEntry soundpoolentry = SoundPoolSounds.GetRandomSoundFromSoundPool(par1Str);

            if (soundpoolentry != null)
            {
                LatestSoundID = (LatestSoundID + 1) % 256;
                string s = (new StringBuilder()).Append("sound_").Append(LatestSoundID).ToString();
                //SndSystem.newSource(false, s, soundpoolentry.SoundUrl, soundpoolentry.SoundName, false, 0.0F, 0.0F, 0.0F, 0, 0.0F);
                MemoryStream stream = new MemoryStream();
                using (var fileStream = new FileStream(soundpoolentry.SoundUrl, FileMode.Open))
                {
                    fileStream.CopyTo(stream);
                }
                OggSong song = new OggSong(stream);

                if (par2 > 1.0F)
                {
                    par2 = 1.0F;
                }

                par2 *= 0.25F;                /*
                                               * SndSystem.setPitch(s, par3);
                                               * SndSystem.setVolume(s, par2 * Options.SoundVolume);
                                               * SndSystem.play(s);*/

                song.Pitch  = par3 - 1;
                song.Volume = par2 * Options.SoundVolume;
                song.Play();
            }
        }
Пример #4
0
        public void PlayStreaming(string par1Str, float par2, float par3, float par4, float par5, float par6)
        {
            if (!Loaded || Options.SoundVolume == 0.0F && par1Str != null)
            {
                return;
            }

            string s = "streaming";

            /*
             *          if (SndSystem.playing("streaming"))
             *          {
             *                  SndSystem.stop("streaming");
             *          }
             */
            if (par1Str == null)
            {
                return;
            }

            SoundPoolEntry soundpoolentry = SoundPoolStreaming.GetRandomSoundFromSoundPool(par1Str);

            /*
             *          if (soundpoolentry != null && par5 > 0.0F)
             *          {
             *                  if (SndSystem.playing("BgMusic"))
             *                  {
             *                          SndSystem.stop("BgMusic");
             *                  }
             *
             *                  float f = 16F;
             *                  SndSystem.newStreamingSource(true, s, soundpoolentry.SoundUrl, soundpoolentry.SoundName, false, par2, par3, par4, 2, f * 4F);
             *                  SndSystem.setVolume(s, 0.5F * Options.SoundVolume);
             *                  SndSystem.play(s);
             *          }*/
        }