Ejemplo n.º 1
0
        private WavFileHeader ReadHeader()
        {
            var header = new WavFileHeader();

            ExpectString("RIFF");
            header.ChunkSize = ReadInt();
            ExpectString("WAVE");
            ExpectString("fmt ");
            header.Subchunk1Size = ReadInt();
            header.AudioFormat   = ReadShort();
            header.NumChannels   = ReadShort();
            header.SampleRate    = ReadInt();
            header.ByteRate      = ReadInt();
            header.BlockAlign    = ReadShort();
            header.BitsPerSample = ReadShort();
            if (header.Subchunk1Size > 16)
            {
                var extras = _reader.ReadBytes(header.Subchunk1Size - 16);
                Console.WriteLine($"Subchunk 1 had {extras.Length} extra bytes: [{string.Join(", ", extras)}]");
            }
            ExpectString("data");

            header.Subchunk2Size = ReadInt();

            foreach (var prop in typeof(WavFileHeader).GetProperties())
            {
                var val  = prop.GetValue(header);
                var name = prop.Name;
                Console.WriteLine($"  - {name.PadRight(20)} = {val}");
            }
            return(header);
        }
Ejemplo n.º 2
0
 public void WriteHeader(WavFileHeader header)
 {
     WriteString("RIFF");
     WriteInt(36); // No samples written yet
     WriteString("WAVE");
     WriteString("fmt ");
     WriteInt(header.Subchunk1Size);
     WriteShort(header.AudioFormat);
     WriteShort(header.NumChannels);
     WriteInt(header.SampleRate);
     WriteInt(header.ByteRate);
     WriteShort(header.BlockAlign);
     WriteShort(header.BitsPerSample);
     WriteString("data");
     WriteInt(0); // No samples written yet
 }
Ejemplo n.º 3
0
 public WavFileReader(string filename)
 {
     _reader = new BinaryFileReader(filename);
     _header = ReadHeader();
 }