Sound limits research

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Sound limits research

Post by Anakin »

Hello there,

i guess everyone who ever worked with custom sounds noticed that it is very laggy and limited. Well i run into a limit, but i don't understand what the actual limit is. So maybe someone can help me with that and explain what is limited.

What i know so far: If you load too many sounds, some disappear. I guess it's first come first serve. But is it the amount of sound lvl or the amount of actual sound files that is limited?


About my problem:
You know about the missing sound fixes from Rayman?
https://www.moddb.com/games/star-wars-b ... ound-fixes
https://www.moddb.com/games/star-wars-b ... -sound-fix
https://www.moddb.com/games/star-wars-b ... -music-fix
I included it into remaster, but got the feedback that with this installed some sounds from a 123 mod are missing. Important battlesounds, and not just those ambiente fixes.
With my knowledge of SWBF2 sounds, it was clear that there are too many sounds loaded and yeah, it makes no sense to load tatooine, wookie and ki adi munid sound fixes on gcw Yavin IV map. So i came around with this piece of code:
Hidden/Spoiler:
[code]
if ReadDataFile then

-- backup old function
local soundFix_ReadDataFile = ReadDataFile

-- wrap ReadDataFile
ReadDataFile = function(...)

-- fixing Tatooine music bug
if arg[1] == "TAT\\tat2.lvl" or arg[1] == "TAT\\tat3.lvl" then
ReadDataFile("REMASTER\\sounds\\tatmusicfix.lvl;tat_music_fix")
end

-- fixing natives
if arg[1] == "SIDE\\des.lvl" or arg[1] == "SIDE\\gar.lvl" or arg[1] == "SIDE\\gun.lvl" or arg[1] == "SIDE\\wok.lvl" then
ReadDataFile("REMASTER\\sounds\\Natives.lvl;nativesfix")
end

-- fixing ki adi mundi
if arg[1] == "SIDE\\rep.lvl" then
local list = {unpack(arg)}

for i, item in ipairs(list) do
if item == "rep_hero_kiyadimundi" then
ReadDataFile("REMASTER\\sounds\\Mundi.lvl;mundifix")
end
end
end

return soundFix_ReadDataFile(unpack(arg))
end
else
print("Remaster: Error")
print(" : ReadDataFile() not found!")
end

-- try to wrap ScriptPostLoad ------------------------------------
if ScriptPostLoad then

-- backup old function
local NativeSoundFix_ScriptPostLoad = ScriptPostLoad

-- wrap ScriptPostLoad
ScriptPostLoad = function(...)

-- let the original function happen and catch the return value
local nativeSoundFix_SPLreturn = {NativeSoundFix_ScriptPostLoad(unpack(arg))}

-- changes by Rayman1103
SetClassProperty("gun_inf_defender", "AcquiredTargetSound", "gungan_chatter_acquired")
SetClassProperty("gun_inf_defender", "HidingSound", "gungan_chatter_hide")
SetClassProperty("gun_inf_defender", "ApproachingTargetSound", "gungan_chatter_approach")
SetClassProperty("gun_inf_defender", "FleeSound", "gungan_chatter_flee")
SetClassProperty("gun_inf_defender", "PreparingForDamageSound", "gungan_chatter_predamage")
SetClassProperty("gun_inf_defender", "HeardEnemySound", "gungan_chatter_heard")
SetClassProperty("gun_inf_defender", "LowHealthSound", "gungan_chatter_heartbeat")

SetClassProperty("gun_inf_rider", "AcquiredTargetSound", "gungan_chatter_acquired")
SetClassProperty("gun_inf_rider", "HidingSound", "gungan_chatter_hide")
SetClassProperty("gun_inf_rider", "ApproachingTargetSound", "gungan_chatter_approach")
SetClassProperty("gun_inf_rider", "FleeSound", "gungan_chatter_flee")
SetClassProperty("gun_inf_rider", "PreparingForDamageSound", "gungan_chatter_predamage")
SetClassProperty("gun_inf_rider", "HeardEnemySound", "gungan_chatter_heard")
SetClassProperty("gun_inf_rider", "LowHealthSound", "gungan_chatter_heartbeat")

SetClassProperty("gun_inf_soldier", "AcquiredTargetSound", "gungan_chatter_acquired")
SetClassProperty("gun_inf_soldier", "HidingSound", "gungan_chatter_hide")
SetClassProperty("gun_inf_soldier", "ApproachingTargetSound", "gungan_chatter_approach")
SetClassProperty("gun_inf_soldier", "FleeSound", "gungan_chatter_flee")
SetClassProperty("gun_inf_soldier", "PreparingForDamageSound", "gungan_chatter_predamage")
SetClassProperty("gun_inf_soldier", "HeardEnemySound", "gungan_chatter_heard")
SetClassProperty("gun_inf_soldier", "LowHealthSound", "gungan_chatter_heartbeat")

