Giter Site home page Giter Site logo

fmod5sharp's Introduction

Fmod5Sharp

Managed decoder for FMOD 5 sound banks (FSB files).

NuGet

This library allows you to read FMOD 5 sound bank files (they start with the characters FSB5) into their contained samples, and then export those samples to standard file formats (assuming the contained data format is supported).

Support for more encodings can be added as requested.

Usage

The Fmod file can be read like this

//Will throw if the bank is not valid.
FmodSoundBank bank = FsbLoader.LoadFsbFromByteArray(rawData);

Or if you don't want it to throw if the file is invalid, you can use

bool success = FsbLoader.TryLoadFsbFromByteArray(rawData, out FmodSoundBank bank);

You can then query some properties about the bank:

FmodAudioType type = bank.Header.AudioType;
uint fmodSubVersion = bank.Header.Version; //0 or 1 have been observed

And get the samples stored inside it:

List<FmodSample> 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).

And, you can convert the audio data back to a standard format.

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.

You can also check if a given format type is supported and, if so, what extension it will result in, like so:

bool isSupported = bank.Header.AudioType.IsSupported();

//Null if not supported
string? extension = bank.Header.AudioType.FileExtension();

Alternatively, you can consult the table below:

Format Supported? Extension Notes
PCM8 ✔️ wav
PCM16 ✔️ wav
PCM24 No games have ever been observed in the wild using this format.
PCM32 ✔️ wav Supported in theory. No games have ever been observed in the wild using this format.
PCMFLOAT Seen in at least one JRPG.
GCADPCM ✔️ wav Tested with single-channel files. Not tested with stereo, but should work in theory. Seen in Unity games.
IMAADPCM ✔️ wav Seen in Unity games.
VAG No games have ever been observed in the wild using this format.
HEVAG Very rarely used - only example I know of is a game for the PS Vita.
XMA Mostly used on Xbox 360.
MPEG Used in some older games.
CELT Used in some older indie games.
AT9 Native format for PlayStation Audio, including in Unity games.
XWMA No games have ever been observed in the wild using this format.
VORBIS ✔️ ogg Very commonly used in Unity games.

Acknowledgements

This project uses:

It also uses System.Text.Json.

fmod5sharp's People

Contributors

ds5678 avatar ihatetrains avatar samboycoding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fmod5sharp's Issues

Vorbis Decoder occasionally produces invalid files

Ref ds5678/AssetRipper/#179.

That issue contains a vorbis-encoded FSB file which results in an invalid OGG being produced, and another which occasionally produces an invalid OGG when running multi-threaded.

If we switch to a combination of https://github.com/SteveLillis/.NET-Ogg-Vorbis-Encoder/ for writing, and roll our own parser for the setup blobs, it should be possible to remove the dependency on OggVorbisSharp (and thus the native libs, and .NET 6.0).

Error code -132 thrown while rebuilding ogg file

This is a forward from AssetRipper/AssetRipper#285, which got ignored in AssetRipper/AssetRipper#302

Game:
Escape from Tarkov (2019.4.34f1)

AssetRipper log output:

