Example #1
0
        /// <summary>
        /// Creates a new WAVDataChunk from a binary reader.<para/>
        /// ENSURE YOU'RE CALLING IN THE RIGHT ORDER: WAVHeader =&gt; WAVFormatChunk =&gt; WAVDataChunk.
        /// </summary>
        /// <param name="reader">The <see cref="BinaryReader"/> to take the data from.</param>
        /// <returns></returns>
        public static WAVDataChunk CreateFromStream(BinaryReader reader, WAVFormatChunk fmtChunk)
        {
            WAVDataChunk data = new WAVDataChunk(fmtChunk);

            // Make sure we're in the right place.
            char[] id         = reader.ReadChars(4);
            string idAsString = string.Concat(id);

            while (idAsString != ID)
            {
                Console.WriteLine("Unexpected ID when trying to create format chunk (got [" + idAsString + "], expecting [" + ID + "] || CURRENT POS: " + reader.BaseStream.Position + ")");
                int size = reader.ReadInt32();
                reader.BaseStream.Seek(size, SeekOrigin.Current);
                id         = reader.ReadChars(4);
                idAsString = string.Concat(id);
            }

            uint length = reader.ReadUInt32();

            data.Data = new short[length / 2];
            byte[] raw = new byte[length];
            reader.Read(raw, 0, raw.Length);
            for (int i = 0; i < raw.Length; i += 2)
            {
                byte  b0  = raw[i];
                byte  b1  = raw[i + 1];
                short val = (short)((b1 << 8) + b0);
                data.Data[i / 2] = val;
            }
            return(data);
        }
Example #2
0
 /// <summary>
 /// Construct a new WEMHeader.
 /// </summary>
 /// <param name="dataChunk"></param>
 public WAVHeader(WAVDataChunk dataChunk)
 {
     DataChunk = dataChunk;
 }