Beispiel #1
0
        public static OldLameHeader FromBinaryReader(BinaryReader br)
        {
            OldLameHeader tmpOldLameHeader = new OldLameHeader();

            tmpOldLameHeader.UnusedByte    = br.ReadByte();
            tmpOldLameHeader.Encoder       = br.ReadBytes(4);
            tmpOldLameHeader.VersionString = br.ReadBytes(16);
            return(tmpOldLameHeader);
        }
        /// <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);
        }
Beispiel #3
0
 public static OldLameHeader FromBinaryReader(BinaryReader br)
 {
     OldLameHeader tmpOldLameHeader = new OldLameHeader();
     tmpOldLameHeader.UnusedByte = br.ReadByte();
     tmpOldLameHeader.Encoder = br.ReadBytes(4);
     tmpOldLameHeader.VersionString = br.ReadBytes(16);
     return tmpOldLameHeader;
 }