Esempio n. 1
0
        /// <summary>
        /// Parses the audio output mode of this frame's audio data.
        /// </summary>
        /// <param name="frameHeader">The 4 byte header for this frame.</param>
        /// <returns>The audio output mode of this frame's audio data.</returns>
        private static Channel ParseChannel(byte[] frameHeader)
        {
            Channel channel;
            int     channelValue = BitTools.MaskBits(frameHeader, 24, 2);

            switch (channelValue)
            {
            case 3:
                channel = Channel.SingleChannel;
                break;

            case 2:
                channel = Channel.DualChannel;
                break;

            case 1:
                channel = Channel.JointStereo;
                break;

            case 0:
                channel = Channel.Stereo;
                break;

            default:
                channel = Channel.SingleChannel;     // ERROR CASE
                break;
            }

            return(channel);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses the version of the MPEG standard this frame header conforms to from the frame header.
        /// </summary>
        /// <param name="frameHeader"> The 4 byte header for this frame. </param>
        /// <returns>
        /// The version of the MPEG standard this frame conforms to.
        /// 1 = Mpeg 1
        /// 2 = Mpeg 2
        /// 3 = Mpeg 2.5
        /// </returns>
        private static int ParseVersion(byte[] frameHeader)
        {
            int version;
            int versionValue = BitTools.MaskBits(frameHeader, 11, 2);

            switch (versionValue)
            {
            case 3:
                version = 1;
                break;

            case 2:
                version = 2;
                break;

            case 0:
                version = 3;
                break;

            default:
                version = -1;       // ERROR
                break;
            }

            return(version);
        }
Esempio n. 3
0
        /// <summary>
        /// Parses which complexity layer of the MPEG standard this frame conforms to from the frame header.
        /// </summary>
        /// <param name="frameHeader">The 4 byte header for this frame.</param>
        /// <returns>The complexity layer this frame conforms to.</returns>
        private static int ParseLayer(byte[] frameHeader)
        {
            int layer;
            int layerValue = BitTools.MaskBits(frameHeader, 13, 2);

            switch (layerValue)
            {
            case 3:
                layer = 1;
                break;

            case 2:
                layer = 2;
                break;

            case 1:
                layer = 3;
                break;

            default:
                layer = -1;
                break;
            }

            return(layer);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the MpegFrame class.
        /// </summary>
        /// <param name="stream">
        /// A stream with its position at the SyncPoint of the header.
        /// </param>
        public MpegFrame(Stream stream)
        {
            long startPostion = stream.Position;

            byte[] frameHeader = new byte[FrameHeaderSize];

            // Guard against a read error
            if (stream.Read(frameHeader, 0, FrameHeaderSize) != FrameHeaderSize)
            {
                goto cleanup;
            }

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

            if (!(value == SyncValue))
            {
                goto cleanup;
            }

            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

            return;

cleanup:
            stream.Position = startPostion;
            frameHeader     = null;
            return;
        }