LowLevelSystem.createSound with byte arrays not working

Hey guys,

I’m trying to load an FSB sound bank direct from memory and it doesn’t seem to work.

In my project I have an fsb file called bank.fsb and it resides inside the Resources folder.

At the beginning I was loading the file via system.createSound(Application.dataPath + "/Resources/bank.fsb", MODE.LOOP_OFF | MODE._2D, out soundbank); and it was loading and creating the sound instance without any problem.

Right now I’m saving my fsb banks inside Asset Bundles and trying to create sound by passing the file bytearray but the createSound method does not recognize the bytearray.

In order to illustrate the main problem (without using asset bundles and so) I renamed the file in the Resources folder to bank.fsb.bytes to be recognized as binary and I’m loading and trying to create the sound instance with the code below:

var text = Resources.Load("bank.fsb") as TextAsset;
var result = system.createSound(text.bytes, MODE.LOOP_OFF | MODE._2D, ref exinfo, out soundGroup);

As result I get an error saying:

FMOD Error (ERR_FILE_NOTFOUND): File not found.

Any thoughts about this problem?

Thanks in advance.

Answering to my own question in case anybody faces it as well.

We must activate the MODE.OPENMEMORY bit flag on the sound creation and pass the bite array size.

So, the final code looks:

var text = Resources.Load("bank.fsb") as TextAsset;
var soundinfo = new CREATESOUNDEXINFO()
    length = (uint)text.bytes.Length,
var result = system.createSound(text.bytes, MODE.LOOP_OFF | MODE._2D | MODE.OPENMEMORY, ref soundinfo, out soundGroup);

Some info about this can be found in the MODE enum “documentation”. Listed below you can see the MODE.OPENMEMORY comment.

/* “name_or_data” will be interpreted as a pointer to memory instead of filename for creating sounds. */