/// <summary> /// Writes the metadata to the given stream. /// </summary> /// <param name="targetStream">The stream where the data will be written to.</param> public void WriteHeaderData(Stream targetStream) { byte data = this.isLastMetaDataBlock ? (byte)128 : (byte)0; // The 128 because the last metadata flag is the most significant bit set to 1 ... data += (byte)(this.typeID & 0x7F); // We make sure to chop off the last bit targetStream.WriteByte(data); // 24-bit metaDataBlockLength targetStream.Write(BinaryDataHelper.GetBytes((UInt64)this.metaDataBlockLength, 3), 0, 3); }
/// <summary> /// When overridden in a derived class, will write the data describing this metadata block to the given stream. /// </summary> /// <param name="targetStream">Stream to write the data to.</param> public override void WriteBlockData(Stream targetStream) { this.Header.WriteHeaderData(targetStream); targetStream.Write(BinaryDataHelper.GetBytesUInt16(this.minimumBlockSize), 0, 2); targetStream.Write(BinaryDataHelper.GetBytesUInt16(this.maximumBlockSize), 0, 2); targetStream.Write(BinaryDataHelper.GetBytes(this.minimumFrameSize, 3), 0, 3); targetStream.Write(BinaryDataHelper.GetBytes(this.maximumFrameSize, 3), 0, 3); // next are 64 bits containing: // * sample rate in Hz (20-bits) // * number of channels (3 bits) // * bits per sample (5 bits) // * total samples per stream (36 bits) UInt64 combinedData = (UInt64)this.SampleRateHz << 44; combinedData = combinedData + ((UInt64)(this.channels - 1) << 41); combinedData = combinedData + ((UInt64)(this.bitsPerSample - 1) << 36); combinedData = combinedData + (UInt64)this.samples; targetStream.Write(BinaryDataHelper.GetBytes(combinedData, 8), 0, 8); targetStream.Write(this.md5Signature, 0, 16); }