예제 #1
0
        /// <summary>
        /// Opens a cached audio file. Usually used for small audio files (.wav)
        /// </summary>
        public AudioSource GetSound(FileSystemEntry entry, bool loop = false)
        {
            AudioBuffer buffer;

            if (!_cached.ContainsKey(entry.FilePath))
            {
                var    decoder = new WaveDecoder(entry.Open());
                byte[] data    = null;
                decoder.GetSamples(ref data);

                buffer = AddDisposable(_engine.CreateBuffer());
                buffer.BufferData(data, decoder.Format);

                _cached[entry.FilePath] = buffer;
            }
            else
            {
                buffer = _cached[entry.FilePath];
            }

            var source = AddDisposable(_engine.CreateSource());

            source.QueryBuffer(buffer);
            // TODO: Implement looping

            _sources.Add(source);

            return(source);
        }
예제 #2
0
        /// <summary>
        /// Opens a cached audio file. Usually used for small audio files (.wav)
        /// </summary>
        public AudioSource GetSound(FileSystemEntry entry,
                                    AudioVolumeSlider?vslider = AudioVolumeSlider.None, bool loop = false)
        {
            AudioBuffer buffer;

            if (!_cached.ContainsKey(entry.FilePath))
            {
                var    decoder = new WaveDecoder(entry.Open());
                byte[] data    = null;
                decoder.GetSamples(ref data);

                buffer = AddDisposable(_engine.CreateBuffer());
                buffer.BufferData(data, decoder.Format);

                _cached[entry.FilePath] = buffer;
            }
            else
            {
                buffer = _cached[entry.FilePath];
            }

            var mixer = (vslider.HasValue && vslider.Value != AudioVolumeSlider.None) ?
                        _mixers[vslider.Value] : null;
            var source = AddDisposable(_engine.CreateSource(mixer));

            source.QueueBuffer(buffer);
            // TODO: Implement looping

            _sources.Add(source);

            return(source);
        }