Esempio n. 1
0
        public ISoundVoice StartPlay2D(ISoundDataSource soundSource, float volume, bool playLooped = false, uint fadeIn = 0, uint minDefferedStart = 0, uint maxDefferedStart = 0)
        {
            if (soundSource == null)
            {
                throw new ArgumentNullException();
            }

            ISoundVoice soundVoice = null;

            //Get an Idle voice ready to play a buffer
            if (GetVoice(soundSource, out soundVoice))
            {
                soundVoice.is3DSound         = false;
                soundVoice.IsLooping         = playLooped;
                soundVoice.PlayingDataSource = soundSource;
                if (maxDefferedStart == 0)
                {
                    soundVoice.PushDataSourceForPlaying();
                }
                soundVoice.RefreshVoices();
                soundVoice.MaxDefferedStart = maxDefferedStart;
                soundVoice.MinDefferedStart = minDefferedStart;
                soundVoice.Start(volume, fadeIn);
                if (playLooped || fadeIn > 0 || maxDefferedStart > 0)
                {
                    AddSoundWatching(soundVoice);
                }
            }
            else
            {
                logger.Warn("Sound playing skipped because no sound channel are IDLE : {0}", soundSource.Alias);
            }

            return(soundVoice);
        }
Esempio n. 2
0
        private bool GetVoice(ISoundDataSource dataSource2Bplayed, out ISoundVoice soundVoice)
        {
            //Get the soundqueue following SoundFormatCategory
            ISoundVoice[] voiceQueue;
            if (!_soundVoices.TryGetValue(dataSource2Bplayed.GetSoundFormatCategory(), out voiceQueue))
            {
                _soundVoices.Add(dataSource2Bplayed.GetSoundFormatCategory(), voiceQueue = new ISoundVoice[_maxVoicePoolPerFileType]);
            }

            //Check for a voice IDLE in the voice pool for this type of sound file.
            long        oldestTimerTick  = -1;
            ISoundVoice oldestSoundVoice = null;

            for (int i = 0; i < _maxVoicePoolPerFileType; i++)
            {
                soundVoice = voiceQueue[i];
                if (soundVoice == null)
                {
                    //logger.Info("NEW Voice Id : {0}, for queue {1} song playing {2}", i, dataSource2Bplayed.WaveFormat.ToString(), dataSource2Bplayed.SoundAlias);
                    soundVoice         = voiceQueue[i] = ToDispose(new SoundVoice(this, dataSource2Bplayed.WaveFormat, Voice_BufferEnd));
                    soundVoice.Id      = i + "  dataSource2Bplayed.WaveFormat.ToString()";
                    soundVoice.Emitter = new Emitter()
                    {
                        ChannelCount        = 1,
                        CurveDistanceScaler = float.MinValue
                    };
                    return(true); //Return a newly created voice
                }
                if (soundVoice.IsPlaying == false)
                {
                    //logger.Info("Reuse Voice Id {0}, for queue {1} song playing {2}", i, dataSource2Bplayed.WaveFormat.ToString(), dataSource2Bplayed.SoundAlias);

                    return(true);  //Return an already created voice, that was waiting to play a sound
                }
                else
                {
                    //If a priority is given, then try to find the oldest sound with lower or equal priority
                    if (dataSource2Bplayed.Priority > 0 && soundVoice.Priority <= dataSource2Bplayed.Priority)
                    {
                        if (oldestTimerTick < soundVoice.PlayingTime.ElapsedTicks)
                        {
                            oldestSoundVoice = soundVoice;
                            oldestTimerTick  = soundVoice.PlayingTime.ElapsedTicks;
                        }
                    }
                }
            }

            if (oldestSoundVoice != null)
            {
                oldestSoundVoice.Stop();
                soundVoice = oldestSoundVoice;
                return(true);
            }
            else
            {
                soundVoice = null;
                return(false);
            }
        }
Esempio n. 3
0
        public ISoundDataSource GetSoundSource(string soundAlias)
        {
            ISoundDataSource soundDataSource = null;

            _soundDataSources.TryGetValue(soundAlias, out soundDataSource);
            return(soundDataSource);
        }
Esempio n. 4
0
 public ISoundVoice StartPlay3D(ISoundDataSource soundSource, Vector3 position, bool playLooped = false, uint minDefferedStart = 0, uint maxDefferedStart = 0)
 {
     if (soundSource != null)
     {
         return(StartPlay3D(soundSource, position, soundSource.Volume, playLooped, minDefferedStart, maxDefferedStart));
     }
     return(null);
 }
