# THE FSB FORMAT, BANKS, STREAMS AND SENTENCING

Introduction

FMOD Introduces a new format called .FSB, or the FMOD Sample Bank format.
This format is generated by the supplied tool. FSBank (fsbank.exe). It is mainly recommended for console formats, but can be used on any platform.
It is especially recommended for PlayStation 2, XBox and GameCube as it is a more optimal method of loading sound data into sound ram rather than using individual sound files which is slow and inefficient when coming off CD.

Compiling the FSB file

Creating an FSB file (or multiple fsb files!) is easy. Just open the tool called fsbank.exe provided in the tools directory. Currently this is only provided as a win32 application.
You will find an interface looking something like this.
FSBank is very easy to use.
You have to first decide what type of FSB file output you want to generate. The most common is a single .FSB file containing multiple sounds. This is the default and accessible by choosing 'Generate Single FSB File' from the pull-down 'Build' menu as shown in the diagram.
Single FSB file
You simply take a directory of any sound files, and specify as the 'Source Directory' field. Then tell the compiler where to build the file to by choosing a 'Destination File'. Now choose a platform to build to ('Choose Target' field at the bottom of the screen), and hit the big 'Build' button.
This generates a single .FSB file, and on top of this it also gives you a C header file to include into your program to allow indexed access to the sound data within the FSB file.
Multiple FSB files
This is similar to before, but now you can generate multiple fsb files instead of 1 file. This is only useful for generating multiple .FSB files to be used for streaming (Think of it as a batch build for individual streams). Note that you can use a single FSB file as described above for streaming, but it is limited during playback to only one of the sounds in the bank at a time.
You simply take a directory of any sound files, and specify as the 'Source Directory' field. Then tell the compiler where to build the file to by choosing a 'Destination Directory'. Now choose a the platform to build too ('Choose Target' field at the bottom of the screen), and hit the big 'Build' button.
This generates multiple .FSB files, one for each source file, and on top of this it also gives you a C header file for each output file.
Single Interleaved FSB File
This mode allows multiple sound files to be interleaved into 1 stream. It only generates 1 FSB entry, but as mono has 1 channel, stereo has 2 channels, these files can have up to 16 channels of interleaved audio. The data is multiplexed in units suitable to the hardware (ie PlayStation 2 will interleave data every 16 bytes, 36 bytes on XBox
Why is this useful? Well with this feature, you could get 16 channels of playback with no seeking. If you loaded and played 16 streams individually you would notice a LOT of seeking which is inneficient, and causes stuttering or the need for huge buffersizes, using up lots of RAM. Using interleaved streams will remove seeking, and reduce stream buffersizes.
Why would you want to have 16 tracks of sound going at once? Well this is up to the user, but the main benefits for this are

- Interactive music.
  Because these streams are interleaved, it also means they are perfectly synchronized. You can have multiple layers of soundtrack interleaved, and for the duration of the song, the majority of the channels can be set to volume 0, so they are muted. When an event or situation arises in the game you can fade up and down different tracks to bring in a new drumbeat or overlay for example, adding mood.
- Multichannel ambience.
  This would be purely beneficial for the technical side of streaming, reducing the amount of seeking and memory needed to play multiple individual streams. You can have many tracks of huge ambience data streaming at once, and 3d position each subchannel if you like, so stream data comes in and out depending on location in the game world for example.

Note: These interleaved files can also be statically loaded using the FMUSIC api, and played back as 'samples' as well as streams, as long as you have enough sound ram.
PlayStation 2
Streams benefit immensely from FSB compiling on PlayStation 2. As .VAG (the native ps2 format) does not support stereo data natively, .FSB overcomes this by interleaving stereo vag blocks into each other, then deinterleaving it at runtime when streaming.
This has a benefit of not having to play 2 mono streams at once (panning one left and one right), like you might have to with other playback systems.

Accessing FSB files from within your program

Loading an .FSB file as a static sound bank into sound ram
To do this, you use the FMUSIC_LoadSong or FMUSIC_LoadSongEx, and FMUSIC_GetSample functions. Because these functions already existed in the FMOD api for mod,s3m,xm,it,midi it seemed appropriate to use this API for FSB files, even though they are strictly not 'songs'.
The C header generated by the FSBank tool contains #defines or indices to reference each individual sound from your code, using FMUSIC_GetSample.
You can simply call FSOUND_PlaySound on each of these sample handles you retrieve through the FMUSIC api and manipulate them as you would with normal samples.
Use FMUSIC_GetNumSamples to determine the number of samples in the FSB format.
You can modify the way all sounds are loaded by using the mode parameter of the FMUSIC_LoadSongEx function. For example if you want to make all sounds hardware 3d you just specify the FSOUND_HW3D flag. You could also make them all 2d, or maybe make them all loop with FSOUND_LOOP_NORMAL.
Opening a multisound FSB file as a stream
This is the same as opening any other stream. Use FSOUND_Stream_Open.
To access the subsounds within the bank is different than with samples. Because it is a stream, you can only seek from one subsound to another. This is achieved with FSOUND_Stream_SetSubStream. Because this is a seeking action, it will stop the currently playing stream, and perform the seek to the new sound. You will have to call FSOUND_Stream_Play to get it to start playing again.

Stream stitching, or sentencing

When playing an FSB file as a stream, did you know you can stitch them together at runtime using FMOD's sentencing engine. This allows for absolutely gapless, efficient stitching of sounds, with no need for slow stopping or starting new streams, and the order of playback is determined at run time.
This is great for voice overs, where you can string together a bunch of sounds to make a single coherent sentence.
How is this done in code?
That is easy. You just call FSOUND_Stream_SetSubStreamSentence before you call FSOUND_Stream_Play or FSOUND_Stream_PlayEx.
ie, say you have a bank with multiple sounds in it, with sound snippets like "Brett", "Andrew", "Scored", "Missed", "One Point", "Two Points!", "Three Points!"
int list[3] = { SOUND_BRETT, SOUND_SCORED, SOUND_THREEPOINTS };
FSOUND_Stream_SetSubStreamSentence(stream, list, 3);
FSOUND_Stream_Play(FSOUND_FREE, stream);
This would result in a very smooth "Brett scored three points!".

Did you know?

If you have loaded your FSB file as a static sample bank, you can call FMUSIC_PlaySong to listen to the contents of the file? It will play each subsound one by one, which is great for previews.