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

            header.ChunkId   = reader.ReadChars(4);
            header.ChunkSize = reader.ReadUInt32();
            header.Format    = reader.ReadChars(4);
            return(header);
        }
예제 #2
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);
        }
예제 #3
0
        public void Parse(BinaryReader reader)
        {
            _header = RiffHeader.Parse(reader);
            _format = WaveFormat.Parse(reader);

            // Every format except the original PCM format must have a fact chunk
            if ((AudioFormatType)_format.AudioFormat != AudioFormatType.Pcm)
            {
                _fact = WaveFact.Parse(reader);
            }

            _data   = WaveData.Parse(reader);
            _buffer = WavParser
                      .GetParser((AudioFormatType)_format.AudioFormat)
                      .Parse(reader, (int)_data.SubChunkSize, _format);
        }
예제 #4
0
        public void Parse(BinaryReader reader)
        {
            _header = RiffHeader.Parse(reader);

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

            _format = WaveFormat.Parse(reader);

            if (new string(_format.SubChunkID) != "fmt ")
            {
                throw new InvalidDataException("Invalid .wav file!");
            }

            if (_format.AudioFormat != 1)
            {
                throw new NotSupportedException("Invalid .wav compression!");
            }

            //probably a compressed format
            if (_format.SubChunkSize > 16)
            {
                reader.BaseStream.Seek(_format.SubChunkSize - 16, SeekOrigin.Current);
            }

            _data = WaveData.Parse(reader);

            if (new string(_data.SubChunkID) != "data")
            {
                throw new InvalidDataException("Invalid .wav file!");
            }

            _buffer = reader.ReadBytes((int)_data.SubChunkSize);
        }