NAudioLame
Wrapper for libmp3lame.dll to add MP3 encoding support to NAudio.
模組介紹 作者原文
NAudio.Lame
Note: This is not my library. This is an upload containing the binaries to allow mods to refer to it as a dependency.
This currently contains my fork:
Description
Wrapper for libmp3lame.dll to add MP3 encoding support to NAudio 2.0 on Windows.
IMPORTANT: Because this wraps Windows native DLLs it will not work on any other operating system.
It may function with Windows emulation layers but I have never tested this.
Includes both 32-bit and 64-bit versions of Windows native libmp3lame.dll (named libmp3lame.32.dll and libmp3lame.64.dll respectively), both of which will be copied to the output folder on build.
If you are compiling for a specific CPU target - x86 or x64 - then you only need to distribute the appropriate version.
The LameDLLWrap project is the interface to both 32-bit and 64-bit version of the native DLLs, and is compiled for both targets.
Both versions are compiled into resources in NAudio.Lame.dll.
At runtime the version for the current process bit width is loaded from resources, which then references the appropriate native library.
Please note that native library loading will fail if for any reason the application's binary path is not in the current search path.
This will happen for example in ASP.NET projects.
Usage
The LameMP3FileWriter class implements a Stream that encodes data written to it, writing the encoded MP3 data to either a file or a stream you provide.
Sample Code
Here is a very simple codec class to convert a WAV file to and from MP3:
using System.IO;
using NAudio.Wave;
using NAudio.Lame;
public static class Codec
{
// Convert WAV to MP3 using libmp3lame library
public static void WaveToMP3(string waveFileName, string mp3FileName, int bitRate = 128)
{
using (var reader = new AudioFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
// Convert MP3 file to WAV using NAudio classes only
public static void MP3ToWave(string mp3FileName, string waveFileName)
{
using (var reader = new Mp3FileReader(mp3FileName))
using (var writer = new WaveFileWriter(waveFileName, reader.WaveFormat))
reader.CopyTo(writer);
}
}
Native DLL Loading
The new NAudio.Lame.LameDLL.LoadNativeDLL(...) method in v1.1.3 allows you to specify a set of root
folders to search for the native DLLs and load the correct version for the current architecture. This is
useful in ASP.NET and ASP.NET Core to resolve the native DLL in paths outside of the current directory
and the system PATH.
For ASP.NET (Framework version):
public static void LoadLameDLL()
{
LameDLL.LoadNativeDLL(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"));
}
For ASP.NET Core, from a PageModel or Controller:
public class IndexModel: PageModel
{
public IndexModel(IWebHostEnvironment hostEnvironment)
{
LameDLL.LoadNativeDLL(hostEnvironment.ContentRootPath);
}
}
When the native DLL is loaded this way the handle is preserved and repeated calls to the method will
return true without attempting to load the DLL again.
The method is called during LameDLLWrap assembly loading the first time a method that uses the
NAudio.Lame classes is called. On ASP.NET (Framework or Core) it is important to load the native DLL
before it is needed.
ID3 tag support
The LameMP3FileWriter class now accepts an ID3TagData parameter, allowing you to supply some information that will be set as the ID3 tag on the MP3 file.
The ID3TagData class is pretty simple right now, with only basic information support.
There are a lot of other bits of information that can potentially be stored in the ID3 tag, with all sorts of interesting ways of encoding the data.
I'll have to play with it some more.
And yes, you can add a cover image, in JPG, PNG or GIF format.
LAME can't directly support ID3v2 tags greater than 32KB in size due to internal buffer size constraints, it does allow you to write your own ID3 tags.
The solution
安裝與使用 安裝:BepInEx 外掛
- 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
- 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
- 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
- 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。
帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。
下面這些內容需要先安裝,否則該模組不會生效: