示例#1
0
        /// <summary>
        /// Initialize the CueSheetTrack.
        /// </summary>
        /// <param name="data">The full data array.</param>
        /// <param name="dataOffset">Where the cuesheet track begins.</param>
        public CueSheetTrack(byte[] data, int dataOffset)
        {
            this.trackOffset   = BinaryDataHelper.GetUInt64(data, dataOffset);
            this.trackNumber   = (byte)BinaryDataHelper.GetUInt64(data, dataOffset + 8, 8);
            this.isrc          = System.Text.Encoding.ASCII.GetString(data, dataOffset + 9, 12).Trim(new char[] { '\0' });
            this.isAudioTrack  = !BinaryDataHelper.GetBoolean(data, dataOffset + 21, 1); // 0 for audio
            this.isPreEmphasis = BinaryDataHelper.GetBoolean(data, dataOffset + 21, 2);
            // 6 bits + 13 bytes need to be zero, won't check this
            byte indexPointCount = (byte)BinaryDataHelper.GetUInt64(data, dataOffset + 35, 8);

            if (indexPointCount > 100)
            {
                throw new FlacLibSharp.Exceptions.FlacLibSharpInvalidFormatException(string.Format("CueSheet track nr {0} has an invalid Track Index Count of {1}. Maximum allowed is 100.", this.TrackNumber, indexPointCount));
            }

            // For all tracks, except the lead-in track, one or more track index points
            dataOffset += 36;
            for (int i = 0; i < indexPointCount; i++)
            {
                this.IndexPoints.Add(new CueSheetTrackIndex(data, dataOffset));
                dataOffset += 12; // Index points are always 12 bytes long
            }

            if (indexPointCount != this.IndexPoints.Count)
            {
                // Should we be so strict?
                throw new FlacLibSharp.Exceptions.FlacLibSharpInvalidFormatException(string.Format("CueSheet track nr {0} indicates {1} index points, but actually {2} index points are present.", this.TrackNumber, indexPointCount, this.IndexPoints.Count));
            }
        }
示例#2
0
 /// <summary>
 /// Creates a new seekpoint.
 /// </summary>
 /// <param name="data"></param>
 public SeekPoint(byte[] data)
 {
     this.firstSampleNumber = BinaryDataHelper.GetUInt64(data, 0);
     this.byteOffset        = BinaryDataHelper.GetUInt64(data, 8);
     this.numberOfSamples   = BinaryDataHelper.GetUInt16(data, 16);
     ValidateIsPlaceholder();
 }
示例#3
0
        /// <summary>
        /// Loads a new stream info block from the provided data.
        /// </summary>
        /// <param name="data"></param>
        public override void LoadBlockData(byte[] data)
        {
            // "All numbers are big-endian coded and unsigned".

            // 1: Minimum Block Size (first 16-bit)
            this.minimumBlockSize = BinaryDataHelper.GetUInt16(data, 0);
            this.maximumBlockSize = BinaryDataHelper.GetUInt16(data, 2);
            this.minimumFrameSize = BinaryDataHelper.GetUInt24(data, 4);
            this.maximumFrameSize = BinaryDataHelper.GetUInt24(data, 7);
            // Interpret 20 bits starting from byte 10 as a UInt
            this.sampleRateHz  = (UInt32)BinaryDataHelper.GetUInt64(data, 10, 20);
            this.channels      = (short)(BinaryDataHelper.GetUInt64(data, 12, 3, 4) + 1);
            this.bitsPerSample = (short)(BinaryDataHelper.GetUInt64(data, 12, 5, 7) + 1);
            this.samples       = (long)BinaryDataHelper.GetUInt64(data, 13, 36, 4);
            this.md5Signature  = new byte[16];
            Array.Copy(data, 18, this.md5Signature, 0, 16);
        }
示例#4
0
        /// <summary>
        /// Parses the binary metadata from the flac file into a CueSheet object.
        /// </summary>
        /// <param name="data">The binary data from the flac file.</param>
        public override void LoadBlockData(byte[] data)
        {
            this.mediaCatalog      = Encoding.ASCII.GetString(data, 0, 128).Trim(new char[] { '\0' });
            this.leadInSampleCount = BinaryDataHelper.GetUInt64(data, 128);
            this.isCDCueSheet      = BinaryDataHelper.GetBoolean(data, 136, 0);
            // We're skipping 7 bits + 258 bytes which is reserved null data
            byte trackCount = data[395];

            if (trackCount > 100)
            {
                // Do we really need to throw an exception here?
                throw new Exceptions.FlacLibSharpInvalidFormatException(string.Format("CueSheet has invalid track count {0}. Cannot be more than 100.", trackCount));
            }

            int cueSheetTrackOffset = 396;

            for (int i = 0; i < trackCount; i++)
            {
                CueSheetTrack newTrack = new CueSheetTrack(data, cueSheetTrackOffset);
                cueSheetTrackOffset += 36 + (12 * newTrack.IndexPointCount); // 36 bytes for the cueSheetTrack and 12 bytes per index point ...
                this.Tracks.Add(newTrack);
            }
        }
 /// <summary>
 /// Creates a new Cue Sheet Track Index based on the binary data provided.
 /// </summary>
 /// <param name="data"></param>
 /// <param name="dataOffset">Where in the data array to start reading.</param>
 public CueSheetTrackIndex(byte[] data, int dataOffset)
 {
     this.offset           = BinaryDataHelper.GetUInt64(data, dataOffset);
     this.indexPointNumber = (byte)BinaryDataHelper.GetUInt64(data, dataOffset + 8, 8);
 }