Exemplo n.º 1
0
        public static int GetTotalLength(MpegAudioVersion version, MpegAudioLayer layer, int bitRateID, int sampleRateID)
        {
            int sampleCount = MpegAudioSpecification.GetSampleCount(version, layer);
            int dataRate    = MpegAudioSpecification.GetBitRate(version, layer, bitRateID) * 1000 / 8;
            int sampleRate  = MpegAudioSpecification.GetSamplingRate(version, sampleRateID);

            return(sampleCount * dataRate / sampleRate);
        }
Exemplo n.º 2
0
        public static int GetSlotLength(MpegAudioLayer layer)
        {
            switch (layer)
            {
            case MpegAudioLayer.I: return(4);

            case MpegAudioLayer.II: return(1);

            case MpegAudioLayer.III: return(1);

            default: throw new InvalidOperationException();
            }
        }
Exemplo n.º 3
0
        public static MpegAudioJoinMode GetJoinMode(MpegAudioLayer layer, int joinID)
        {
            switch (layer)
            {
            case MpegAudioLayer.I:
            case MpegAudioLayer.II:
                return(MpegAudioJoinMode.IntensityStereo);

            case MpegAudioLayer.III:
                return((MpegAudioJoinMode)joinID);

            default: throw new InvalidOperationException();
            }
        }
Exemplo n.º 4
0
        public static MpegAudioJoinBands GetJoinBands(MpegAudioLayer layer, int joinID)
        {
            switch (layer)
            {
            case MpegAudioLayer.I:
            case MpegAudioLayer.II:
                return((MpegAudioJoinBands)joinID);

            case MpegAudioLayer.III:
                return(MpegAudioJoinBands.Dynamic);

            default: throw new InvalidOperationException();
            }
        }
Exemplo n.º 5
0
        protected MpegAudioFrame(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            BitField header = BitField.FromBytes(reader.ReadBytes(4));

            if (header.Length != 32)
            {
                throw new InvalidDataException(string.Format("Incorrect header length '{0}', expected '32'.", header.Bits.Count()));
            }

            if (header[0, 11].Value != 0x07FF)
            {
                throw new InvalidDataException(string.Format("Incorrect sync '{0}', expected '11111111111'.", header[0, 11]));
            }
            this.version = (MpegAudioVersion)header[11, 13].Value;
            if (version == MpegAudioVersion.Reserved)
            {
                throw new InvalidDataException(string.Format("Incorrect version '{0}'.", version));
            }
            this.layer = (MpegAudioLayer)header[13, 15].Value;
            if (layer == MpegAudioLayer.Reserved)
            {
                throw new InvalidDataException(string.Format("Incorrect layer '{0}'.", layer));
            }
            this.hasErrorProtection = !header[15];
            this.bitRateID          = header[16, 20].Value;
            if (bitRateID == 0 || bitRateID == 15)
            {
                throw new InvalidDataException(string.Format("Incorrect bit rate ID '{0}'.", bitRateID));
            }
            this.sampleRateID = header[20, 22].Value;
            if (sampleRateID == 3)
            {
                throw new InvalidDataException(string.Format("Incorrect sample rate ID '{0}'.", sampleRateID));
            }
            this.hasPadding    = header[22];
            this.privateBit    = header[23];
            this.channelMode   = (MpegAudioChannelMode)header[24, 26].Value;
            this.joinID        = header[26, 28].Value;
            this.isCopyrighted = header[28];
            this.isOriginal    = header[29];
            this.emphasis      = (MpegAudioEmphasis)header[30, 32].Value;

            this.checksum = hasErrorProtection ? reader.ReadUInt16() : (ushort)0;
        }
