Пример #1
0
        private void Update(int channelCount, int sampleRate)
        {
            // Check parameters
            if (channelCount <= 0 || sampleRate <= 0)
            {
                throw new ArgumentException();
            }

            // Find the best format according to the number of channels
            var format = AudioDevice.GetFormat(channelCount);

            if (format == 0)
            {
                throw new Exception("Failed to load sound buffer (unsupported number of channels: " + channelCount.ToString() + ")");
            }

            // First make a copy of the list of sounds so we can reattach later
            var sounds = new List <Sound>(_sounds);

            // Detach the buffer from the sounds that use it (to avoid OpenAL errors)
            foreach (var sound in sounds)
            {
                sound.ResetBuffer();
            }

            // fill the buffer
            int size = _samples.Length * sizeof(short);

            ALChecker.Check(() => AL.BufferData(_buffer, format, _samples, size, sampleRate));

            // Compute the duration
            _duration = TimeSpan.FromSeconds((float)_samples.Length / sampleRate / channelCount);

            // Now reattach the buffer to the sounds that use it
            foreach (var sound in sounds)
            {
                sound.Buffer = this;
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="SoundSystem"/>.
 /// </summary>
 public SoundSystem()
 {
     device   = AudioDevice.Instance;
     channels = new HashSet <SoundChannel>();
 }