private AudioHeader(ByteVector data, TagLib.File file, long position) { this.duration = TimeSpan.Zero; stream_length = 0; string error = GetHeaderError(data); if (error != null) { throw new CorruptFileException(error); } flags = data.ToUInt(); xing_header = XingHeader.Unknown; vbri_header = VBRIHeader.Unknown; file.Seek(position + XingHeader.XingHeaderOffset(Version, ChannelMode)); ByteVector xing_data = file.ReadBlock(16); if (xing_data.Count == 16 && xing_data.StartsWith(XingHeader.FileIdentifier)) { xing_header = new XingHeader(xing_data); } if (xing_header.Present) { return; } file.Seek(position + VBRIHeader.VBRIHeaderOffset()); ByteVector vbri_data = file.ReadBlock(24); if (vbri_data.Count == 24 && vbri_data.StartsWith(VBRIHeader.FileIdentifier)) { vbri_header = new VBRIHeader(vbri_data); } }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="AudioHeader" /> by reading its contents from a /// <see cref="ByteVector" /> object and its Xing Header from /// the appropriate location in the specified file. /// </summary> /// <param name="data"> /// A <see cref="ByteVector" /> object containing the header /// to read. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the Xing /// header from. /// </param> /// <param name="position"> /// A <see cref="long" /> value indicating the position in /// <paramref name="file" /> at which the header begins. /// </param> /// <exception cref="CorruptFileException"> /// <paramref name="data" /> is less than 4 bytes long, /// does not begin with a MPEG audio synch, has a negative /// bitrate, or has a sample rate of zero. /// </exception> private AudioHeader(ByteVector data, TagLib.File file, long position) { this.duration = TimeSpan.Zero; stream_length = 0; string error = GetHeaderError(data); if (error != null) { throw new CorruptFileException(error); } flags = data.ToUInt(); xing_header = XingHeader.Unknown; vbri_header = VBRIHeader.Unknown; // Check for a Xing header that will help us in // gathering information about a VBR stream. file.Seek(position + XingHeader.XingHeaderOffset( Version, ChannelMode)); ByteVector xing_data = file.ReadBlock(16); if (xing_data.Count == 16 && xing_data.StartsWith( XingHeader.FileIdentifier)) { xing_header = new XingHeader(xing_data); } if (xing_header.Present) { return; } // A Xing header could not be found, next chec for a // Fraunhofer VBRI header. file.Seek(position + VBRIHeader.VBRIHeaderOffset()); // Only get the first 24 bytes of the Header. // We're not interested in the TOC entries. ByteVector vbri_data = file.ReadBlock(24); if (vbri_data.Count == 24 && vbri_data.StartsWith(VBRIHeader.FileIdentifier)) { vbri_header = new VBRIHeader(vbri_data); } }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="AudioHeader" /> by reading its contents from a /// <see cref="ByteVector" /> object and its Xing Header from /// the appropriate location in the specified file. /// </summary> /// <param name="data"> /// A <see cref="ByteVector" /> object containing the header /// to read. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the Xing /// header from. /// </param> /// <param name="position"> /// A <see cref="long" /> value indicating the position in /// <paramref name="file" /> at which the header begins. /// </param> /// <exception cref="CorruptFileException"> /// <paramref name="data" /> is less than 4 bytes long, /// does not begin with a MPEG audio synch, has a negative /// bitrate, or has a sample rate of zero. /// </exception> private AudioHeader(ByteVector data, TagLib.File file, long position) { this.duration = TimeSpan.Zero; stream_length = 0; if (data.Count < 4) { throw new CorruptFileException( "Insufficient header length."); } if (data [0] != 0xFF) { throw new CorruptFileException( "First byte did not match MPEG synch."); } if (data [1] < 0xE0) { throw new CorruptFileException( "Second byte did not match MPEG synch."); } flags = data.ToUInt(); if (((flags >> 12) & 0x0F) == 0x0F) { throw new CorruptFileException( "Header uses invalid bitrate index."); } if (((flags >> 10) & 0x03) == 0x03) { throw new CorruptFileException( "Invalid sample rate."); } xing_header = XingHeader.Unknown; vbri_header = VBRIHeader.Unknown; // Check for a Xing header that will help us in // gathering information about a VBR stream. file.Seek(position + XingHeader.XingHeaderOffset( Version, ChannelMode)); ByteVector xing_data = file.ReadBlock(16); if (xing_data.Count == 16 && xing_data.StartsWith( XingHeader.FileIdentifier)) { xing_header = new XingHeader(xing_data); } if (xing_header.Present) { return; } // A Xing header could not be found, next chec for a // Fraunhofer VBRI header. file.Seek(position + VBRIHeader.VBRIHeaderOffset()); // Only get the first 24 bytes of the Header. // We're not interested in the TOC entries. ByteVector vbri_data = file.ReadBlock(24); if (vbri_data.Count == 24 && vbri_data.StartsWith(VBRIHeader.FileIdentifier)) { vbri_header = new VBRIHeader(vbri_data); } }