News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: [PC][Tutorial] Sound MOD tutorial  (Read 271 times)

0 Members and 1 Guest are viewing this topic.

Offline Charor

  • Jr. Member
  • **
  • Posts: 7
    • View Profile
[PC][Tutorial] Sound MOD tutorial
« on: January 30, 2024, 11:00:07 PM »
This is a sound mod tutorial for PC version of Bully video game

-------------------------------
LONG STORY SHORT
-------------------------------
  • download PC sound kit.zip and extract it
  • Drag and Drop .bin file on export wav.bat (from \AUDIO\PLAYLIST\)
  • Edit wavs you want and delete unmodified wavs
    Modded audio must be same duration or shorter, same sample rate and channels as originals
  • Save as wav s16 pcm. Don't change names
  • Drag and Drop .bin file on import.bat
  • Done!


FOR THOSE WHO WANT TO DIVE DEEPER

------------------------------------
GENERAL INFORMATION
------------------------------------
audio\PLAYLIST\ folder contains some .bin files:
Sound for cutscenes and dialogs resides in Cuts.bin and Speech.bin files
Music is in Music.bin
Ambient sound, like birds, crowd noise, dogs, music class intro, preacher prayers etc are in Ambs.bin

Aside there is a .LST files with same name as .bins (Cuts.lst Music.lst etc)
Its a name list files.
You can open them with notepad if you need to

PC version:
.bin sound file is archive containing Sound Banks (.xsb idstring SDBK) and Wave Banks (.xwb idstring WBND)
This banks is microsoft's audio lib file types
We need Wave Banks cos they are containing raw wave data
Compressed as Microsoft ADPCM

For all chimichanga we will need some tools:
------------------------------------------------------
2.EXTRACT SOUND FOR MODDING
------------------------------------------------------
to extract PC wave data in usable format, we can use bin2wav.bms
Code: [Select]
// Bully Scholarship Edition PC wav extrctor
// Extract wav file or files from bin using this script
// use quickbms bin2wav.bms <<Dir>>.bin to extract wav files
// Edit wav. Keep same duration or shorter. Save as wav s16 pcm (Speech - mono, Cuts - stereo)

get Dir BASENAME
idstring "Hash"
get FILES long

// extract one file by name
//comment this block if you need all files
/* set Query string "3-R05A"
Findloc OFFSET string Query
goto OFFSET */
//------------------------------

for i = 0 < FILES
//move
Findloc OFFSET string "WBND"
set DataOFFSET long OFFSET
math OFFSET + 0x2c
goto OFFSET
//read info from header
get BankOFFSET long //0x800
get DataSIZE long
get Unk1 long //flags?
get WaveCount long
get FNAME string

math OFFSET + 0x6c
goto OFFSET
get AudioFormat long // binary32: BitsPerSample(1) BlockAlign(8) SampleRate(18) Channels(3) FormatTag(2)
// 0001 1000 0000 1010 1100 0100 0110 1010
// ||>>>>>>>> |>>>>>>>>>>>>>>>>>>>>>|>>>|format
// B|Align    |SampleRate           |channels
// format: 0-PCM; 1-XMA; 2-ADPCM; 3-WMA
//xmath Format "AudioFormat & 3"               //                     11 mask (2)
xmath numChannels "AudioFormat >> 2 & 7"     //                    111 mask (3)
xmath SampleRate "AudioFormat >> 5 & 262143" // 11 1111 1111 1111 1111 mask (18)
//xmath blockAlign "AudioFormat >> 23 & 255"   //              1111 1111 mask (8)
xmath BitsPerSample "AudioFormat >> 31 & 1"  //                      1 mask (1)
xmath BitsPerSample "8 * BitsPerSample + 8"  // BitsPerSample(PCM only): 0-8bit; 1-16bit
//print "AudioFormat=%AudioFormat|hex% %FNAME%\nnumChannels=%numChannels% SampleRate=%SampleRate% blockAlign=%blockAlign% BitsPerSample=%BitsPerSample%"

if WaveCount > 1
print "Multiwave Bank %FNAME%"
Break
endif

math DataOFFSET += BankOFFSET //+0x800

//write to wav file
callfunction WavHeader

// extract one file by name
if FNAME = Query
Break
endif

next i

startfunction WavHeader
log MEMORY_FILE1 0 0
log MEMORY_FILE2 0 0

//create wav header in memory
set MEMORY_FILE2 binary "\x52\x49\x46\x46\x72\x21\x1E\x00\x57\x41\x56\x45\x66\x6D\x74\x20\x32\x00\x00\x00\x02\x00\x02\x00\x22\x56\x00\x00\x10\x5E\x00\x00\x8C\x00\x04\x00\x20\x00\x80\x00\x07\x00\x00\x01\x00\x00\x00\x02\x00\xFF\x00\x00\x00\x00\xC0\x00\x40\x00\xF0\x00\x00\x00\xCC\x01\x30\xFF\x88\x01\x18\xFF\x64\x61\x74\x61\x20\x21\x1E\x00"

