SamboyCoding/Fmod5Sharp

GitHub: SamboyCoding/Fmod5Sharp

用于解码 FMOD 5 声音库文件并将音频采样导出为标准格式的纯 C# 托管库。

Stars: 46 | Forks: 17

# Fmod5Sharp ## FMOD 5 声音库(FSB 文件)的托管解码器。 [![NuGet](https://img.shields.io/nuget/v/Fmod5Sharp?)](https://www.nuget.org/packages/Fmod5Sharp/) 该库允许你读取 FMOD 5 声音库文件(以字符 FSB5 开头)中包含的采样, 然后将这些采样导出为标准文件格式(假设所包含的数据格式受支持)。 可以根据需要添加对更多编码格式的支持。 ## 用法 可以像这样读取 Fmod 文件 ``` //Will throw if the bank is not valid. FmodSoundBank bank = FsbLoader.LoadFsbFromByteArray(rawData); ``` 或者,如果你不想在文件无效时抛出异常,你可以使用 ``` bool success = FsbLoader.TryLoadFsbFromByteArray(rawData, out FmodSoundBank bank); ``` 然后,你可以查询有关该声音库的一些属性: ``` FmodAudioType type = bank.Header.AudioType; uint fmodSubVersion = bank.Header.Version; //0 or 1 have been observed ``` 并获取存储在其中的采样: ``` List samples = bank.Samples; int frequency = samples[0].Metadata.Frequency; //E.g. 44100 uint numChannels = samples[0].Metadata.Channels; //2 for stereo, 1 for mono. string name = samples[0].Name; //Null if not present in the bank file (which is usually the case). ``` 而且,你可以将音频数据转换回标准格式。 ``` var success = samples[0].RebuildAsStandardFileFormat(out var dataBytes, out var fileExtension); //Assuming success == true, then this file format was supported and you should have some data and an extension (without the leading .). //Now you can save dataBytes to an file with the given extension on your disk and play it using your favourite audio player. //Or you can use any standard library to convert the byte array to a different format, if you so desire. ``` 你还可以检查给定的格式类型是否受支持,如果受支持,它会生成什么扩展名,如下所示: ``` bool isSupported = bank.Header.AudioType.IsSupported(); //Null if not supported string? extension = bank.Header.AudioType.FileExtension(); ``` 或者,你可以查阅下表: | 格式 | 是否支持? | 扩展名 | 备注 | |:--------:|:----------:|:---------:|:---------------------------------------------------------------------------------------------------------:| | PCM8 | ✔️ | wav | | | PCM16 | ✔️ | wav | | | PCM24 | ❌ | | 从未在实际游戏中观察到使用此格式。 | | PCM32 | ✔️ | wav | 理论上受支持。从未在实际游戏中观察到使用此格式。 | | PCMFLOAT | ❌ | | 至少在一款 JRPG 中见过。 | | GCADPCM | ✔️ | wav | 已使用单声道文件测试过。未使用立体声测试过,但理论上应该可行。在 Unity 游戏中见过。 | | IMAADPCM | ✔️ | wav | 在 Unity 游戏中见过。 | | VAG | ❌ | | 从未在实际游戏中观察到使用此格式。 | | HEVAG | ❌ | | 极少使用——我所知道的唯一例子是一款 PS Vita 游戏。 | | XMA | ❌ | | 主要用于 Xbox 360。 | | MPEG | ❌ | | 用于一些较老的游戏。 | | CELT | ❌ | | 用于一些较老的独立游戏。 | | AT9 | ❌ | | PlayStation Audio 的原生格式,包括在 Unity 游戏中。 | | XWMA | ❌ | | 从未在实际游戏中观察到使用此格式。 | | VORBIS | ✔️ | ogg | 在 Unity 游戏中非常常用。 | | FADPCM | ✔️ | wav | 似乎用于 Unreal Engine 游戏。 | | OPUS | ❌ | | ? | # 致谢 本项目使用了: - [OggVorbisEncoder](https://github.com/SteveLillis/.NET-Ogg-Vorbis-Encoder) 来构建 Ogg Vorbis 输出流。 - [NAudio.Core](https://github.com/naudio/NAudio) 对 WAV 文件执行相同的操作。 - [BitStreams](https://github.com/rubendal/BitStream) 用于解析 vorbis 头数据。 - [IndexRange](https://github.com/bgrainger/IndexRange) 在支持 .NET Standard 2.0 时让我的工作更轻松。 它还使用了 System.Text.Json。
标签:FMOD, 多人体追踪, 多媒体解码, 文件解析, 音效库, 音频处理