Ejemplo n.º 1
0
        private static Channel ParseChannel(byte[] frameHeader)
        {
            Channel channel;

            switch (BitTools.MaskBits(frameHeader, 24, 2))
            {
            case 0:
                channel = Channel.Stereo;
                break;

            case 1:
                channel = Channel.JointStereo;
                break;

            case 2:
                channel = Channel.DualChannel;
                break;

            case 3:
                channel = Channel.SingleChannel;
                break;

            default:
                channel = Channel.SingleChannel;
                break;
            }
            return(channel);
        }
Ejemplo n.º 2
0
        public MpegFrame(Stream stream, byte[] data)
        {
            this.frameHeader = new byte[4];
            if (data != null)
            {
                for (int index = 0; index < this.frameHeader.Length; ++index)
                {
                    this.frameHeader[index] = data[index];
                }
            }
            else if (stream.Read(this.frameHeader, 0, 4) != 4)
            {
                goto label_7;
            }
            if (BitTools.MaskBits(this.frameHeader, 0, 11) == 2047)
            {
                this.Version           = MpegFrame.ParseVersion(this.frameHeader);
                this.Layer             = MpegFrame.ParseLayer(this.frameHeader);
                this.IsProtected       = BitTools.MaskBits(this.frameHeader, 15, 1) != 1;
                this.BitrateIndex      = BitTools.MaskBits(this.frameHeader, 16, 4);
                this.SamplingRateIndex = BitTools.MaskBits(this.frameHeader, 20, 2);
                this.Padding           = BitTools.MaskBits(this.frameHeader, 22, 1);
                this.Channels          = MpegFrame.ParseChannel(this.frameHeader);
                return;
            }
label_7:
            this.frameHeader = (byte[])null;
        }
Ejemplo 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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a string representing the structure in little-endian
        /// hexadecimal format.
        /// </summary>
        /// <remarks>
        /// The string generated here is intended to be passed as
        /// CodecPrivateData for Silverlight 2's MediaStreamSource
        /// </remarks>
        /// <returns>
        /// A string representing the structure in little-endia hexadecimal
        /// format.
        /// </returns>
        public string ToHexString()
        {
            string s = WaveFormatExtensible.ToHexString();

            char[] mpeglayer3Data = new char[6 * 4];
            BitTools.ToHexHelper(4, this.Id, 0, mpeglayer3Data);
            BitTools.ToHexHelper(8, this.BitratePaddingMode, 4, mpeglayer3Data);
            BitTools.ToHexHelper(4, this.BlockSize, 12, mpeglayer3Data);
            BitTools.ToHexHelper(4, this.FramesPerBlock, 16, mpeglayer3Data);
            BitTools.ToHexHelper(4, this.CodecDelay, 20, mpeglayer3Data);
            return(s + new string(mpeglayer3Data));
        }
Ejemplo n.º 6
0
 public string ToHexString()
 {
     char[] chars = new char[36];
     BitTools.ToHexHelper((byte)4, (long)this.FormatTag, 0, chars);
     BitTools.ToHexHelper((byte)4, (long)this.Channels, 4, chars);
     BitTools.ToHexHelper((byte)8, (long)this.SamplesPerSec, 8, chars);
     BitTools.ToHexHelper((byte)8, (long)this.AverageBytesPerSecond, 16, chars);
     BitTools.ToHexHelper((byte)4, (long)this.BlockAlign, 24, chars);
     BitTools.ToHexHelper((byte)4, (long)this.BitsPerSample, 28, chars);
     BitTools.ToHexHelper((byte)4, (long)this.ExtraDataSize, 32, chars);
     return(new string(chars));
 }
 /// <summary>
 /// Returns a string representing the structure in little-endian
 /// hexadecimal format.
 /// </summary>
 /// <remarks>
 /// The string generated here is intended to be passed as
 /// CodecPrivateData for Silverlight 2's MediaStreamSource
 /// </remarks>
 /// <returns>
 /// A string representing the structure in little-endia hexadecimal
 /// format.
 /// </returns>
 public string ToHexString()
 {
     char[] data = new char[9 * 4];
     BitTools.ToHexHelper(4, this.FormatTag, 0, data);
     BitTools.ToHexHelper(4, this.Channels, 4, data);
     BitTools.ToHexHelper(8, this.SamplesPerSec, 8, data);
     BitTools.ToHexHelper(8, this.AverageBytesPerSecond, 16, data);
     BitTools.ToHexHelper(4, this.BlockAlign, 24, data);
     BitTools.ToHexHelper(4, this.BitsPerSample, 28, data);
     BitTools.ToHexHelper(4, this.ExtraDataSize, 32, data);
     return(new string(data));
 }
