/// <summary> /// Initializes a new instance of the <see cref="Music"/> class /// from specified <see cref="Stream"/> containing sound data. /// </summary> /// <param name="stream">A <see cref="Stream"/> contains sound data to load.</param> public Music(Stream stream) : this() { _reader = Decoders.CreateReader(stream); if (_reader == null) { throw new NotSupportedException("The specified sound is not supported."); } _info = _reader.Open(stream); Initialize(_info.ChannelCount, _info.SampleRate); }
private void Initialize(SoundReader reader, SampleInfo info) { // Retrieve the sound parameters long sampleCount = info.SampleCount; int channelCount = info.ChannelCount; int sampleRate = info.SampleRate; // Read the samples from the provided file using (reader) { _samples = new short[sampleCount]; if (reader.Read(_samples, sampleCount) == sampleCount) { // Update the internal buffer with the new samples Update(channelCount, sampleRate); } else { throw new Exception("Failed to decode the sound data."); } } }