Exemplo n.º 1
0
        /// <summary>
        /// Interprets the meta data block header.
        /// </summary>
        /// <param name="data"></param>
        protected void ParseData(byte[] data) {
            // Parses the 4 byte header data:
            // Bit 1:   Last-metadata-block flag: '1' if this block is the last metadata block before the audio blocks, '0' otherwise.
            // Bit 2-8: Block Type, 
            //  0 : STREAMINFO 
            //  1 : PADDING 
            //  2 : APPLICATION 
            //  3 : SEEKTABLE 
            //  4 : VORBIS_COMMENT 
            //  5 : CUESHEET 
            //  6 : PICTURE 
            //  7-126 : reserved 
            //  127 : invalid, to avoid confusion with a frame sync code
            // Next 3 bytes: Length (in bytes) of metadata to follow (does not include the size of the METADATA_BLOCK_HEADER)

            this.isLastMetaDataBlock = BinaryDataHelper.GetBoolean(data, 0, 0);

            typeID = data[0] & 0x7F;
            switch (typeID) {
                case 0:
                    this.type = MetadataBlockType.StreamInfo;
                    this.metaDataBlockLength = 34;
                    break;
                case 1:
                    this.type = MetadataBlockType.Padding;
                    break;
                case 2:
                    this.type = MetadataBlockType.Application;
                    break;
                case 3:
                    this.type = MetadataBlockType.Seektable;
                    break;
                case 4:
                    this.type = MetadataBlockType.VorbisComment;
                    break;
                case 5:
                    this.type = MetadataBlockType.CueSheet;
                    break;
                case 6:
                    this.type = MetadataBlockType.Picture;
                    break;
            }
            if (typeID > 6 && typeID < 127) {
                this.type = MetadataBlockType.None;
            } else if(typeID >= 127) {
                this.type = MetadataBlockType.Invalid;
            }

            this.metaDataBlockLength = (BinaryDataHelper.GetUInt24(data, 1));
        }
Exemplo n.º 2
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);
        }