//audio settings
if numChannels = 2
set blockAlign short 140 //blockAlign 70(mono) or 140(stereo)
else
set blockAlign short 70
endif

//write settings to header
xmath WAVESIZE "DataSIZE + 0x46"
    putvarchr MEMORY_FILE2 0x04 WAVESIZE long
    putvarchr MEMORY_FILE2 0x16 numChannels short // mono-stereo
putvarchr MEMORY_FILE2 0x18 SampleRate long
    xmath BYTERATE "(SampleRate * BitsPerSample * numChannels) / 8"
    putvarchr MEMORY_FILE2 0x1c BYTERATE long // (Sample Rate * BitsPerSample * Channels)/8
    putvarchr MEMORY_FILE2 0x20 blockAlign short
    putvarchr MEMORY_FILE2 0x4a DataSIZE long

//append audio data
    log MEMORY_FILE1 DataOFFSET DataSIZE
append
    log MEMORY_FILE2 0 DataSIZE MEMORY_FILE1
append

//write to wav file
    get MF2Size asize MEMORY_FILE2
    string WavName P "%Dir%/%FName%.wav"
    log WAVName 0 MF2Size MEMORY_FILE2
endfunction

As a result, we will get folder named as bin name with wav files (MS ADPCM) in it

PC MSADPCM .wavs are ready to edit with any audio editor you like(i.e. audiacity)

Modded audio must be same duration or shorter same sample rate and channels as original
Save as wav s16 pcm

----------------------------------------
5.COMPRESS SOUND BACK
----------------------------------------
for PC we can use cli tool AdpcmEncode.exe from Microsoft DirectX SDK
After installation it will be in \Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86\
encode example:
Code: [Select]
AdpcmEncode.exe Speech\Algie_CHATTER_v2.wav import\Algie_CHATTER_v2.wavSpeech\Algie_CHATTER_v2.wav is s16 pcm wav
import\Algie_CHATTER_v2.wav is output file with MS ADPCM 128 samples/block compression
Don't forget to remove unmoded(MSADPCM) wavs from Speech (or whatever your .bin name is) folder
otherwise AdpcmEncode will decode them
As a result we got our moded wavs MSADPCM encoded in import\ folder
Now, we need to cut out a RIFF header with wav2dat.bms
Code: [Select]
// MSADPCM wav header cutter quickbms script
idstring "RIFF"
goto 0x14
get FORMAT short
 
if FORMAT != 2
print "not a Microsoft ADPCM"
print "REMOVE ALL UNMODIFIED WAVS BEFORE IMPORT. IMPORTED WAVS MUST BE S16 PCM"
exit
endif

get FNAME BASENAME
string FName P "import/%FName%.dat"

Findloc DataOFFSET string "data"
goto DataOFFSET
get data long
get DataSIZE long
SavePos DataOFFSET
math DataSIZE - 0x80 //cut tail just in case

log FNAME DataOFFSET DataSIZE
sound dat is ready to be imported in .bin
------------------------------------------------------
5.IMPORTING MODDED SOUND BACK
------------------------------------------------------
Use bin2dat.bms script with r and w options
Code: [Select]
quickbms -r -w bin2dat.bms Cuts.bin
Code: [Select]
// Bully Scholarship Edition PC audio dat extrctor (wav without header)
// Extract dat file or files from bin using this script
// use quickbms bin2dat.bms <<Dir>>.bin to extract dat files
// use quickbms -r -w bin2dat.bms <<Dir>>.bin to import dat files from "import" folder back to bin

get Dir BASENAME
idstring "Hash"
get FILES long

// extract one file by name. works on import too
//comment this block if you need all files
/* set Query string "1-04"
Findloc OFFSET string Query
goto OFFSET */
//------------------------------

for i = 0 < FILES
//move
Findloc OFFSET string "WBND"
set DataOFFSET long OFFSET
math OFFSET + 0x2c
goto OFFSET
//read info from header
get BankOFFSET long //0x800
get DataSIZE long
get Unk1 long //flags?
get WaveCount long
get FNAME string

if WaveCount > 1
print "Multiwave Bank %FNAME%"
Break
endif

math DataOFFSET += BankOFFSET //+0x800
string Name P "import/%FName%.dat"

//write to dat file
log Name DataOFFSET DataSIZE

// extract one file by name
if FNAME = Query
Break
endif

next i
to import back sound dat file(s) from import folder to .bin (Cuts.bin in example above)
dat files must be named same as in LST (i.e. 5-04.dat 1-09.dat 4-B1.dat)

Now you can test modded .bin in game!
« Last Edit: January 30, 2024, 11:36:11 PM by Charor »