fivem icon indicating copy to clipboard operation
fivem copied to clipboard

Audio bank load/unload behavior

Open fkk-cz opened this issue 2 years ago • 6 comments

Certain audio banks return false when requested, despite being valid and present in the decompiled scripts:

trevor2.c:111870: AUDIO::REQUEST_AMBIENT_AUDIO_BANK("TREVOR_2_BIKER_RINGTONE", false, -1);
Citizen.CreateThread(
    function()
        while not NetworkIsSessionActive() do
            Citizen.Wait(1000)
        end

        if not RequestAmbientAudioBank("TREVOR_2_BIKER_RINGTONE", false, -1) then
            print("Failed to load TREVOR_2_BIKER_RINGTONE")
        end
    end
)

This was tested in a fresh server with no other client scripts running.

~~In addition, restarting or stopping a resource that has requested an audio bank doesn't seem to consistently unload it as expected. This can be observed by requesting multiple audio banks in one resource, while simultaneously requesting or having other audio banks loaded in another resource.~~

I've heard someone mention there is a global limit of ~7 audio banks loaded at one time, although I was unable to get anywhere close as the first issue exists where perfectly valid audio banks fail to load for whatever reason.

fkk-cz avatar Feb 01 '22 20:02 fkk-cz

The game has a specific list of 'SP' only sounds or so, maybe you're hitting something related to that.

As to unloading, it could be Rockstar doesn't use the mission cleanup list for these so you may have to manually remove them.

blattersturm avatar Feb 01 '22 20:02 blattersturm

After further testing, the limit does appear to be exactly 7 audio banks loaded at once. The automatic unloading does seem to work, audio banks in another script loaded immediately when another requesting resource was stopped.

Not sure if this is even possible but increasing this limit would be nice -- 7 is really low considering some resources (and even observed in decompiled scripts) use 3-4 at a given time.

The game has a specific list of 'SP' only sounds or so, maybe you're hitting something related to that.

Is there any workaround to this? Or a way to play specific .awc files?

fkk-cz avatar Feb 01 '22 21:02 fkk-cz

Theoretically you should be able to request the sp_sounds file as a GAME_SOUNDDATA fine.

blattersturm avatar Feb 01 '22 21:02 blattersturm

As to the bank slots thing, not sure, this seems to be a bit particular in game code.

blattersturm avatar Feb 01 '22 21:02 blattersturm

Theoretically you should be able to request the sp_sounds file as a GAME_SOUNDDATA fine.

Could you give an example of this? This sound in particular is trevor_2_biker_ringtone.awc in x64\audio\sfx\SCRIPT.rpf\

fkk-cz avatar Feb 01 '22 21:02 fkk-cz

Could you give an example of this?

I believe the idea was something along the lines to data_file 'AUDIO_SOUNDDATA' 'sp_sounds.dat' where sp_sounds.dat54.rel is copied from the gamefiles.

Since this issue was originally posted there have been a variety of tutorials published on the forums/elsewhere about creating and streaming your sounds that you can look into as well. A lot of progress has been made here:

https://forum.cfx.re/t/how-to-make-a-simplesound-using-native-audio/5156001

As to unloading, it could be Rockstar doesn't use the mission cleanup list for these so you may have to manually remove them.

Related to this is another category of issue others have people have reported: protected assets that request audio banks without disposing of them properly. Providing a mechanism for developers to debug this would be nice.

gottfriedleibniz avatar Feb 05 '24 13:02 gottfriedleibniz