コード例 #1
0
ファイル: AudioHeader.cs プロジェクト: DukeLupus/QuickList
 /// <summary>
 ///     Constructs and initializes a new instance of
 ///     <see
 ///         cref="AudioHeader" />
 ///     by populating it with specified
 ///     values.
 /// </summary>
 /// <param name="flags">
 ///     A <see cref="uint" /> value specifying flags for the new
 ///     instance.
 /// </param>
 /// <param name="streamLength">
 ///     A <see cref="long" /> value specifying the stream length
 ///     of the new instance.
 /// </param>
 /// <param name="xingHeader">
 ///     A <see cref="XingHeader" /> object representing the Xing
 ///     header associated with the new instance.
 /// </param>
 /// <param name="vbriHeader">
 ///     A <see cref="VBRIHeader" /> object representing the VBRI
 ///     header associated with the new instance.
 /// </param>
 private AudioHeader(uint flags, long streamLength,
                     XingHeader xingHeader,
                     VBRIHeader vbriHeader)
 {
     this.flags    = flags;
     stream_length = streamLength;
     XingHeader    = xingHeader;
     VBRIHeader    = vbriHeader;
     duration      = TimeSpan.Zero;
 }
コード例 #2
0
ファイル: AudioHeader.cs プロジェクト: DukeLupus/QuickList
        /// <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)
        {
            duration      = TimeSpan.Zero;
            stream_length = 0;

            var error = GetHeaderError(data);

            if (error != null)
            {
                throw new CorruptFileException(error);
            }

            flags = data.ToUInt();

            XingHeader = XingHeader.Unknown;

            VBRIHeader = 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));

            var xing_data = file.ReadBlock(16);

            if (xing_data.Count == 16 && xing_data.StartsWith(
                    XingHeader.FileIdentifier))
            {
                XingHeader = new XingHeader(xing_data);
            }

            if (XingHeader.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.
            var vbri_data = file.ReadBlock(24);

            if (vbri_data.Count == 24 &&
                vbri_data.StartsWith(VBRIHeader.FileIdentifier))
            {
                VBRIHeader = new VBRIHeader(vbri_data);
            }
        }