Beispiel #1
0
        public static RiffHeader Parse(BinaryReader reader)
        {
            var header = new RiffHeader();

            header.ChunkId   = reader.ReadFourCc();
            header.ChunkSize = reader.ReadUInt32();
            header.Format    = reader.ReadFourCc();

            if (header.ChunkId != "RIFF" ||
                header.Format != "WAVE")
            {
                throw new InvalidDataException("Invalid or missing .wav file header!");
            }

            return(header);
        }
Beispiel #2
0
        public WaveDecoder(Stream s)
        {
            using (BinaryReader br = new BinaryReader(s))
            {
                _header = RiffHeader.Parse(br);
                _format = WaveFormat.Parse(br);

                if (_format.AudioFormat != WaveFormatType.Pcm)
                {
                    _fact = WaveFact.Parse(br);
                }

                _data = WaveData.Parse(br);
                var variant = WavParser.GetParser(_format.AudioFormat);

                _decodedData = variant.Parse(br, (int)_data.SubChunkSize, _format);

                _audioFormat.BitsPerSample = variant.BitsPerSample;
                _audioFormat.Channels      = _format.NumChannels;
                _audioFormat.SampleRate    = (int)_format.SampleRate;

                _numSamples = _samplesLeft = _decodedData.Length / _audioFormat.BytesPerSample;
            }
        }