コード例 #1
0
        public static LameTag FromBinaryReader(BinaryReader br)
        {
            LameTag tmpLameTag = new LameTag();

            tmpLameTag.Quality       = br.ReadByte();
            tmpLameTag.Encoder       = br.ReadBytes(4);
            tmpLameTag.VersionString = br.ReadBytes(5);
            tmpLameTag.TagRevision_EncodingMethod = (byte)(br.ReadByte() & 0x0F);
            tmpLameTag.Lowpass               = br.ReadByte();
            tmpLameTag.ReplayGain            = br.ReadBytes(8);
            tmpLameTag.EncodingFlags_ATHType = (byte)(br.ReadByte() & 0x0F);
            tmpLameTag.Bitrate               = br.ReadByte();
            tmpLameTag.EncoderDelays         = br.ReadBytes(3);
            tmpLameTag.MiscInfo              = br.ReadByte();
            tmpLameTag.MP3Gain               = br.ReadByte();
            tmpLameTag.Surround_Preset       = br.ReadBytes(2);
            tmpLameTag.MusicLength           = br.ReadBytes(4);
            tmpLameTag.MusicCRC              = br.ReadBytes(2);
            tmpLameTag.InfoTagCRC            = br.ReadBytes(2);

            tmpLameTag.NoiseShaping = (byte)(tmpLameTag.MiscInfo & 0x03);
            tmpLameTag.StereoMode   = (byte)((tmpLameTag.MiscInfo & 0x1C) >> 2);

            return(tmpLameTag);
        }
