FMOD JS API, Confused by FS_createPreloadedFile

So I’m working on creating some loading methods so we only load exactly what we need at first, then async load other stuff for later. Basically, I want to have multiple tracks or banks, but only load the tracks/banks I need for the first event, then load everything else later.

I thought this was something to deal with loadBank methods, but I’m finding that it’s not the case at all. I find that the load times seems to be between ‘preRun’ and ‘onRuntimeInitialized’ functions, where the time between is based on the FMOD.FS_createPreloadedFile() funciton. However the documentation doesn’t make this clear, nor does it seem to give us other options.

Could I call this function later on to load/download other banks/files in the lifetime? Or does it absolutely need to be called in the preRun funciton?

Is there any other way to async load/download audio files/banks so I don’t have to wait 1-5 minutes before starting the first event, when I only need one audio bank?

Hi. Using createPreloadedFile is just a helper, and you dont have to do everything at init/startup.

If you have your own method of loading data, you can pass it to FMOD via memory for example, or you can even hook your file reader into fmod’s file system with file callbacks. More at
https://fmod.com/resources/documentation-api?version=2.1&page=platforms-html5.html#file-access has some information on loading techniques.

Check the load_banks.js example for different loading techniques

here’s the memory version

        var memoryPtr;
        var memoryLength;
        var memoryMode;

        result = FMOD.ReadFile(gSystemCore, "/" + filename, outval);    // Use a little helper function to load a file into memory.  Use your own Int8Array object if you want.
        CHECK_RESULT(result);

        memoryPtr    = outval.val;      // Pointer to FMOD owned file data.  See below where FMOD.Memory_Free is used to free it.
        memoryLength = outval.length;   // Length of FMOD owned file data
        memoryMode = (method == 2.0 ? FMOD.STUDIO_LOAD_MEMORY_POINT : FMOD.STUDIO_LOAD_MEMORY);

        result = gSystem.loadBankMemory(memoryPtr, memoryLength, memoryMode, FMOD.STUDIO_LOAD_BANK_NONBLOCKING, outval);
        CHECK_RESULT(result);

        FMOD.Memory_Free(memoryPtr);   // Because the memory for the file came from FMOD.  use helper function to free it.

        gBank[method] = outval.val;

this uses ‘FMOD.ReadFile’ which relies again on FS_createPreloadedFile but you can extract the data from your own file load and use a Int8Array instead

Right, but the load_banks.js still uses createPreloadedFile for all the audio banks in the example.

I’m loading these files, ideally, from a remote host. The client (user), will access the website and will download the audio banks from the host (remote) as needed. The client doesn’t see this happening, as it’s all done automatically from the client js files.

If I remove the createPreloadedFile function, I’ll get an error saying it was unable to find the file I’m trying to load. I’ll try your example to see if I can bypass it and get the functionality I want, but it seems that the createPreloadedFile function is being called for all the audio banks in that example.

createPreloadedFile is the way the examples load ‘from disk’, we don’t have an existing game engine which already handles file i/o to demonstrate.

How do you load your files outside of audio? This is the point of my previous reply. If you have an existing system you can use it.

If you are downloading from a remote host, i assume the data is accessible in a buffer? This means you would use the Int8Array method and skip the readfile part.

So we’re not really running an engine per say. We’re building this into a webpage that has media. The sounds/music are triggered using html elements and other triggers. The current HTML5 examples you have seem to work perfectly fine. I can connect from a separate device and it downloads the music and plays it. So I suspect that there’s already functionality in the createPreloadedFile that downloads these files if needed. Unless somehow it’s getting served the client in a different manner I’m not aware of.

Update question: Is there any place I can find documentation on these FMOD functions, i.e. FMOD.FS_createPreloadedFile() and such. I can’t find it on the standard api documentation, and when on log out the arguments for the function, I find there are extra capabilities that I wasn’t aware of that could be useful. I’d like to read further documentation to see if these other parameters do as I think.

Apologies for the refresh.

I was hoping to get more information about the documentation on the FMOD.FS_createPreloadedFile() functions and such.

createPreloaded file is an emscripten helper, the documentation for it is at https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.createPreloadedFile

I will update our docs to point to this.