This struct implements IAudioCodec to provide support for reading DSF stream properties.
Esempio n. 1
0
        /// <summary>
        ///    Reads the contents of the current instance determining
        ///    the size of the dsf data, the area the tagging is in,
        ///    and optionally reading in the tags and media properties.
        /// </summary>
        /// <param name="read_tags">
        ///    If <see langword="true" />, any tags found will be read
        ///    into the current instance.
        /// </param>
        /// <param name="style">
        ///    A <see cref="ReadStyle"/> value specifying how the media
        ///    data is to be read into the current instance.
        /// </param>
        /// <param name="dsf_size">
        ///    A <see cref="uint"/> value reference to be filled with
        ///    the size of the RIFF data as read from the file.
        /// </param>
        /// <param name="tag_start">
        ///    A <see cref="long" /> value reference to be filled with
        ///    the absolute seek position at which the tagging data
        ///    starts.
        /// </param>
        /// <param name="tag_end">
        ///    A <see cref="long" /> value reference to be filled with
        ///    the absolute seek position at which the tagging data
        ///    ends.
        /// </param>
        /// <exception cref="CorruptFileException">
        ///    The file does not begin with <see cref="FileIdentifier"
        ///    />.
        /// </exception>
        private void Read(bool read_tags, ReadStyle style,
                          out uint dsf_size, out long tag_start,
                          out long tag_end)
        {
            Seek(0);
            if (ReadBlock(4) != FileIdentifier)
            {
                throw new CorruptFileException(
                          "File does not begin with DSF identifier");
            }

            Seek(12);
            dsf_size = ReadBlock(8).ToUInt(false);

            tag_start = (long)ReadBlock(8).ToULong(false);
            tag_end   = -1;

            // Get the properties of the file
            if (header_block == null &&
                style != ReadStyle.None)
            {
                long fmt_chunk_pos = Find(FormatIdentifier, 0);

                if (fmt_chunk_pos == -1)
                {
                    throw new CorruptFileException(
                              "No Format chunk available in DSF file.");
                }

                Seek(fmt_chunk_pos);
                header_block = ReadBlock((int)StreamHeader.Size);

                StreamHeader header = new StreamHeader(header_block, dsf_size);
                properties = new Properties(TimeSpan.Zero, header);
            }

            // Now position to the ID3 chunk, which we read before
            if (tag_start > 0)
            {
                Seek(tag_start);
                if (ReadBlock(3) == ID3Identifier)
                {
                    if (read_tags && tag == null)
                    {
                        tag = new Id3v2.Tag(this, tag_start, style);
                    }

                    // Get the length of the tag out of the ID3 chunk
                    Seek(tag_start + 6);
                    uint tag_size = SynchData.ToUInt(ReadBlock(4)) + 10;

                    InvariantStartPosition = tag_start;
                    tag_end = InvariantEndPosition = tag_start + tag_size;
                }
            }
        }
Esempio n. 2
0
		/// <summary>
		///    Reads the contents of the current instance determining
		///    the size of the dsf data, the area the tagging is in,
		///    and optionally reading in the tags and media properties.
		/// </summary>
		/// <param name="read_tags">
		///    If <see langword="true" />, any tags found will be read
		///    into the current instance.
		/// </param>
		/// <param name="style">
		///    A <see cref="ReadStyle"/> value specifying how the media
		///    data is to be read into the current instance.
		/// </param>
		/// <param name="dsf_size">
		///    A <see cref="uint"/> value reference to be filled with
		///    the size of the RIFF data as read from the file.
		/// </param>
		/// <param name="tag_start">
		///    A <see cref="long" /> value reference to be filled with
		///    the absolute seek position at which the tagging data
		///    starts.
		/// </param>
		/// <param name="tag_end">
		///    A <see cref="long" /> value reference to be filled with
		///    the absolute seek position at which the tagging data
		///    ends.
		/// </param>
		/// <exception cref="CorruptFileException">
		///    The file does not begin with <see cref="FileIdentifier"
		///    />.
		/// </exception>
		private void Read(bool read_tags, ReadStyle style,
							out uint dsf_size, out long tag_start,
							out long tag_end)
		{
			Seek(0);
			if (ReadBlock(4) != FileIdentifier)
				throw new CorruptFileException(
					"File does not begin with DSF identifier");

			Seek(12);
			dsf_size = ReadBlock(8).ToUInt(false);

			tag_start = (long)ReadBlock(8).ToULong(false);
			tag_end = -1;

			// Get the properties of the file
			if (header_block == null &&
				style != ReadStyle.None)
			{
				long fmt_chunk_pos = Find(FormatIdentifier, 0);

				if (fmt_chunk_pos == -1)
				{
					throw new CorruptFileException(
						"No Format chunk available in DSF file.");
				}

				Seek(fmt_chunk_pos);
				header_block = ReadBlock((int) StreamHeader.Size);

				StreamHeader header = new StreamHeader(header_block, dsf_size);
				properties = new Properties(TimeSpan.Zero, header);
			}

			// Now position to the ID3 chunk, which we read before
			if (tag_start > 0)
			{
				Seek(tag_start);
				if (ReadBlock(3) == ID3Identifier)
				{
					if (read_tags && tag == null)
					{
						tag = new Id3v2.Tag(this, tag_start);
					}

					// Get the length of the tag out of the ID3 chunk
					Seek(tag_start + 6);
					uint tag_size = SynchData.ToUInt(ReadBlock(4)) + 10;

					InvariantStartPosition = tag_start;
					tag_end = InvariantEndPosition = tag_start + tag_size;
				}
			}
		}