ExportedFile : 'transparant_smoke' exported
ExportedFile : 'rainDrop' exported
ExportedFile : 'Water Splash' exported
Import : Resource file 'sharedassets3.assets.resS' has been loaded
ExportedFile : 'dust_splash' exported
ExportedFile : 'raindrop' exported
ExportedFile : 'smoke' exported
[Error] : System.Exception: vorbis_synthesis_headerin threw error code -132
   at Fmod5Sharp.FmodVorbis.FmodVorbisRebuilder.Checked(Int32 result, String name)
   at Fmod5Sharp.FmodVorbis.FmodVorbisRebuilder.RebuildOggFile(FmodSample sample)
   at Fmod5Sharp.FmodSample.RebuildAsStandardFileFormat(Byte[]& data, String& fileExtension)
   at AssetRipper.Library.Exporters.Audio.AudioClipDecoder.TryGetDecodedAudioClipData(Byte[] rawData, Byte[]& decodedData, String& fileExtension) in D:\a\AssetRipper\AssetRipper\AssetRipperLibrary\Exporters\Audio\AudioClipDecoder.cs:line 70
   at AssetRipper.Library.Exporters.Audio.AudioClipDecoder.TryGetDecodedAudioClipData(IAudioClip audioClip, Byte[]& decodedData, String& fileExtension) in D:\a\AssetRipper\AssetRipper\AssetRipperLibrary\Exporters\Audio\AudioClipDecoder.cs:line 55
   at AssetRipper.Library.Exporters.Audio.AudioClipExporter.Export(IExportContainer container, IUnityObjectBase asset, String path) in D:\a\AssetRipper\AssetRipper\AssetRipperLibrary\Exporters\Audio\AudioClipExporter.cs:line 26
   at AssetRipper.Core.Project.Collections.AssetExportCollection.ExportInner(ProjectAssetContainer container, String filePath, String dirPath) in D:\a\AssetRipper\AssetRipper\AssetRipperCommon\Project\Collections\AssetExportCollection.cs:line 99
   at AssetRipper.Core.Project.Collections.AssetExportCollection.Export(ProjectAssetContainer container, String dirPath) in D:\a\AssetRipper\AssetRipper\AssetRipperCommon\Project\Collections\AssetExportCollection.cs:line 58
   at AssetRipper.Core.Project.ProjectExporterBase.Export(GameCollection fileCollection, IEnumerable`1 files, CoreConfiguration options) in D:\a\AssetRipper\AssetRipper\AssetRipperCommon\Project\ProjectExporterBase.cs:line 157
   at AssetRipper.Core.Project.ProjectExporterBase.Export(GameCollection fileCollection, CoreConfiguration options) in D:\a\AssetRipper\AssetRipper\AssetRipperCommon\Project\ProjectExporterBase.cs:line 68
   at AssetRipper.Core.Structure.GameStructure.GameStructure.Export(CoreConfiguration options) in D:\a\AssetRipper\AssetRipper\AssetRipperCore\Structure\GameStructure\GameStructure.cs:line 90
   at AssetRipper.Library.Ripper.ExportProject(String exportPath, Func`2 filter) in D:\a\AssetRipper\AssetRipper\AssetRipperLibrary\Ripper.cs:line 151
   at AssetRipper.Library.Ripper.ExportProject(String exportPath) in D:\a\AssetRipper\AssetRipper\AssetRipperLibrary\Ripper.cs:line 132
   at AssetRipper.GUI.Managers.UIExportManager.ExportInternal(Ripper ripper, String toRoot, Action onSuccess, Action`1 onError) in D:\a\AssetRipper\AssetRipper\AssetRipperGUI\Managers\UIExportManager.cs:line 55

The error code corresponds to OV_ENOTVORBIS = -132 (https://xiph.org/vorbis/doc/libvorbis/vorbis_synthesis_headerin.html).

Problem importing wav file

The WAV file
A wav file which cannot be played by Media Player but interestingly on uploading it can be played on Chrome and Discord, when imported to Unity, I get this error,

Errors during import of AudioClip Assets/Weapons1.wav:
FSBTool ERROR: The format of the source file is invalid, see output for details.
FSBTool ERROR: Internal error from FMOD sub-system.

I tried ffprobe on the wav file and I got the following,

[wav @ 000002096b740900] Packet corrupt (stream = 0, dts = NOPTS).
[wav @ 000002096b740900] Estimating duration from bitrate, this may be inaccurate
Input #0, wav, from 'Adamant Sniper Rifle_shoot.wav':
Duration: 00:00:01.62, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s]

Is there any tool to fix the wav file so that fmod can import it or any setting that would allow fmod to import the file?

IMAADPCM issue

this is a reference to this issue on assetripper AssetRipper/AssetRipper#411 in the last 2 comments.

After i finish ripping assets from the game and listening to the wav files that got exported, it will play 0 seconds of nothing.

Upon inspecting the compression format on the wav files, i found out they're ADPCM compressed.

Directory.Delete(outPath, true)

Seriously? What kind of Psychopath does that , without even asking for confirmation.
My bad for executing code without reading it completely first i guess.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.