Example #1
0
        public void PlaySound(string soundName)
        {
            AudioBuffer buffer = null;

            AudioEvent ev = Game.ContentManager.IniDataContext.AudioEvents.Find(x => x.Name == soundName);

            string[] paths     = { _settings.AudioRoot, _settings.SoundsFolder, ev.Sounds[0] };
            string   soundPath = Path.Combine(paths);

            soundPath = Path.ChangeExtension(soundPath, _settings.SoundsExtension);

            if (!_files.ContainsKey(soundPath))
            {
                var file = Game.ContentManager.Load <WavFile>(soundPath);
                buffer            = AddDisposable(new AudioBuffer(file));
                _files[soundPath] = buffer;
            }
            else
            {
                buffer = _files[soundPath];
            }

            var source = AddDisposable(new AudioSource(buffer));

            if (ev.Control.HasFlag(AudioControlFlags.Loop))
            {
                source.Looping = true;
            }

            //set the volume of the sound
            source.Volume = ev.Volume;

            _sources.Add(source);
            source.Play();
        }
Example #2
0
        private FileSystemEntry ResolveAudioEventPath(AudioEvent ev)
        {
            // TODO: Try to remove these allocations.

            // TOOD: Check control flag before choosing at random?
            var soundFileName = $"{ev.Sounds[_random.Next(ev.Sounds.Length)]}.{_settings.SoundsExtension}";
            var isLocalised   = ev.Type?.Get(AudioTypeFlags.Voice) ?? false;
            var filePath      = Path.Combine(isLocalised ? _localisedAudioRoot : _audioRoot, soundFileName);

            return(Game.ContentManager.FileSystem.GetFile(filePath));
        }
Example #3
0
        private FileSystemEntry ResolveAudioEventEntry(AudioEvent ev)
        {
            if (ev.Sounds.Length == 0)
            {
                return(null);
            }

            // TOOD: Check control flag before choosing at random.
            var sound = ev.Sounds[_random.Next(ev.Sounds.Length)];

            return(sound.AudioFile.Value?.Entry);
        }
Example #4
0
        internal static AudioEvent ParseAsset(BinaryReader reader, Asset asset, AssetImportCollection imports)
        {
            var result = new AudioEvent();

            result.SetNameAndInstanceId(asset);

            ParseAsset(reader, result);

            result.Attack = reader.ReadArrayAtOffset(() => new LazyAssetReference <AudioFileWithWeight>(AudioFileWithWeight.ParseAsset(reader, imports)));
            result.Sounds = reader.ReadArrayAtOffset(() => new LazyAssetReference <AudioFileWithWeight>(AudioFileWithWeight.ParseAsset(reader, imports)));
            result.Decay  = reader.ReadArrayAtOffset(() => new LazyAssetReference <AudioFileWithWeight>(AudioFileWithWeight.ParseAsset(reader, imports)));

            return(result);
        }