public void ParseHeader(byte[] headerBytes) { bool [] boolHeader = BitReader.ToBitBools(headerBytes); ParseVersion(boolHeader[11], boolHeader[12]); ParseLayer(boolHeader[13], boolHeader[14]); this.Protection = boolHeader[15]; ParseBitRate(boolHeader[16], boolHeader[17], boolHeader[18], boolHeader[19]); ParseFrequency(boolHeader[20], boolHeader[21]); this.Padding = boolHeader[22]; this.Private = boolHeader[23]; ParseChannelMode(boolHeader[24], boolHeader[25]); ParseModeExtension(boolHeader[26], boolHeader[27]); this.CopyRight = boolHeader[28]; this.Original = boolHeader[29]; ParseEmphasis(boolHeader[30], boolHeader[31]); }
private void ReadExtendedHeader() { // Extended header size 4 * %0xxxxxxx // Number of flag bytes $01 // Extended Flags $xx // Where the 'Extended header size' is the size of the whole extended header, stored as a 32 bit synchsafe integer. // read teh size // this code is courtesy of Daniel E. White w/ minor modifications by me Thanx Dan //Dan Code char[] extHeaderSize = br.ReadChars(4); // I use this to read the bytes in from the file int[] bytes = new int[4]; // for bit shifting ulong newSize = 0; // for the final number // The ID3v2 tag size is encoded with four bytes // where the most significant bit (bit 7) // is set to zero in every byte, // making a total of 28 bits. // The zeroed bits are ignored // // Some bit grinding is necessary. Hang on. bytes[3] = extHeaderSize[3] | ((extHeaderSize[2] & 1) << 7); bytes[2] = ((extHeaderSize[2] >> 1) & 63) | ((extHeaderSize[1] & 3) << 6); bytes[1] = ((extHeaderSize[1] >> 2) & 31) | ((extHeaderSize[0] & 7) << 5); bytes[0] = ((extHeaderSize[0] >> 3) & 15); newSize = ((UInt64)10 + (UInt64)bytes[3] | ((UInt64)bytes[2] << 8) | ((UInt64)bytes[1] << 16) | ((UInt64)bytes[0] << 24)); //End Dan Code this.extHeaderSize = newSize; // next we read the number of flag bytes this.extNumFlagBytes = System.Convert.ToInt32(br.ReadByte()); // read the flag byte(s) and set the flags bool[] extFlags = BitReader.ToBitBools(br.ReadBytes(this.extNumFlagBytes)); this.EB_Update = extFlags[1]; this.EC_CRC = extFlags[2]; this.ED_Restrictions = extFlags[3]; // check for flags if (this.EB_Update) { // this tag has no data but will have a null byte so we need to read it in //Flag data length $00 br.ReadByte(); } if (this.EC_CRC) { // Flag data length $05 // Total frame CRC 5 * %0xxxxxxx // read the first byte and check to make sure it is 5. if not the header is corrupt // we will still try to process but we may be funked. int extC_FlagDataLength = System.Convert.ToInt32(br.ReadByte()); if (extC_FlagDataLength == 5) { extHeaderSize = br.ReadChars(5); // I use this to read the bytes in from the file bytes = new int[4]; // for bit shifting newSize = 0; // for the final number // The ID3v2 tag size is encoded with four bytes // where the most significant bit (bit 7) // is set to zero in every byte, // making a total of 28 bits. // The zeroed bits are ignored // // Some bit grinding is necessary. Hang on. bytes[4] = extHeaderSize[4] | ((extHeaderSize[3] & 1) << 7); bytes[3] = ((extHeaderSize[3] >> 1) & 63) | ((extHeaderSize[2] & 3) << 6); bytes[2] = ((extHeaderSize[2] >> 2) & 31) | ((extHeaderSize[1] & 7) << 5); bytes[1] = ((extHeaderSize[1] >> 3) & 15) | ((extHeaderSize[0] & 15) << 4); bytes[0] = ((extHeaderSize[0] >> 4) & 7); newSize = ((UInt64)10 + (UInt64)bytes[4] | ((UInt64)bytes[3] << 8) | ((UInt64)bytes[2] << 16) | ((UInt64)bytes[1] << 24) | ((UInt64)bytes[0] << 32)); this.extHeaderSize = newSize; } else { // we are f****d. do something } } if (this.ED_Restrictions) { // Flag data length $01 //Restrictions %ppqrrstt // advance past flag data lenght byte br.ReadByte(); this.extD_Restrictions = br.ReadByte(); } }