コード例 #1
0
        public void Configure(IAudioFrameHeader frameHeader)
        {
            Mp3FrameHeader       mp3FrameHeader    = (Mp3FrameHeader)frameHeader;
            MpegLayer3WaveFormat layer3WaveFormat1 = new MpegLayer3WaveFormat();

            layer3WaveFormat1.nChannels       = (ushort)mp3FrameHeader.Channels;
            layer3WaveFormat1.nSamplesPerSec  = (uint)frameHeader.SamplingFrequency;
            layer3WaveFormat1.nAvgBytesPerSec = (uint)mp3FrameHeader.Bitrate / 8U;
            layer3WaveFormat1.nBlockSize      = (ushort)frameHeader.FrameLength;
            MpegLayer3WaveFormat layer3WaveFormat2 = layer3WaveFormat1;

            this.CodecPrivateData  = WaveFormatExExtensions.ToCodecPrivateData((WaveFormatEx)layer3WaveFormat2);
            this.Channels          = (int)layer3WaveFormat2.nChannels;
            this.SamplingFrequency = frameHeader.SamplingFrequency;
            this.Bitrate           = new int?(mp3FrameHeader.Bitrate);
            this.Name = frameHeader.Name;
            this.SetConfigured();
        }
コード例 #2
0
        public bool Parse(byte[] buffer, int index, int length, bool verbose = false)
        {
            this.MarkerIndex  = new int?();
            this.HeaderOffset = 0;
            if (length < 4)
            {
                return(false);
            }
            int  num1 = index;
            int  num2 = index + length;
            int  num3;
            byte num4;

            do
            {
                bool flag = true;
                do
                {
                    flag = true;
                    if (index + 4 <= num2)
                    {
                        num3 = index;
                    }
                    else
                    {
                        goto label_3;
                    }
                }while ((int)byte.MaxValue != (int)buffer[index++]);
                if (index + 3 <= num2)
                {
                    num4 = buffer[index++];
                }
                else
                {
                    goto label_7;
                }
            }while (7 != ((int)num4 >> 5 & 7));
            goto label_10;
label_3:
            return(false);

label_7:
            return(false);

label_10:
            this.HeaderOffset = index - num1 - 2;
            if (this.HeaderOffset < 0)
            {
                return(false);
            }
            this.MarkerIndex = new int?(num3);
            int index1 = (int)num4 >> 3 & 3;

            if (1 == index1)
            {
                return(false);
            }
            int version = 1;

            if (0 == (index1 & 1))
            {
                version = (index1 & 2) == 0 ? 3 : 2;
            }
            int index2 = (int)num4 >> 1 & 3;

            if (index2 < 1)
            {
                return(false);
            }
            int layer = 4 - index2;

            this.HeaderLength = 0 == ((int)num4 & 1) ? 6 : 4;
            byte num5         = buffer[index++];
            int  bitrateIndex = (int)num5 >> 4 & 15;
            int  bitrate      = Mp3FrameHeader.GetBitrate(version, layer, bitrateIndex);

            if (bitrate < 1)
            {
                return(false);
            }
            int sampleIndex = (int)num5 >> 2 & 3;
            int sampleRate  = Mp3FrameHeader.GetSampleRate(version, sampleIndex);

            if (sampleRate <= 0)
            {
                return(false);
            }
            bool paddingFlag = 0 != ((int)num5 >> 1 & 1);
            bool flag1       = 0 != ((int)num5 & 1);
            byte num6        = buffer[index++];
            int  num7        = (int)num6 >> 6 & 3;
            int  num8        = (int)num6 >> 4 & 3;
            int  num9        = (int)num6 >> 3 & 1;
            int  num10       = (int)num6 >> 2 & 1;
            int  num11       = (int)num6 & 3;

            if (this.ChannelMode != num7)
            {
                this.ChannelMode = num7;
                this.Name        = (string)null;
            }
            int num12 = num7 == 3 ? 1 : 2;

            if (this.Channels != num12)
            {
                this.Channels = num12;
                this.Name     = (string)null;
            }
            if (this.Bitrate != bitrate)
            {
                this.Bitrate = bitrate;
                this.Name    = (string)null;
            }
            if (this.SamplingFrequency != sampleRate)
            {
                this.SamplingFrequency = sampleRate;
                this.Name = (string)null;
            }
            this.FrameLength = Mp3FrameHeader.GetFrameSize(version, layer, bitrate, sampleRate, paddingFlag);
            this.Duration    = this.GetDuration(version, layer, sampleRate);
            if (string.IsNullOrEmpty(this.Name))
            {
                this.Name = string.Format("MP3 {0}, {1} sample {2}kHz bitrate {3}kHz {4} channels", (object)Mp3FrameHeader.VersionName[index1], (object)Mp3FrameHeader.LayerName[index2], (object)((double)sampleRate / 1000.0), (object)((double)bitrate / 1000.0), (object)this.Channels);
            }
            if (verbose)
            {
                Debug.WriteLine("Configuration MP3 Frame: {0}, {1} sample {2}kHz bitrate {3}kHz channel mode {4}", (object)Mp3FrameHeader.VersionName[index1], (object)Mp3FrameHeader.LayerName[index2], (object)((double)sampleRate / 1000.0), (object)((double)bitrate / 1000.0), (object)num7);
            }
            return(true);
        }