Ejemplo n.º 8
0
 public static int FindBytePattern(byte[] data, byte[] pattern, int startIndex)
 {
     if (pattern == null)
     {
         throw new ArgumentNullException("pattern");
     }
     byte[] mask = new byte[pattern.Length];
     for (int index = 0; index < pattern.Length; ++index)
     {
         mask[index] = byte.MaxValue;
     }
     return(BitTools.FindBitPattern(data, pattern, mask, startIndex));
 }
Ejemplo n.º 9
0
        public string ToHexString()
        {
            string hexString = this.WaveFormatExtensible.ToHexString();

            char[] chars = new char[24];
            BitTools.ToHexHelper((byte)4, (long)this.Id, 0, chars);
            BitTools.ToHexHelper((byte)8, (long)this.BitratePaddingMode, 4, chars);
            BitTools.ToHexHelper((byte)4, (long)this.BlockSize, 12, chars);
            BitTools.ToHexHelper((byte)4, (long)this.FramesPerBlock, 16, chars);
            BitTools.ToHexHelper((byte)4, (long)this.CodecDelay, 20, chars);
            string str = new string(chars);

            return(hexString + str);
        }
Ejemplo n.º 10
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>
        /// <param name="data">
        /// The first 4 bytes of the audiostream. This should contain the MpegFrame's
        /// header data.
        /// </param>
        public MpegFrame(Stream stream, byte[] data)
        {
            this.frameHeader = new byte[FrameHeaderSize];

            if (data != null)
            {
                for (int i = 0; i < this.frameHeader.Length; i++)
                {
                    this.frameHeader[i] = data[i];
                }
            }
            else
            {
                // Guard against a read error
                if (stream.Read(this.frameHeader, 0, FrameHeaderSize) != FrameHeaderSize)
                {
                    goto cleanup;
                }
            }

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

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

            this.Version           = ParseVersion(this.frameHeader);
            this.Layer             = ParseLayer(this.frameHeader);
            this.IsProtected       = BitTools.MaskBits(this.frameHeader, 15, 1) == 1 ? false : true;
            this.BitrateIndex      = BitTools.MaskBits(this.frameHeader, 16, 4);
            this.SamplingRateIndex = BitTools.MaskBits(this.frameHeader, 20, 2);
            this.Padding           = BitTools.MaskBits(this.frameHeader, 22, 1);
            //// Private Bit = BitTools.MaskBits(_mp3FrameHeader,8,1); //USELESS
            this.Channels = ParseChannel(this.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:
            this.frameHeader = null;
            return;
        }
Ejemplo n.º 11
0
        private static int ParseLayer(byte[] frameHeader)
        {
            int num;

            switch (BitTools.MaskBits(frameHeader, 13, 2))
            {
            case 1:
                num = 3;
                break;

            case 2:
                num = 2;
                break;

            case 3:
                num = 1;
                break;

            default:
                num = -1;
                break;
            }
            return(num);
        }
Ejemplo n.º 12
0
 public static int FindBytePattern(byte[] data, byte[] pattern)
 {
     return(BitTools.FindBytePattern(data, pattern, 0));
 }
Ejemplo n.º 13
0
 public static int FindBitPattern(byte[] data, byte[] pattern, byte[] mask)
 {
     return(BitTools.FindBitPattern(data, pattern, mask, 0));
 }