citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.55k stars 2.09k forks source link

Audio bank load/unload behavior #1260

Open fkk-cz opened 2 years ago

fkk-cz commented 2 years ago

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.

blattersturm commented 2 years ago

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.

fkk-cz commented 2 years ago

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?

blattersturm commented 2 years ago

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

blattersturm commented 2 years ago

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

fkk-cz commented 2 years ago

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\

gottfriedleibniz commented 8 months ago

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.