/// <summary> /// Create new Equalisation frame /// </summary> /// <param name="FrameID">4 characters frame identifer of current Frame class</param> /// <param name="Flags">Frame Flags</param> /// <param name="Data">TagStream to read frame from</param> /// <param name="Length">Maximum length to read frame</param> public Equalisation(string FrameID, FrameFlags Flags, int Length, Stream FS) : base(FrameID, Flags, FS) { _Frequensies = new FrameCollection <FrequencyAdjustmentFrame>("Frequency Adjustment"); TStream = new Macalifa.Tags.TagStreamUWP(FS); _AdjustmentBits = TStream.ReadByte(FS); Length--; if (_AdjustmentBits == 0) { ExceptionOccured(new ID3Exception("Adjustment bit of Equalisation is zero. this frame is invalid", FrameID, ExceptionLevels.Error)); return; } if (_AdjustmentBits % 8 != 0 || _AdjustmentBits > 32) { ExceptionOccured(new ID3Exception("AdjustmentBit of Equalisation Frame is out of supported range of this program", FrameID, ExceptionLevels.Error)); return; } int AdLen = _AdjustmentBits / 8; int FreqBuf; uint AdjBuf; while (Length > 3) { FreqBuf = Convert.ToInt32(TStream.ReadUInt(2)); AdjBuf = TStream.ReadUInt(AdLen); _Frequensies.Add(new FrequencyAdjustmentFrame(FreqBuf, AdjBuf)); Length -= 2 + AdLen; } }
/// <summary> /// Create new AudioEncryptionFrame /// </summary> /// <param name="FrameID">4 Characters tag identifier</param> /// <param name="Flags">2 Bytes flags identifier</param> /// <param name="Data">Contain Data for this frame</param> /// <param name="Length">Maximum available length for this frame</param> public AudioEncryptionFrame(string FrameID, FrameFlags Flags, int Length, Stream FS) : base(FrameID, Flags, FS) { TStream = new Macalifa.Tags.TagStreamUWP(FS); _Owner = TStream.ReadText(Length, TextEncodings.Ascii, ref Length, true); _PreviewStart = Convert.ToInt32(TStream.ReadUInt(2)); _PreviewLength = Convert.ToInt32(TStream.ReadUInt(2)); Length -= 4; _Data = TStream.ReadData(Length); }
/// <summary> /// Create new STempoCodes /// </summary> /// <param name="FrameID">4 Characters tag identifier</param> /// <param name="Flags">2 Bytes flags identifier</param> /// <param name="Data">Contain Data for this frame</param> /// <param name="Length"></param> public SynchronisedTempoFrame(string FrameID, FrameFlags Flags, int Length, Stream FS) : base(FrameID, Flags, FS) { _TempoCodes = new FrameCollection <TempoCode>("Temnpo Codes"); TStream = new Macalifa.Tags.TagStreamUWP(FS); _TimeStamp = (TimeStamps)TStream.ReadByte(FS); if (IsValidEnumValue(_TimeStamp, ExceptionLevels.Error, FrameID)) { return; } int Tempo; uint Time; while (Length > 4) { Tempo = TStream.ReadByte(FS); Length--; if (Tempo == 0xFF) { Tempo += TStream.ReadByte(FS); Length--; } Time = TStream.ReadUInt(4); Length -= 4; _TempoCodes.Add(new TempoCode(Tempo, Time)); } }
/// <summary> /// New SynchronisedText /// </summary> /// <param name="FrameID">FrameID</param> /// <param name="Flags">Frame Flag</param> /// <param name="Data">FileStream contain current frame data</param> /// <param name="Length">Maximum availabel length for this frame</param> public SynchronisedText(string FrameID, FrameFlags Flags, int Length, Stream FS) : base(FrameID, Flags, FS) { _Syllables = new FrameCollection <Syllable>("Syllables"); TStream = new Macalifa.Tags.TagStreamUWP(FS); TextEncoding = (TextEncodings)TStream.ReadByte(FS); if (!IsValidEnumValue(TextEncoding, ExceptionLevels.Error, FrameID)) { return; } Length--; Language = new Language(TStream.FS); Length -= 3; _TimeStamp = (TimeStamps)TStream.ReadByte(FS); if (!IsValidEnumValue(_TimeStamp, ExceptionLevels.Error, FrameID)) { return; } Length--; _ContentType = (ContentTypes)TStream.ReadByte(FS); if (!IsValidEnumValue(_ContentType)) { _ContentType = ContentTypes.Other; } Length--; // use Text variable for descriptor property Text = TStream.ReadText(Length, TextEncoding, ref Length, true); string tempText; uint tempTime; while (Length > 5) { tempText = TStream.ReadText(Length, TextEncoding, ref Length, true); tempTime = TStream.ReadUInt(4); _Syllables.Add(new Syllable(tempTime, tempText)); Length -= 4; } }
/// <summary> /// Create new EventTimingCodeFrame /// </summary> /// <param name="FrameID">FrameID</param> /// <param name="Flags">Flags of frame</param> /// <param name="Data">TagStream to read data from</param> /// <param name="Length">Maximum available length</param> public EventTimingCodeFrame(string FrameID, FrameFlags Flags, int Length, Stream FS) : base(FrameID, Flags, FS) { _Events = new FrameCollection <EventCode>("EventCode"); TStream = new Macalifa.Tags.TagStreamUWP(FS); _TimeStamp = (TimeStamps)TStream.ReadByte(FS); if (!IsValidEnumValue(_TimeStamp, ExceptionLevels.Error, FrameID)) { return; } Length--; while (Length >= 5) { _Events.Add(new EventCode(TStream.ReadByte(FS), TStream.ReadUInt(4))); Length -= 5; } }
/// <summary> /// Read all frames from specific FileStream /// </summary> /// <param name="Data">FileStream to read data from</param> /// <param name="Length">Length of data to read from FileStream</param> private void ReadFrames(int Length) { string FrameID; int FrameLength; FrameFlags Flags = new FrameFlags(); byte Buf; // If ID3v2 is ID3v2.2 FrameID, FrameLength of Frames is 3 byte // otherwise it's 4 character int FrameIDLen = Version.Minor == 2 ? 3 : 4; // Minimum frame size is 10 because frame header is 10 byte while (Length > 10) { // check for padding( 00 bytes ) Buf = TStream.ReadByte(TStream.FS); if (Buf == 0) { Length--; continue; } // if readed byte is not zero. it must read as FrameID TStream.FS.Seek(-1, SeekOrigin.Current); // ---------- Read Frame Header ----------------------- FrameID = TStream.ReadText(FrameIDLen, TextEncodings.Ascii); if (FrameIDLen == 3) { FrameID = FramesInfo.Get4CharID(FrameID); } try { var len = Convert.ToInt32(TStream.ReadUInt(FrameIDLen)); FrameLength = len; } catch { FrameLength = 0; } if (FrameIDLen == 4) { Flags = (FrameFlags)TStream.ReadUInt(2); } else { Flags = 0; // must set to default flag } long Position = TStream.FS.Position; if (Length > 0x10000000) { throw (new FileLoadException("This file contain frame that have more than 256MB data. This is not valid for ID3.")); } bool Added = false; if (IsAddable(FrameID)) // Check if frame is not filter { Added = AddFrame(FrameID, FrameLength, Flags, TStream.FS); } if (!Added) { // if don't read this frame // we must go forward to read next frame TStream.FS.Position = Position + FrameLength; } Length -= FrameLength + 10; // 10 for Frame Header header } }