Example #1
0
        /// <summary>
        /// Initializes a new instance of the MpegFrame class.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This class is a partial implementation of an MPEG audio frame.  The primary purpose of this class is to represent an Mpeg 1 Layer 3
        /// file or MP3 file for short. Many of the features not explicitly needed
        /// for audio rendering are omitted from the implementation.
        /// </para>
        /// <para>
        /// Data on this format is readily discoverable in many books as well as by
        /// searching for "MP3 Frame" in your favorite search engine. As always,
        /// Wikipedia is well stocked in all of these areas as well.
        /// </para>
        /// </remarks>
        /// <param name="frameHeader">Byte array containing 4 bytes representing an MPEG Layer 3 header.</param>
        public MpegFrame(byte[] frameHeader)
        {
            if (frameHeader == null)
            {
                throw new ArgumentNullException("frameHeader");
            }

            if (frameHeader.Length != 4)
            {
                throw new ArgumentException("Invalid frame header length.");
            }

            // Sync
            int value = BitTools.MaskBits(frameHeader, 0, 11);

            if (value != SyncValue)
            {
                throw new ArgumentException("Invalid sync value.");
            }

            this.Version           = ParseVersion(frameHeader);
            this.Layer             = ParseLayer(frameHeader);
            this.IsProtected       = BitTools.MaskBits(frameHeader, 15, 1) == 1 ? false : true;
            this.BitrateIndex      = BitTools.MaskBits(frameHeader, 16, 4);
            this.SamplingRateIndex = BitTools.MaskBits(frameHeader, 20, 2);
            this.Padding           = BitTools.MaskBits(frameHeader, 22, 1);
            //// Private Bit = BitTools.MaskBits(_mp3FrameHeader,8,1); //USELESS
            this.Channels = ParseChannel(frameHeader);
            //// Joint Mode = ParseJoitMode(_mp3FrameHeader); //Not used by  Mp3MSS
            //// CopyRight = BitTools.MaskBits(_mp3FrameHeader,3,1); //Not used by Mp3MSS
            //// Original = BitTools.MaskBits(_mp3FrameHeader,2,1); //Not used by Mp3MSS
            //// Emphasis = ParseEmphasis(_mp3FrameHeader); //Not used by Mp3MSS

            this.BitRate          = MpegFrame.CalculateBitRate(this.Version, this.Layer, this.BitrateIndex);
            this.SamplingRate     = MpegFrame.LookupSamplingRate(this.Version, this.SamplingRateIndex);
            this.FrameSize        = MpegFrame.CalculateFrameSize(this.Version, this.Layer, this.BitRate, this.SamplingRate, this.Padding);
            this.NumberOfChannels = (this.Channels == Channel.SingleChannel) ? 1 : 2;

            if ((this.Version == -1) || (this.Layer == -1) ||
                (this.BitrateIndex < 0) || (this.BitrateIndex >= 15) ||
                (this.SamplingRateIndex < 0) || (this.SamplingRateIndex >= 3))
            {
                throw new ArgumentException("Invalid header values");
            }

            // Add in the bytes we already read
            if (this.FrameSize <= 0)
            {
                throw new InvalidOperationException("MpegFrame's FrameSize must be greater than zero.");
            }
        }
Example #2
0
        /// <summary>
        /// Determines whether the specified Object is equal to the current Object
        /// </summary>
        /// <param name="obj">The object to compare with the current object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            MpegFrame other = obj as MpegFrame;

            if (other == null)
            {
                return(false);
            }

            return((this.Version == other.Version) &&
                   (this.Layer == other.Layer) &&
                   (this.SamplingRate == other.SamplingRate) &&
                   (this.Channels == other.Channels));
        }