Esempio n. 5
0
        public ISoundVoice StartPlay3D(ISoundDataSource soundSource, Vector3 position, float volume, bool playLooped = false, uint minDefferedStart = 0, uint maxDefferedStart = 0)
        {
            if (soundSource == null)
            {
                throw new ArgumentNullException();
            }

            ISoundVoice soundVoice = null;

            if (GetVoice(soundSource, out soundVoice))
            {
                soundVoice.Emitter.Position  = position;
                soundVoice.Emitter.OrientTop = Vector3.UnitY;
                soundVoice.Emitter.Velocity  = Vector3.Zero;

                soundVoice.is3DSound         = true;
                soundVoice.IsLooping         = playLooped;
                soundVoice.PlayingDataSource = soundSource;
                if (maxDefferedStart == 0)
                {
                    soundVoice.PushDataSourceForPlaying();
                }
                soundVoice.RefreshVoices();
                soundVoice.MaxDefferedStart = maxDefferedStart;
                soundVoice.MinDefferedStart = minDefferedStart;
                soundVoice.Start(volume);
                if (playLooped || maxDefferedStart > 0)
                {
                    AddSoundWatching(soundVoice);
                }
            }
            else
            {
                logger.Warn("Sound playing skipped because no sound channel are IDLE : {0}", soundSource.Alias);
            }

            return(soundVoice);
        }
Esempio n. 6
0
        public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
        {
            #region Load Derived classes sounds
            foreach (var data in _preLoad)
            {
                ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(data.Path, data.Alias, SourceCategory.FX, priority: data.Priority);
                if (dataSource != null)
                {
                    dataSource.Volume = data.Volume;
                    dataSource.Power  = data.Power;
                }
            }
            #endregion

            #region Load Steps sounds
            //Buffer cube walking sound
            foreach (var cube in _visualWorldParameters.WorldParameters.Configuration.GetAllCubesProfiles().Where(x => x.WalkingOverSound.Count > 0))
            {
                foreach (var walkingSound in cube.WalkingOverSound)
                {
                    RegisterStepSound(cube.Id, new SoundMetaData()
                    {
                        Path   = walkingSound.FilePath,
                        Alias  = walkingSound.Alias ?? Path.GetFileNameWithoutExtension(walkingSound.FilePath),
                        Volume = walkingSound.Volume,
                        Power  = walkingSound.Power
                    }
                                      );
                }
            }

            foreach (var pair in _stepsSounds)
            {
                foreach (var sound in pair.Value)
                {
                    ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(sound.Path, sound.Alias, SourceCategory.FX, priority: 100);
                    if (dataSource != null)
                    {
                        dataSource.Volume = sound.Volume;
                        dataSource.Power  = sound.Power;
                    }
                }
            }

            #endregion

            #region Load biome Ambiant sound

            //Prepare Sound for biomes ========================
            if (_biomesParams != null)
            {
                foreach (var biome in _biomesParams.Biomes)
                {
                    foreach (var biomeSound in biome.AmbientSound)
                    {
                        ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(biomeSound.FilePath, biomeSound.Alias, SourceCategory.Music, priority: biomeSound.Priority);
                        if (dataSource != null)
                        {
                            dataSource.Volume     = biomeSound.Volume;
                            dataSource.isStreamed = true;
                        }
                    }
                }
            }

            #endregion

            #region Mood Sound
            //Load and prefetch Mood sounds ========================
            foreach (var moodSoundFile in Directory.GetFiles(@"Sounds\Moods", "*_*.wma"))
            {
                TimeOfDaySound time;
                MoodType       type;
                string[]       fileMetaData = moodSoundFile.Replace(".wma", "").Split('_');
                if (fileMetaData.Length < 3)
                {
                    time = TimeOfDaySound.FullDay;
                }
                else
                {
                    switch (fileMetaData[2].ToLower())
                    {
                    case "day":
                        time = TimeOfDaySound.Day;
                        break;

                    case "night":
                        time = TimeOfDaySound.Night;
                        break;

                    default:
                        time = TimeOfDaySound.FullDay;
                        break;
                    }
                }

                switch (fileMetaData[1].ToLower())
                {
                case "fear":
                    type = MoodType.Fear;
                    break;

                case "peace":
                    type = MoodType.Peace;
                    break;

                case "dead":
                    type = MoodType.Dead;
                    break;

                default:
                    continue;
                }

                MoodsSoundSource soundSource = new MoodsSoundSource()
                {
                    Alias      = "Mood" + fileMetaData[0],
                    FilePath   = moodSoundFile,
                    Volume     = type == MoodType.Peace ? 0.1f : 0.6f,
                    isStreamed = true
                };

                if (time == TimeOfDaySound.FullDay)
                {
                    InsertMoodSound(soundSource, TimeOfDaySound.Day, type);
                    InsertMoodSound(soundSource, TimeOfDaySound.Night, type);
                }
                else
                {
                    InsertMoodSound(soundSource, time, type);
                }

                ISoundDataSource dataSource = _soundEngine.AddSoundSourceFromFile(soundSource.FilePath, soundSource.Alias, SourceCategory.Music);
                if (dataSource != null)
                {
                    dataSource.Volume = soundSource.Volume;
                    dataSource.Power  = soundSource.Power;
                }
            }
            #endregion

            base.LoadContent(context);
        }
Esempio n. 7
0
 public ISoundVoice StartPlay2D(ISoundDataSource soundSource, bool playLooped = false, uint fadeIn = 0, uint minDefferedStart = 0, uint maxDefferedStart = 0)
 {
     return(StartPlay2D(soundSource, soundSource.Volume, playLooped, fadeIn, minDefferedStart, maxDefferedStart));
 }
Esempio n. 8
0
 private void PrepareVoiceSource(ISoundDataSource playingDataSource)
 {
     PrepareVoiceSource(playingDataSource.WaveFormat);
 }