Esempio n. 1
0
        /// <summary>Read in an MTrk chunk from the stream.</summary>
        /// <param name="inputStream">The stream from which to read the MTrk chunk.</param>
        /// <returns>The MTrk chunk read.</returns>
        public static MTrkChunkHeader Read(Stream inputStream)
        {
            Validate.NonNull("inputStream", inputStream);

            // Read in a header from the stream and validate it
            ChunkHeader header = ChunkHeader.Read(inputStream);

            ValidateHeader(header);

            // Read in the amount of data specified in the chunk header
            byte[] data = new byte[header.Length];
            int    bytesRead;

            for (int offset = 0; offset < data.Length; offset += bytesRead)
            {
                if ((bytesRead = inputStream.Read(data, offset, data.Length - offset)) < 0)
                {
                    throw new InvalidOperationException("Not enough data in stream to fill MTrk chunk.");
                }
            }

            // Return the new chunk
            return(new MTrkChunkHeader(data));
        }
Esempio n. 2
0
 /// <summary>Initialize the MTrk chunk header.</summary>
 /// <param name="data">The track data for which this is a header.</param>
 public MTrkChunkHeader(byte[] data)
 {
     m_header = new ChunkHeader(MTrkID, data != null ? data.Length : 0);
     m_data   = data;
 }