private LamePreset GuessForVersion(LameVersionGroup AVersionGroup, byte ABitrate, byte AQuality, byte AEncodingMethod, byte ANoiseShaping, byte AStereoMode, byte AATHType, byte ALowpassDiv100, out bool ANonBitrate) { LamePreset preset1 = LamePreset.Unknown; LamePreset preset2 = LamePreset.Unknown; ANonBitrate = false; foreach (PresetGuessRow row1 in PresetGuesser.m_PresetGuessTable) { if (((row1.HasVersionGroup(AVersionGroup) && (row1.TVs[1] == AQuality)) && ((row1.TVs[2] == AEncodingMethod) && (row1.TVs[3] == ANoiseShaping))) && (((row1.TVs[4] == AStereoMode) && (row1.TVs[5] == AATHType)) && (row1.TVs[6] == ALowpassDiv100))) { if (row1.TVs[0] == ABitrate) { preset1 = row1.Res; break; } if ((AEncodingMethod == 3) || (AEncodingMethod == 4)) { preset2 = row1.Res; } } } if ((preset1 == LamePreset.Unknown) && (preset2 != LamePreset.Unknown)) { ANonBitrate = true; preset1 = preset2; } return(preset1); }
public LamePreset GuessPreset(string AVersionString, byte ABitrate, byte AQuality, byte AEncodingMethod, byte ANoiseShaping, byte AStereoMode, byte AATHType, byte ALowpassDiv100, out bool ANonBitrate) { string text1 = AVersionString.Substring(0, 4); string text2 = AVersionString.Substring(0, 5); if (((text1 == "3.90") && (text2 != "3.90.")) || (text1 == "3.92")) { return(this.GuessForVersion(LameVersionGroup.lvg390_3901_392, ABitrate, AQuality, AEncodingMethod, ANoiseShaping, AStereoMode, AATHType, ALowpassDiv100, out ANonBitrate)); } if (text2 == "3.90.") { return(this.BestGuessTwoVersions(LameVersionGroup.lvg3902_391, LameVersionGroup.lvg3931_3903up, ABitrate, AQuality, AEncodingMethod, ANoiseShaping, AStereoMode, AATHType, ALowpassDiv100, out ANonBitrate)); } switch (text1) { case "3.91": return(this.GuessForVersion(LameVersionGroup.lvg3902_391, ABitrate, AQuality, AEncodingMethod, ANoiseShaping, AStereoMode, AATHType, ALowpassDiv100, out ANonBitrate)); case "3.93": return(this.BestGuessTwoVersions(LameVersionGroup.lvg3931_3903up, LameVersionGroup.lvg393, ABitrate, AQuality, AEncodingMethod, ANoiseShaping, AStereoMode, AATHType, ALowpassDiv100, out ANonBitrate)); } if (string.Compare(text1, "3.94") >= 0) { return(this.GuessForVersion(LameVersionGroup.lvg394up, ABitrate, AQuality, AEncodingMethod, ANoiseShaping, AStereoMode, AATHType, ALowpassDiv100, out ANonBitrate)); } LamePreset preset1 = LamePreset.Unknown; ANonBitrate = false; return(preset1); }
private void Initialize(LameVersionGroup vg1, LameVersionGroup vg2, LameVersionGroup vg3, Byte tv1, Byte tv2, Byte tv3, Byte tv4, Byte tv5, Byte tv6, Byte tv7, LamePreset result) { VGs[0] = vg1; VGs[1] = vg2; VGs[2] = vg3; TVs[0] = tv1; TVs[1] = tv2; TVs[2] = tv3; TVs[3] = tv4; TVs[4] = tv5; TVs[5] = tv6; TVs[6] = tv7; Res = result; }
private void Initialize(LameVersionGroup vg1, LameVersionGroup vg2, LameVersionGroup vg3, Byte tv1, Byte tv2, Byte tv3, Byte tv4, Byte tv5, Byte tv6, Byte tv7, LamePreset result) { VGs[0] = vg1; VGs[1] = vg2; VGs[2] = vg3; TVs[0] = tv1; TVs[1] = tv2; TVs[2] = tv3; TVs[3] = tv4; TVs[4] = tv5; TVs[5] = tv6; TVs[6] = tv7; Res = result; }
private void Initialize(LameVersionGroup vg1, LameVersionGroup vg2, LameVersionGroup vg3, byte tv1, byte tv2, byte tv3, byte tv4, byte tv5, byte tv6, byte tv7, LamePreset result) { this.VGs[0] = vg1; this.VGs[1] = vg2; this.VGs[2] = vg3; this.TVs[0] = tv1; this.TVs[1] = tv2; this.TVs[2] = tv3; this.TVs[3] = tv4; this.TVs[4] = tv5; this.TVs[5] = tv6; this.TVs[6] = tv7; this.Res = result; }
private LamePreset BestGuessTwoVersions(LameVersionGroup AGroup1, LameVersionGroup AGroup2, byte ABitrate, byte AQuality, byte AEncodingMethod, byte ANoiseShaping, byte AStereoMode, byte AATHType, byte ALowpassDiv100, out bool ANonBitrate) { LamePreset preset1; LamePreset preset2 = this.GuessForVersion(AGroup1, ABitrate, AQuality, AEncodingMethod, ANoiseShaping, AStereoMode, AATHType, ALowpassDiv100, out ANonBitrate); bool flag1 = ANonBitrate; LamePreset preset3 = this.GuessForVersion(AGroup2, ABitrate, AQuality, AEncodingMethod, ANoiseShaping, AStereoMode, AATHType, ALowpassDiv100, out ANonBitrate); bool flag2 = ANonBitrate; if ((preset2 == LamePreset.Unknown) || (flag1 && (preset3 != LamePreset.Unknown))) { preset1 = preset3; ANonBitrate = flag2; return(preset1); } preset1 = preset2; ANonBitrate = flag1; return(preset1); }
private LamePreset GuessForVersion(LameVersionGroup AVersionGroup, Byte ABitrate, Byte AQuality, Byte AEncodingMethod, Byte ANoiseShaping, Byte AStereoMode, Byte AATHType, Byte ALowpassDiv100, out bool ANonBitrate) { LamePreset Result = LamePreset.Unknown; LamePreset NonBitrateResult = LamePreset.Unknown; ANonBitrate = false; foreach (PresetGuessRow row in _presetGuessTable) { if ((row.HasVersionGroup(AVersionGroup)) && (row.TVs[1] == AQuality) && (row.TVs[2] == AEncodingMethod) && (row.TVs[3] == ANoiseShaping) && (row.TVs[4] == AStereoMode) && (row.TVs[5] == AATHType) && (row.TVs[6] == ALowpassDiv100)) { if (row.TVs[0] == ABitrate) { Result = row.Res; break; } // Non-bitrate based guessing is only relevant to the VBR presets. else if (AEncodingMethod == 3 || AEncodingMethod == 4) { NonBitrateResult = row.Res; } } } if (Result == LamePreset.Unknown && NonBitrateResult != LamePreset.Unknown) { ANonBitrate = true; Result = NonBitrateResult; } return(Result); }
public void Encode(Stream source, string outputPath, SongTags tags, byte[] reusedBuffer) { WaveFileReader reader = null; LameMP3FileWriter writer = null; try //Idk if using captures the original instance - clearer to just use try-finally { reader = new WaveFileReader(source); var id3 = new ID3TagData() { Artist = tags.Artist, Title = tags.Title, }; if (LamePreset != null) { writer = new LameMP3FileWriter(outputPath, reader.WaveFormat, LamePreset.GetValueOrDefault(), id3); } else if (BitRate != null) { writer = new LameMP3FileWriter(outputPath, reader.WaveFormat, BitRate.GetValueOrDefault(), id3); } else { writer = new LameMP3FileWriter(outputPath, reader.WaveFormat, LAMEPreset.STANDARD, id3); } while (reader.Position < reader.Length) { int bytesRead = reader.Read(reusedBuffer, 0, reusedBuffer.Length); writer.Write(reusedBuffer, 0, bytesRead); } } finally { reader?.Dispose(); writer?.Dispose(); } }
public PresetGuessRow(LameVersionGroup vg1, byte tv1, byte tv2, byte tv3, byte tv4, byte tv5, byte tv6, byte tv7, LamePreset result) { this.VGs = new LameVersionGroup[3]; this.TVs = new byte[7]; this.Initialize(vg1, LameVersionGroup.None, LameVersionGroup.None, tv1, tv2, tv3, tv4, tv5, tv6, tv7, result); }
private void Initialize(LameVersionGroup vg1, LameVersionGroup vg2, LameVersionGroup vg3, byte tv1, byte tv2, byte tv3, byte tv4, byte tv5, byte tv6, byte tv7, LamePreset result) { this.VGs[0] = vg1; this.VGs[1] = vg2; this.VGs[2] = vg3; this.TVs[0] = tv1; this.TVs[1] = tv2; this.TVs[2] = tv3; this.TVs[3] = tv4; this.TVs[4] = tv5; this.TVs[5] = tv6; this.TVs[6] = tv7; this.Res = result; }
public PresetGuessRow(LameVersionGroup vg1, LameVersionGroup vg2, LameVersionGroup vg3, Byte tv1, Byte tv2, Byte tv3, Byte tv4, Byte tv5, Byte tv6, Byte tv7, LamePreset result) { Initialize(vg1, vg2, vg3, tv1, tv2, tv3, tv4, tv5, tv6, tv7, result); }
public PresetGuessRow(LameVersionGroup vg1, LameVersionGroup vg2, LameVersionGroup vg3, Byte tv1, Byte tv2, Byte tv3, Byte tv4, Byte tv5, Byte tv6, Byte tv7, LamePreset result) { Initialize(vg1, vg2, vg3, tv1, tv2, tv3, tv4, tv5, tv6, tv7, result); }
public PresetGuessRow(LameVersionGroup vg1, byte tv1, byte tv2, byte tv3, byte tv4, byte tv5, byte tv6, byte tv7, LamePreset result) { this.VGs = new LameVersionGroup[3]; this.TVs = new byte[7]; this.Initialize(vg1, LameVersionGroup.None, LameVersionGroup.None, tv1, tv2, tv3, tv4, tv5, tv6, tv7, result); }
/// <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); }
/// <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); }