/// <summary>
        /// Creates a new empty frame.
        /// </summary>
        public MP3AudioFrame(byte[] data)
        {
            m_Data = data;
            Header = new MP3AudioFrameHeader(data);
            if (Header.Validation != MP3AudioFrameHeadervalidation.Valid)
            {
                throw new InvalidDataException();
            }

            var dataLength = Header.Length;

            if (dataLength == 0 || data.Length != dataLength)
            {
                throw new InvalidDataException();
            }
        }
        /// <summary>
        /// Parses the specified stream to load all fields for this instance.
        /// </summary>
        /// <param name="reader">FrameReader to read from.</param>
        public override bool Parse(DataFrameReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("Reader");
            }

            if (!reader.EnsureBuffer(4))
            {
                return(false);
            }

            var headerData = reader.Read(0, 4);

            Header = new MP3AudioFrameHeader(headerData);
            if (Header.Validation != MP3AudioFrameHeadervalidation.Valid)
            {
                return(false);
            }

            var dataLength = Header.Length;

            if (dataLength == 0)
            {
                return(false);
            }

            if (!reader.EnsureBuffer(dataLength))
            {
                return(false);
            }

            m_Data = reader.Read(0, dataLength);

            // check next header
            if (reader.EnsureBuffer(dataLength + 4))
            {
                var nextHeaderBuffer = reader.Read(dataLength, 4);
                var next             = new MP3AudioFrameHeader(nextHeaderBuffer);
                if (next.Validation != MP3AudioFrameHeadervalidation.Valid)
                {
                    if ((nextHeaderBuffer[0] == 'I') && (nextHeaderBuffer[1] == 'D') && (nextHeaderBuffer[2] == '3'))
                    {
                        // ID3 v2 tag incoming
                    }
                    else if ((nextHeaderBuffer[0] == 'T') && (nextHeaderBuffer[1] == 'A') && (nextHeaderBuffer[2] == 'G'))
                    {
                        // ID3 v1 tag incoming
                    }
                    else
                    {
                        // next header is invalid, check if the padding bit is set incorrectly
                        // there is a high pobability that the padding bit is invalid if
                        // the framestart is not directly after our buffer but one byte late
                        var newStart = dataLength + (Header.Padding ? -1 : 1);
                        nextHeaderBuffer = reader.Read(newStart, 4);
                        next             = new MP3AudioFrameHeader(nextHeaderBuffer);
                        if (next.Validation == MP3AudioFrameHeadervalidation.Valid)
                        {
                            if (!Header.Padding)
                            {
                                // frame has a padding byte but the header padding bit is not set
                                m_Data = reader.Read(0, newStart);
                            }
                            else
                            {
                                // frame has no padding byte but the header padding bit is set
                                m_Data = reader.Read(0, newStart);
                            }
                            InvalidPaddingCorrected = true;
                        }
                    }
                }
            }

            reader.Remove(m_Data.Length);
            return(true);
        }