[TUTORIAL] Custom SFX implementation

Started by Giftheck, September 20, 2020, 01:57:57 AM

Previous topic - Next topic


I'll be referring to the mod folder as MOD or DataMOD in this tutorial, but it'll be whatever you have named yours.

So, first off, there's two file formats you'll need to implement custom SFX:

QuoteSND - this is the actual configuration file that stores what samples are called, pitch, volume, etc.
ASFX - this is where the samples called by the AU are stored.

Create a folder inside DataMOD/Sounds/worlds and name it whatever you want (most likely the three letter MOD name)

Inside that, you'll also need two folders - effects, and samples.

Basically, this is what the folder will look like:

Quote-base REQ file (the MOD id)
--REQ file for effects and streams called for CW (MODcw)
--ASFX file for effects and streams called for CW (MODcw)
--Same as above, but for GCW
--SND files - doesn't have to be for both, and you can have as many of these as you like. The best practice here is to have an AU file for shared SFX (in this instance it would be the LEGO brick explosions upon death) and a separate one for each era. These can be called whatever you want but for simplicity's sake I'll go with MODcw, MODgcw, and shared.

First, you'll need your sound effects placed into the effects folder. These sounds, ideally, should be saved as 22kHz mono wav files.

Next, you'll need to set up the REQ files. Open MOD.req. This is what needs to be inside:

ucft
{
    REQN
    {
        "str"
        "align=2048"
    }
    REQN
    {
        "lvl"
        "MODcw"
        "MODgcw"
    }

}


Now open MODgcw.req. This is what needs to be inside that:

ucft
{
    REQN
    {
    "bnk"
    "align=2048"
    "MODgcw"
    }

    REQN
    {
    "config"
    "MODgcw"
    "shared"
    }
}


Same would go for MODcw.

The bnk section will look for ASFX and SFX files. However, SFX files are not useful in this instance since we're not making a new common.bnk, these sounds are to be munged and loaded directly from the sound.lvl

The next step is top open up the ASFX file in Notepad. It should be blank. All this will be is a list referring to the .wav files. All that needs to be is thus:

Quoteeffects\whatever_the_sound_is_called.wav

You can also add -resample pc 22050 (changing 22050 to whatever you want) but if the wavs are already 22khz this is not needed.

Now comes the 'fun' part - the AU files. Open shared.snd. Windows will try to open these in Windows Media Player, but they are, in fact, just text files, so you open these with Notepad also.

This is the 'fun' part because you have to figure out which settings are appropriate for the sound you want to implement.
In this instance I find it much easier to just find one of the stock AU files, open it, look for a sound that is similar to the one you're looking for. In this example we are going to implement a custom death sound SFX.

So find imp_unit.au in the sound/gcw folder Any of the sounds that inherit from "imp_inf_pain_vo" will be fine to copy into your au file.

IE:

SoundProperties()
{
    Name("imp_inf_com_chatter_death");
    Group("imp_inf_pain_vo");
    Inherit("pain_chatter_template");
    PlayInterval(0.0);
    PlayIntervalDev(0.0);
    PlayProbability(1.0);
    SampleList()
    {
        Sample("IICOM419", 0.33);
        Sample("IICOM420", 0.33);
        Sample("IICOM421", 0.33);
    }
}


Now, generally, the settings don't need to be messed with. You will need to change two things though:

-The 'name' of the sound
-The samples called in the list.

Name is easy. Just change it to whatever you want to. You can then paste that name into your ODF files' DeathSound line.

The sample list is a tad more complicated.
You have these values bracketed under it:

        Sample("IICOM419", 0.33);
        Sample("IICOM420", 0.33);
        Sample("IICOM421", 0.33);


Sample is obvious as this refers to the file names as defined in the ASFX file. The number defines the 'weight' of the sound - basically, it randomizes the sound called. The number should always be 1 divided by the number of samples in the list, rounded to 2 decimal places.
Let's say this is what's in the ASFX file:

Quoteeffects\LEGO_FALLAPART1.wav
effects\LEGO_FALLAPART2.wav
effects\LEGO_FALLAPART3.wav
effects\LEGO_FALLAPART4.wav
effects\LEGO_FALLAPART5.wav

You'll want all of those to be called into the AU, and all equally 'weighted'.
So your sample list will end up looking like this:

        Sample("LEGO_FALLAPART1", 0.2);
        Sample("LEGO_FALLAPART2", 0.2);
        Sample("LEGO_FALLAPART3", 0.2);
        Sample("LEGO_FALLAPART4", 0.2);
        Sample("LEGO_FALLAPART5", 0.2);


That should conclude the setting up of the ASFX, SND and REQ files, but if you try to munge now, you'll get nothing. Unlike the SWBF1 mod tools, the SWBF2 Mod Tools aren't automatically set to allow for munging of custom sounds. So, there is a bit of tinkering left to do before you're ready.

Open up the soundmungedir.bat file
Find this line:

for /R %%A in (*.sfx) do @echo Munging %%~nA%%~xA & @soundflmunge -platform %4 -banklistinput %%A -bankoutput %MUNGEDIR%\ %CHECKDATE% -resample %CHECKID% noabort %SOUNDOPT% %BANKOPT% 2>>%MUNGE_LOG% 1>>%SOUNDLOGOUT%

Paste this under that line:

for /R %%A in (*.asfx) do @echo Munging %%~nA%%~xA & @soundflmunge -platform %4 -banklistinput %%A -bankoutput %MUNGEDIR%\ %CHECKDATE% -resample -checkid noabort %SOUNDOPT% 2>>%MUNGE_LOG% 1>>%SOUNDLOGOUT%

You will also need to do this for the original Data folder (BF2_ModTools\Data)

Next find BF2_ModTools\data\ _BUILD\sound\munge.bat, open that, find this line:

@for /R %%A in (*.sfx) do @set BANKLIST=!BANKLIST! %%A

Under that, pop this in:

@for /R %%A in (*.asfx) do @set BANKLIST=!BANKLIST! %%A

Lastly, you'll need to edit an entry in soundmunge.bat inside your DataMOD folder. Find this line:

@call soundmungedir _BUILD\sound\worlds\snd\%MUNGE_DIR% sound\worlds\snd sound\worlds\snd\%MUNGE_PLATFORM% %MUNGE_PLATFORM% _BUILD _LVL_%MUNGE_PLATFORM%\sound _BUILD\sound snd

Change snd to whatever your base REQ file is (which assumedly is your MOD id)

The last step is calling it in your LUA. Find this:

    ReadDataFile("sound\\tat.lvl;tat2gcw")

Then add this above

    ReadDataFile("dc:sound\\MOD.lvl;MODgcw")

One other thing is that it seems the Sound folder won't copy over to the addon folder, at least not when I test munged, so you will have to do that manually.

Munge, test... and if your sounds work (there is a chance that a sound will not play if it's not in the correct format but usually the munger catches that), then that's it!

(NOTE: I am not able to test the munged sounds directly myself since I cannot get munged maps to even run in SWBF2 - however, the steps I have outlined produce a functioning sound file)
In Progress:
--Phantom Menace Celebration Maps
--SWBFEA Demakes

Completed:
--Star Wars: Battlefront - Anniversary Edition (formerly Star Wars: Battlefront - Legacy)

On Hold:
--Star Wars Battlefront: Elite Squadron For SWBF1