SetClassProperty("wok_inf_mechanic", "HidingSound", "all_inf_com_chatter_hide_wookie")
SetClassProperty("wok_inf_mechanic", "ApproachingTargetSound", "all_inf_com_chatter_approach_wookie")
SetClassProperty("wok_inf_mechanic", "FleeSound", "all_inf_com_chatter_flee_wookie")
SetClassProperty("wok_inf_mechanic", "PreparingForDamageSound", "all_inf_com_chatter_predamage_wookie")
SetClassProperty("wok_inf_mechanic", "HeardEnemySound", "all_inf_com_chatter_heard_wookie")

SetClassProperty("wok_inf_rocketeer", "HidingSound", "all_inf_com_chatter_hide_wookie")
SetClassProperty("wok_inf_rocketeer", "ApproachingTargetSound", "all_inf_com_chatter_approach_wookie")
SetClassProperty("wok_inf_rocketeer", "FleeSound", "all_inf_com_chatter_flee_wookie")
SetClassProperty("wok_inf_rocketeer", "PreparingForDamageSound", "all_inf_com_chatter_predamage_wookie")
SetClassProperty("wok_inf_rocketeer", "HeardEnemySound", "all_inf_com_chatter_heard_wookie")

SetClassProperty("wok_inf_warrior", "HidingSound", "all_inf_com_chatter_hide_wookie")
SetClassProperty("wok_inf_warrior", "ApproachingTargetSound", "all_inf_com_chatter_approach_wookie")
SetClassProperty("wok_inf_warrior", "FleeSound", "all_inf_com_chatter_flee_wookie")
SetClassProperty("wok_inf_warrior", "PreparingForDamageSound", "all_inf_com_chatter_predamage_wookie")
SetClassProperty("wok_inf_warrior", "HeardEnemySound", "all_inf_com_chatter_heard_wookie")

-- return the unmanipulated values
return unpack(nativeSoundFix_SPLreturn)
end
else
print("Remaster: Error")
print(" : ScriptPostLoad() not found!")
end
[/code]
Let's have a look into the details. I have two wrappers. One on the ScriptPostLoad function and one on the ReadDataFile function.

ScriptPostLoad:
Every time a mission is loaded, there is one(!) ScriptPostLoad and this code modification waits for it beeing finished and set some additional properties. This happens ALWAYS since it doesn't hurt anyone if there is no wok_inf_warrior, who cares if he has some properties?

ReadDataFile:
This one is more tricky, since there are a lot of ReadDataFile calls while a match is loaded. So i analyze the parameters passed to the function. If mos eisley or jabbas palace is loaded, the tatooine sound fix is loaded. If one of the native's side lvl is loaded, well the native sound fix is loaded, too. This guarantees that the fix does not only work for the stock maps, but for custom maps/mods, too.
Finally the mundi sound fix goes a similar way, but there are a lot of republic mods that do not have mundi, so i further analyze the actual units that are loaded and not just the side's lvl file. If mundi is found, load the sound fix.

This works very well, the files are loaded whenever they should be loaded and the reported missing sounds on custom mods where fixed. Well but the soundfixes do no longer work. Don't misunderstand me, the soundfixes are loaded, but the swbf2 sound system mess up and do not play them. Just like there were too many sound files loaded. When i do not use all those code stuff and load the sound fixes immediately when the user script is executed, it works fine. But in that case the sound fix is applied to EVERY mod, map and era and causes problems with large era mods that come with custom sounds.

Any idea what actually limits the sounds, or how to fix this?
wsa30h
Rebel Sergeant
Rebel Sergeant
Posts: 208
Joined: Thu Jul 26, 2018 12:22 pm
Projects :: No Mod project currently.
Games I'm Playing :: star wars bf2
xbox live or psn: No gamertag set

Re: Sound limits research

Post by wsa30h »

sound limit is 32 megabytes. i wonder is there a way around the sound limit.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Sound limits research

Post by Marth8880 »

There can only be 32 MB of sound samples loaded into the game at once. There is no way around this limit.
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: Sound limits research

Post by Anakin »

does it cut just the sounds that you wanna load afterwards, or does it skip the whole lvl if it is full?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Sound limits research

Post by Marth8880 »

My assumption is that, if the sound memory usage is at 31 MB, and you try to load 2 more sound samples, the first of which is 2 MB, and the second is 0.5 MB, it will try to load the first, be unable to, and then successfully load the second one. So if you're trying to load too many, my guess is that it'll load as many as it can, rather than stop altogether if it reaches a single sample that would take it over the limit.
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: Sound limits research

Post by Anakin »

well i don't trust that much in SWBF2. But it could be easily tested with a single 32 MB sample. But for me not even creating a new project works, so no chance for me to test it
Post Reply