コード例 #2
0
ファイル: Structs.cs プロジェクト: Rashed-Hoque/IdSharp
        public static LameTag FromBinaryReader(BinaryReader br)
        {
            LameTag tmpLameTag = new LameTag();

            tmpLameTag.Quality = br.ReadByte();
            tmpLameTag.Encoder = br.ReadBytes(4);
            tmpLameTag.VersionString = br.ReadBytes(5);
            tmpLameTag.TagRevision_EncodingMethod = (byte)(br.ReadByte() & 0x0F);
            tmpLameTag.Lowpass = br.ReadByte();
            tmpLameTag.ReplayGain = br.ReadBytes(8);
            tmpLameTag.EncodingFlags_ATHType = (byte)(br.ReadByte() & 0x0F);
            tmpLameTag.Bitrate = br.ReadByte();
            tmpLameTag.EncoderDelays = br.ReadBytes(3);
            tmpLameTag.MiscInfo = br.ReadByte();
            tmpLameTag.MP3Gain = br.ReadByte();
            tmpLameTag.Surround_Preset = br.ReadBytes(2);
            tmpLameTag.MusicLength = br.ReadBytes(4);
            tmpLameTag.MusicCRC = br.ReadBytes(2);
            tmpLameTag.InfoTagCRC = br.ReadBytes(2);

            tmpLameTag.NoiseShaping = (byte)(tmpLameTag.MiscInfo & 0x03);
            tmpLameTag.StereoMode = (byte)((tmpLameTag.MiscInfo & 0x1C) >> 2);

            return tmpLameTag;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicLameTagReader"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        public BasicLameTagReader(string path)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");

            // Initialize
            _isLameTagFound = true;

            _tag = new LameTag();

            using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                int startPos = ID3v2.GetTagSize(br.BaseStream);

                // Seek past ID3v2 tag
                br.BaseStream.Seek(startPos, SeekOrigin.Begin);

                // Get StartOfFile structure
                StartOfFile startOfFile = StartOfFile.FromBinaryReader(br);

                // Seek past ID3v2 tag
                br.BaseStream.Seek(startPos, SeekOrigin.Begin);

                string info1 = Encoding.ASCII.GetString(startOfFile.Info1);
                string info2 = Encoding.ASCII.GetString(startOfFile.Info2);
                string info3 = Encoding.ASCII.GetString(startOfFile.Info3);

                if (info1 == "Xing" || info1 == "Info")
                {
                    br.BaseStream.Seek(Info1Offset, SeekOrigin.Current);
                }
                else if (info2 == "Xing" || info2 == "Info")
                {
                    br.BaseStream.Seek(Info2Offset, SeekOrigin.Current);
                }
                else if (info3 == "Xing" || info3 == "Info")
                {
                    br.BaseStream.Seek(Info3Offset, SeekOrigin.Current);
                }
                else
                {
                    _isLameTagFound = true;
                }

                // Read LAME tag structure
                br.BaseStream.Seek(LAMETagOffset, SeekOrigin.Current);
                _tag = LameTag.FromBinaryReader(br);

                // Read old LAME header
                br.BaseStream.Seek(0 - Marshal.SizeOf(typeof(LameTag)), SeekOrigin.Current);
                OldLameHeader oldLameHeader = OldLameHeader.FromBinaryReader(br);
                _versionStringNonLameTag = Encoding.ASCII.GetString(oldLameHeader.VersionString);
            }

            // Set version string
            if (_tag.VersionString[1] == '.')
            {
                byte[] versionString = new byte[6];
                int i;
                for (i = 0; i < 4 || (i == 4 && _tag.VersionString[i] == 'b'); i++)
                    versionString[i] = _tag.VersionString[i];
                Array.Resize(ref versionString, i);
                _versionString = Encoding.ASCII.GetString(versionString);
            }
            else
            {
                _versionString = "";
            }

            // If encoder is not LAME, set IsLameTagFound to false
            // TODO : How about other encoders that use the LAME tag?
            if (Encoding.ASCII.GetString(_tag.Encoder) != "LAME")
            {
                _isLameTagFound = false;
            }

            // Set preset WORD
            _preset = (ushort)(((_tag.Surround_Preset[0] << 8) + _tag.Surround_Preset[1]) & 0x07FF);

            // Guess preset
            _presetGuess = (new PresetGuesser()).GuessPreset(
                VersionStringNonLameTag, /*m_Tag.VersionString*/
                _tag.Bitrate,
                _tag.Quality,
                _tag.TagRevision_EncodingMethod,
                _tag.NoiseShaping,
                _tag.StereoMode,
                _tag.EncodingFlags_ATHType,
                _tag.Lowpass,
                out _isPresetGuessNonBitrate);
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicLameTagReader"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        public BasicLameTagReader(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            // Initialize
            _isLameTagFound = true;

            _tag = new LameTag();

            using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                int startPos = ID3v2.GetTagSize(br.BaseStream);

                // Seek past ID3v2 tag
                br.BaseStream.Seek(startPos, SeekOrigin.Begin);

                // Get StartOfFile structure
                StartOfFile startOfFile = StartOfFile.FromBinaryReader(br);

                // Seek past ID3v2 tag
                br.BaseStream.Seek(startPos, SeekOrigin.Begin);

                string info1 = Encoding.ASCII.GetString(startOfFile.Info1);
                string info2 = Encoding.ASCII.GetString(startOfFile.Info2);
                string info3 = Encoding.ASCII.GetString(startOfFile.Info3);

                if (info1 == "Xing" || info1 == "Info")
                {
                    br.BaseStream.Seek(Info1Offset, SeekOrigin.Current);
                }
                else if (info2 == "Xing" || info2 == "Info")
                {
                    br.BaseStream.Seek(Info2Offset, SeekOrigin.Current);
                }
                else if (info3 == "Xing" || info3 == "Info")
                {
                    br.BaseStream.Seek(Info3Offset, SeekOrigin.Current);
                }
                else
                {
                    _isLameTagFound = true;
                }

                // Read LAME tag structure
                br.BaseStream.Seek(LAMETagOffset, SeekOrigin.Current);
                _tag = LameTag.FromBinaryReader(br);

                // Read old LAME header
                br.BaseStream.Seek(0 - Marshal.SizeOf(typeof(LameTag)), SeekOrigin.Current);
                OldLameHeader oldLameHeader = OldLameHeader.FromBinaryReader(br);
                _versionStringNonLameTag = Encoding.ASCII.GetString(oldLameHeader.VersionString);
            }

            // Set version string
            if (_tag.VersionString[1] == '.')
            {
                byte[] versionString = new byte[6];
                int    i;
                for (i = 0; i < 4 || (i == 4 && _tag.VersionString[i] == 'b'); i++)
                {
                    versionString[i] = _tag.VersionString[i];
                }
                Array.Resize(ref versionString, i);
                _versionString = Encoding.ASCII.GetString(versionString);
            }
            else
            {
                _versionString = "";
            }

            // If encoder is not LAME, set IsLameTagFound to false
            // TODO : How about other encoders that use the LAME tag?
            if (Encoding.ASCII.GetString(_tag.Encoder) != "LAME")
            {
                _isLameTagFound = false;
            }

            // Set preset WORD
            _preset = (ushort)(((_tag.Surround_Preset[0] << 8) + _tag.Surround_Preset[1]) & 0x07FF);

            // Guess preset
            _presetGuess = (new PresetGuesser()).GuessPreset(
                VersionStringNonLameTag, /*m_Tag.VersionString*/
                _tag.Bitrate,
                _tag.Quality,
                _tag.TagRevision_EncodingMethod,
                _tag.NoiseShaping,
                _tag.StereoMode,
                _tag.EncodingFlags_ATHType,
                _tag.Lowpass,
                out _isPresetGuessNonBitrate);
        }