Пример #1
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;
        }
Пример #2
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;
        }
Пример #3
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)
 {
 }