コード例 #1
0
        private static string ReadTextField(StreamBuffer sb)
        {
            if (sb == null)
                throw new ArgumentNullException("sb");

            int size = sb.ReadInt16();
            return sb.ReadString(size);
        }
コード例 #2
0
 public void ReadInt16Test()
 {
     const short Value = 0x1234;
     const short Expected = 0x1234;
     StreamBuffer target = new StreamBuffer(BitConverter.GetBytes(Value)) { Position = 0 };
     short actual = target.ReadInt16();
     Assert.AreEqual(Expected, actual);
 }
コード例 #3
0
        private static void ReadAudioMetaFields(StreamBuffer sb, MusicMatchTag tag)
        {
            if (sb == null)
                throw new ArgumentNullException("sb");

            // Single-line text fields
            tag.SongTitle = ReadTextField(sb);
            tag.AlbumTitle = ReadTextField(sb);
            tag.ArtistName = ReadTextField(sb);
            tag.Genre = ReadTextField(sb);
            tag.Tempo = ReadTextField(sb);
            tag.Mood = ReadTextField(sb);
            tag.Situation = ReadTextField(sb);
            tag.Preference = ReadTextField(sb);

            // Non-text fields
            tag.SongDuration = ReadTextField(sb);
            tag.CreationDate = DateTime.FromOADate(sb.ReadDouble());
            tag.PlayCounter = sb.ReadInt32();
            tag.OriginalFilename = ReadTextField(sb);
            tag.SerialNumber = ReadTextField(sb);
            tag.TrackNumber = sb.ReadInt16();

            // Multi-line text fields
            tag.Notes = ReadTextField(sb);
            tag.ArtistBio = ReadTextField(sb);
            tag.Lyrics = ReadTextField(sb);

            // Internet addresses
            tag.ArtistUrl = ReadTextField(sb);
            tag.BuyCdUrl = ReadTextField(sb);
            tag.ArtistEmail = ReadTextField(sb);
        }
コード例 #4
0
ファイル: LameTag.cs プロジェクト: NeWbY100/AudioVideoLib
        ////------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="LameTag"/> class.
        /// </summary>
        /// <param name="firstFrameBuffer">The first frame buffer containing a <see cref="LameTag"/>.</param>
        public LameTag(StreamBuffer firstFrameBuffer)
        {
            // string lameTag = "LAME"
            firstFrameBuffer.ReadString(4);
            float ver;
            float.TryParse(firstFrameBuffer.ReadString(4), out ver);
            Version = ver;

            firstFrameBuffer.Seek(-8, SeekOrigin.Current);
            if (Version < 3.90f)
            {
                // Initial LAME info, 20 bytes for LAME tag. for example, "LAME3.12 (beta 6)"
                // LAME prior to 3.90 writes only a 20 byte encoder string.
                EncoderVersion = firstFrameBuffer.ReadString(20);
            }
            else
            {
                EncoderVersion = firstFrameBuffer.ReadString(9);

                // Revision Information Tag + VBR Info
                int infoAndVbr = firstFrameBuffer.ReadByte();

                // Revision information in 4 MSB
                InfoTagRevision = infoAndVbr >> 4;
                if (InfoTagRevision == Formats.InfoTagRevision.Reserved)
                    throw new ArgumentException("InfoTagRevision bit is set to reserved (0xF)");

                // VBR info in 4 LSB
                VbrMethod = infoAndVbr & 0x0F;

                // lowpass information, multiply by 100 to get hz
                LowpassFilterValue = firstFrameBuffer.ReadByte() * 100;

                // Radio replay gain fields
                // Peak signal amplitude
                PeakSignalAmplitude = firstFrameBuffer.ReadFloat();

                // Radio Replay Gain
                RadioReplayGain = firstFrameBuffer.ReadInt16();

                // Audiophile Replay Gain
                AudiophileReplayGain = firstFrameBuffer.ReadInt16();

                // Encoding Flags + ATH type
                int encodingFlagsAndAthType = firstFrameBuffer.ReadByte();

                // Encoding Flags in 4 MSB
                EncodingFlags = encodingFlagsAndAthType >> 4;

                // LAME ATH Type in 4 LSB
                AthType = encodingFlagsAndAthType & 0x0F;

                // If ABR, this will be the specified bitrate
                // Otherwise (CBR/VBR), the minimal bitrate (255 means 255 or bigger)
                BitRate = firstFrameBuffer.ReadByte();

                // the 12 bit values (0-4095) of how many samples were added at start (encoder delay)
                // in X and how many 0-samples were padded at the end in Y to complete the last frame.
                EncoderDelays = firstFrameBuffer.ReadInt(3);
                EncoderDelaySamples = EncoderDelays & 0xFFF;
                EncoderDelayPaddingSamples = EncoderDelays >> 12;
                ////int numberSamplesInOriginalWav = frameCount

                Misc = firstFrameBuffer.ReadByte();

                // Any mp3 can be amplified by a factor 2 ^ ( x * 0.25) in a lossless manner by a tool like eg. mp3gain
                // if done so, this 8-bit field can be used to log such transformation happened so that any given time it can be undone.
                Mp3Gain = firstFrameBuffer.ReadByte();

                // Preset and surround info
                PresetSurroundInfo = firstFrameBuffer.ReadInt16();

                // 32 bit integer filed containing the exact length in bytes of the mp3 file originally made by LAME excluded ID3 tag info at the end.
                MusicLength = firstFrameBuffer.ReadBigEndianInt32();

                // Contains a CRC-16 of the complete mp3 music data as made originally by LAME.
                _musicCrc = (short)firstFrameBuffer.ReadBigEndianInt16();

                // contains a CRC-16 of the first 190 bytes (0x00 - 0xBD) of the Info header frame.
                // This field is calculated at the end, once all other fields are completed.
                _infoTagCrc = (short)firstFrameBuffer.ReadBigEndianInt16();
            }
        }