Code Monkey home page Code Monkey 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

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.