Exemplo n.º 6
0
        protected MpegAudioFrame
        (
            MpegAudioVersion version,
            MpegAudioLayer layer,
            bool hasErrorProtection,
            int bitRateID,
            int sampleRateID,
            bool hasPadding,
            bool privateBit,
            MpegAudioChannelMode channelMode,
            int joinID,
            bool isCopyrighted,
            bool isOriginal,
            MpegAudioEmphasis emphasis,
            ushort checksum
        )
        {
            if (version == MpegAudioVersion.Reserved)
            {
                throw new ArgumentException(string.Format("Incorrect version '{0}'.", version));
            }
            if (layer == MpegAudioLayer.Reserved)
            {
                throw new ArgumentException(string.Format("Incorrect layer '{0}'.", layer));
            }
            if (bitRateID <= 0 || bitRateID >= 15)
            {
                throw new ArgumentException(string.Format("Incorrect bit rate ID '{0}'.", bitRateID));
            }
            if (sampleRateID < 0 || sampleRateID >= 3)
            {
                throw new ArgumentException(string.Format("Incorrect sample rate ID '{0}'.", sampleRateID));
            }

            this.version            = version;
            this.layer              = layer;
            this.hasErrorProtection = hasErrorProtection;
            this.bitRateID          = bitRateID;
            this.sampleRateID       = sampleRateID;
            this.hasPadding         = hasPadding;
            this.privateBit         = privateBit;
            this.channelMode        = channelMode;
            this.joinID             = joinID;
            this.isCopyrighted      = isCopyrighted;
            this.isOriginal         = isOriginal;
            this.emphasis           = emphasis;

            this.checksum = checksum;
        }
Exemplo n.º 7
0
 protected MpegAudioMetaDataFrame
 (
     MpegAudioVersion version,
     MpegAudioLayer layer,
     bool hasErrorProtection,
     int bitRateID,
     int sampleRateID,
     bool hasPadding,
     bool privateBit,
     MpegAudioChannelMode channelMode,
     int joinID,
     bool isCopyrighted,
     bool isOriginal,
     MpegAudioEmphasis emphasis,
     ushort checksum
 )
     : base(version, layer, hasErrorProtection, bitRateID, sampleRateID, hasPadding, privateBit, channelMode, joinID, isCopyrighted, isOriginal, emphasis, checksum)
 {
 }
Exemplo n.º 8
0
        public static int GetSampleCount(MpegAudioVersion version, MpegAudioLayer layer)
        {
            switch (layer)
            {
            case MpegAudioLayer.I: return(0x180);

            case MpegAudioLayer.II: return(0x480);

            case MpegAudioLayer.III:
                switch (version)
                {
                case MpegAudioVersion.Mpeg1: return(0x480);

                case MpegAudioVersion.Mpeg2: return(0x240);

                case MpegAudioVersion.Mpeg25: return(0x240);

                default: throw new InvalidOperationException();
                }

            default: throw new InvalidOperationException();
            }
        }
Exemplo n.º 9
0
        public static int GetBitRate(MpegAudioVersion version, MpegAudioLayer layer, int value)
        {
            if (value <= 0 || value >= 15)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            switch (version)
            {
            case MpegAudioVersion.Mpeg1:
                switch (layer)
                {
                case MpegAudioLayer.I: return(version1Layer1Bitrates[value]);

                case MpegAudioLayer.II: return(version1Layer2Bitrates[value]);

                case MpegAudioLayer.III: return(version1Layer3Bitrates[value]);

                default: throw new ArgumentOutOfRangeException("layer");
                }

            case MpegAudioVersion.Mpeg2:
            case MpegAudioVersion.Mpeg25:
                switch (layer)
                {
                case MpegAudioLayer.I: return(version2Layer1Bitrates[value]);

                case MpegAudioLayer.II: return(version2Layer2Bitrates[value]);

                case MpegAudioLayer.III: return(version2Layer3Bitrates[value]);

                default: throw new ArgumentOutOfRangeException("layer");
                }

            default: throw new ArgumentOutOfRangeException("version");
            }
        }
Exemplo n.º 10
0
        public MpegAudioFrameType(MpegAudioVersion version, MpegAudioLayer layer, int sampleRateID, int channelCount)
        {
            if (version == MpegAudioVersion.Reserved)
            {
                throw new ArgumentOutOfRangeException("version");
            }
            if (layer == MpegAudioLayer.Reserved)
            {
                throw new ArgumentOutOfRangeException("layer");
            }
            if (sampleRateID < 0 || sampleRateID >= 3)
            {
                throw new ArgumentOutOfRangeException("sampleRateID");
            }
            if (channelCount < 1 || channelCount > 2)
            {
                throw new ArgumentOutOfRangeException("channelCount");
            }

            this.version      = version;
            this.layer        = layer;
            this.sampleRateID = sampleRateID;
            this.channelCount = channelCount;
        }