Esempio n. 1
0
        public override void ChangeStream(Stream stream)
        {
            if (!stream.CanRead)
            {
                throw new ArgumentException("WavDecoder stream can not be read");
            }

            var header = WavHeader.Read(stream);

            if (header.AudioFormat != 1)
            {
                throw new ArgumentException("WavDecoder can not decode compressed wave");
            }

            var sampleSizeInBytes = header.BitsPerSample / 8;

            this.totalSamples = header.SubChunk2Size / sampleSizeInBytes;
            this.sampleRate   = (int)header.SampleRate;
            this.sampleSize   = header.BitsPerSample;
            this.channels     = header.NumChannels;

            if (this.sampleBuffer.Length % sampleSizeInBytes != 0)
            {
                var bufferSize = this.SampleBufferSize;
                Array.Resize(ref this.sampleBuffer, bufferSize + (bufferSize % sampleSizeInBytes));
            }

            this.stream?.Dispose();
            this.stream = stream;
        }