FMOD Engine User Manual 2.03

11. Core API Reference | HTML5 Specific

APIs and types for HTML5 platform.

FS_createPreloadedFile

Mounts a local file so that FMOD can recognize it when calling a function that uses a filename. Should be called in prerun.

JS

FS_createPreloadedFile(ptr, value, type);
parent
Parent folder path. (UTF-8 string)
name
The name of the new file. (UTF-8 string)
url
Local (real) file system path the contents will be loaded from (UTF-8 string).
canRead

Whether the file should have read permissions set from the program’s point of view.

  • Units: Boolean
canWrite

Whether the file should have write permissions set from the program’s point of view.

  • Units: Boolean

Example usage.

function prerun()
{
    var fileUrl = "/public/js/";
    var fileName = "Master.Bank";
    var folderName = "/";

    FMOD.FS_createPreloadedFile(folderName, fileName, fileUrl + fileName, true, false);
}

Wrapper for the emscripten function.

See Also: ReadFile

ReadFile

Read the entire contents of a file into a memory variable, as preloaded by FS_createPreloadedFile.

JS

ReadFile(system, value, type);
system
System object handle.
filename
Filename of the file that is to be loaded, that has the path and filename that matches the preloaded path/filename if loaded in that fashion.
output Out
Output object containing 'val' and 'length'. Val contains memory that can be passed to FMOD functions like System::createSound (using FMOD_OPENMEMORY ) or Studio::System::loadBankMemory.

Example usage.

result = FMOD.ReadFile(gSystemCore, "/" + filename, outval);
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

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

Call Memory_Free on the variable after using it.

Memory_Free

Free memory allocated by FMOD internally in ReadFile.

JS

Memory_Free(ptr);
ptr
Number representing the FMOD buffer address from the ReadFile function.

See Also: ReadFile

file_open

Helper function to open a file that was preloaded by FS_createPreloadedFile.

JS

file_open(system, filename, filesize, handle);
system
System object handle.
filename
path and filename which matches the path/filename set up in FMOD.FS_createPreloadedFile. (UTF-8 string)
filesize Out
An object with the calculated size of the file stored in filesize.val.
handle Out
An object with the file handle stored in handle.val.

See Also: file_close, file_read, file_seek

file_close

Helper function to close a file manually that was preloaded with FS_createPreloadedFile.

JS

file_close(handle);
handle
Handle returned by the file_open function.

See Also: file_read, file_seek

file_read

Helper function to read from a file that was preloaded with FS_createPreloadedFile.

JS

file_read(handle, buffer, sizebytes, bytesread);
handle
Handle returned by the file_open function.
buffer
A memory address that would come from FMOD, such as that from an FMOD callback or Sound::lock.
sizebytes
Integer value with the number of bytes requested to be read from the file handle.
bytesread Out
An object with the number of bytes actually read stored in bytesread.val.

See Also: file_open, file_close, file_seek

file_seek

Helper function to seek a file manually that was preloaded with FS_createPreloadedFile.

JS

file_seek(handle, pos);
handle
Handle returned by file_open function.
pos
offset in bytes to seek into the file, relative to the start.

See Also: file_close, file_read

setValue

Store a value at a specific FMOD memory address.

JS

setValue(ptr, value, type);
ptr
Number representing the FMOD buffer address.
value
The value to be stored.
type
value type specified as a string. ie 'i8', 'i16', 'i32', 'i64', 'float', 'double'. (UTF-8 string)

Example usage.

for (var samp = 0; samp < length; samp++)
{
    for (var chan = 0; chan < outchannels; chan++)
    {
        // This DSP filter just halves the volume! Input is modified, and sent to output.
        let val = FMOD.getValue(inbuffer + (((samp * inchannels) + chan) * 4), 'float') * dsp_state.plugindata.volume_linear;

        FMOD.setValue(outbuffer + (((samp * outchannels) + chan) * 4), val, 'float');
    }
}

Wrapper for the emscripten function.

See Also: getValue

getValue

Retrieve a value from a specific FMOD memory address.

JS

getValue(ptr, value);
ptr
Number representing the FMOD buffer address.
type
value type specified as a string. ie 'i8', 'i16', 'i32', 'i64', 'float', 'double'. (UTF-8 string)

Example usage.

for (var samp = 0; samp < length; samp++)
{
    for (var chan = 0; chan < outchannels; chan++)
    {
        // This DSP filter just halves the volume! Input is modified, and sent to output.
        let val = FMOD.getValue(inbuffer + (((samp * inchannels) + chan) * 4), 'float') * dsp_state.plugindata.volume_linear;

        FMOD.setValue(outbuffer + (((samp * outchannels) + chan) * 4), val, 'float');
    }
}

Wrapper for the emscripten function.

Return value

If this method succeeds, it returns an integer value stored at the specified memory address.

See Also: setValue

file_seek

Helper function to seek a file manually that was preloaded with FS_createPreloadedFile.

JS

file_seek(handle, pos);
handle
Handle returned by file_open function.
pos
offset in bytes to seek into the file, relative to the start.

See Also: file_close, file_read