Sign in to follow this  
bead-v

Sound files

Recommended Posts

Though this kind of continues the tutorial thread, I didn't want to post there because I think there are still too many unknowns.
(I'll only be talking about TSL here, don't know how much of it applies to K1)

It seems to me there are three types of sound files:
 - sounds.bif has raw .wav files
 - StreamMusic & StreamVoices has compressed .mp3 files renamed to .wav. If renamed back to .mp3 they still play fine, and (untested, correct me if I'm wrong) I assume if they were raw .wav they would still play fine.
 - StreamSounds apparently has something else (extension .wav). To play them in audacity, I needed to import them as raw data, and then halve the playing rate. But that also imports the header, so there's some glitchy sound at the beginning of every file. Kotor Tool also cannot play them and neither can Miles.

 

For my version (4CD), a reference to a sound from a .2da (tested with spells.2da) or from a .uts works only if the sound is in raw .wav and in the override. It doesn't work if the file is in StreamSounds, presumably because it has to be in that third file format.

 

Fair Strides has told me that the Aspyr Update to KotOR 2 on Steam made it so that specific version and update only takes .mp3 files. If anyone has that update, it would be nice to know how the three types of files behave there, so mods can be made compatible with it.

 

There's also one more bug that's been happening to me related to sounds that I just can't figure out. I'm setting off a grenade, so I'm using the visual effect, and I'm firing the vanilla sound in sounds.bif with PlaySound(). Now other sounds I play in the same cutscene (usually!) play normally, but this one is being rebellious. At one point it would work if I started the cutscene directly, but if I went from another cutscene that leads into this one, it wouldn't work. Currently it doesn't work however I play the cutscene. If anyone can think of anything that could cause problems for calling PlaySound() to play a vanilla sound from sounds.bif, please let me know!
EDIT: figured it out!
 

Edited by bead-v

Share this post


Link to post
Share on other sites

TSL has a bit more variation in its audio than K1. If you have access to a Linux box you can run this bash script to convert them - https://gist.github.com/shmerl/30412cda5a5107132a1f

 

Windows 10 has that bash shell, that might also work, although the script requires hexdump, so I dunno. You might be better off spinning up a VM.

Share this post


Link to post
Share on other sites

TSL has a bit more variation in its audio than K1. If you have access to a Linux box you can run this bash script to convert them.

 

That is, to convert TSL audio to K1 audio?

 

Also, found the source of my grenade sound problem, a combat animation was playing at the same time, apparently its (silent) sound overrode the grenade sound. It seems that with PlaySound(), only one sound can play at the same time, a new one will end the previous one.

EDIT: Wrong. Rather it has something to do with the fact that it's the owner & speaker of the node who fires the animation.

EDIT2:

Okay, final solution. The sound wasn't playing because I performed ClearAllActions() on the dialog owner right after it, making it seem like the next sound canceled it. It's acting like it was ActionPlaySound().

Edited by bead-v

Share this post


Link to post
Share on other sites

Ah yes. I would have gone the long way around, decompress with Miles, and export to .mp3 with Audacity.

Share this post


Link to post
Share on other sites

Update!

The StreamSounds sound files as well as the ambient area sound files in StreamMusic in K1 (thanks to HaloGirlAsh117 for identifying those) are RAW .wav files with an added .mp3 header (or rather, three headers, for whatever reason :question:). To play these files, open them up in a hex editor and delete everything up until RIFF, that is 1D6 bytes. You can then open it up normally in Audacity or play it in Miles.

 

Fortunately, the game doesn't need the header to play the files, so if you're adding an edited sound file to the game, just stick the file in RAW .wav format into the right folder and you're done.

Share this post


Link to post
Share on other sites

I have a problem with VO audio files in K1 and was hoping that you might be able to help me.

 

Last summer, when I last edited vanilla VO files, I simply renamed them from .wav to .mp3 and they would play just fine. I could then import them to Audacity and do whatever I wanted.

But now, none of these play anymore. Instead I get static noise in VLC or silence in Windows Media Player. Neither can I edit them in Audacity.

 

I'm probably missing some codec or something but I've no idea which one, so any help would be very appreciated.

Share this post


Link to post
Share on other sites

Just to be safe - could you tell me which files you're trying to open? I should check that they work for me.

Share this post


Link to post
Share on other sites

From a quick sample, it looks like the K1 voice files have a fake header of 199 bytes. You can batch convert them with DD - http://www.chrysocome.net/dd (scroll to the bottom of the page).

 

Put the source WAVs and DD in a folder together, open a command window (Start -> Run -> CMD), navigate to the folder, then put in this:

for %F in (*.wav) do dd if=%~nF.wav of=%~nF.mp3 bs=1 skip=199
That will trim the fake headers.

 

If you want to turn it into a batch file instead, you need to change it slightly:

for %%F in (*.wav) do dd if=%%~nF.wav of=%%~nF.mp3 bs=1 skip=199
pause
Paste that into a text file, save it out as xxx.BAT, put it in the same folder as the files and double click. The "pause" at the end isn't strictly necessary, but it will leave the window open with a "press any key to continue" so you can see what happened.

 

Edit: Or, if you want something where you can enter whatever number of bytes you want to trim, try this:

@echo off
set /p byteno="Please enter the number of bytes to trim from the header: "
for %%F in (*.wav) do dd if=%%~nF.wav of=%%~nF.mp3 bs=1 skip=%byteno%
pause
Alternatively, install Cygwin - https://www.cygwin.com/setup-x86.exe or https://www.cygwin.com/setup-x86_64.exe - making sure to enable XXD in the package list, download the bash scripts I linked to earlier, https://gist.github.com/shmerl/2cec6273ba25dd1486dd and https://gist.github.com/shmerl/30412cda5a5107132a1f, copy the K1 and TSL music files to separate folders under the Cygwin Home directory (e.g. \cygwin64\home\<username>\) and put the appropriate SH script in each. Now open a Cygwin terminal, navigate to the particular music folder (you can use CD to change directory, the same as DOS) and run the bash script using "./", for example,

./gog_kotor_extract_music.sh
  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

@ bead-v: I tried several files but one example is NM15ACJUHA07000_.wav

 

@ Darth Parametric: I'll give this a shot. Not quite sure why this is necessary though as simply renaming worked last time I tried this.

Share this post


Link to post
Share on other sites

DarthParametric: That's an intriguing sounding program! I look forward to playing with it when the computer is rebuilt. (Ordering the rest of the parts today, I believe.)

Share this post


Link to post
Share on other sites

Thank you very much. Your solution worked perfectly :)

Is there anything I need to do to get my edited files working ingame or would I just save them as raw .wav?

  • Like 1

Share this post


Link to post
Share on other sites

That's an intriguing sounding program!

It's the program used in those bash scripts for Linux I posted earlier in the thread (it's a standard inclusion in Linux packages I believe). I didn't realise at the time that someone had compiled a version for Windows. I was messing around with trying to do the batch trimming in Powershell when I saw mention of the Windows binary.

 

Is there anything I need to do to get my edited files working ingame or would I just save them as raw .wav?

I'm not sure to be honest, I haven't had much to do with audio mods.

Share this post


Link to post
Share on other sites

 

I'm not sure to be honest, I haven't had much to do with audio mods.

 

Exporting .wav from Audacity worked. I think those are raw .wav files so the answer is proabably yes.

  • Like 1

Share this post


Link to post
Share on other sites

Hey DP,

I have tried to follow your instructions above and the batch script together with dd does seem to convert the original .wav files but I can't call it a success.

I run the batch script and it produces .mp3 conversion for each .wav file. 

Those .mp3 files can be played alright in Winamp but that same result I could get by simply changing the extension of the original .wav files to .mp3.

If after the conversion I change the extension of the newly created .mp3 files back to .wav, I'm back with files that cannot be played.

Share this post


Link to post
Share on other sites

For Kotor2 when  converting .wav files in StreamSounds, I needed to use skip=470 in the batch file. 

I used a hexeditor to ensure it was removing the correct number of bytes, and a value of 470 produced the correct result.  Which makes sense, because the header is 470 bytes long (for the files I needed to modify anyways). :D 

I created my own batch file that simply outputs the header-less .wav into a folder named "output" without changing its name:

for %%F in (*.wav) do ddrelease64 if=%%~nF.wav of=output\%%~nF.wav bs=1 skip=470
pause

And I (of course) had to create my own header file for the conversion back (again by using a hexeditor to copy paste the 470 byte header):

FF F3 60 C4 00 00 00 03 48 00 00 00 00 4C 41 4D 45 33 2E 39 33 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 4C 41 4D 45 33 2E 39 33 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 FF F3 62 C4 8F 00 00 03 48 00 00 00 00 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 4C 41 4D 45 33 2E 39 33 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 FF F3 62 C4 FF 00 00 03 48 00 00 00 00 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55

I created and used the following batch file to add the header back (it simply outputs the re-headered file into a folder named "with-header" without changing the filename):

for %%F in (*.wav) do copy /b "header.bin" + "%%~nF.wav" "with_header\%%~nF.wav"
pause

 

I did the above because I found myself needing to replace THE MOST ANNOYING SOUND EFFECTS EVER IN A VIDEO GAME: amb_elecwire_A and amb_elecwire_B

Holy crap those sounds sucked so bad I thought it was a bug because it sounds like corrupted white noise. Those files both had a header 470 bytes long.  I don't know if every .wav file's header is 470 bytes long, but it's easy enough to confirm using a hexeditor. 

These weren't raw wav files or mp3 files disguised as wav files... they were just straight up normal wav files with a normal wav file header that starts with RIFF -- they just originally had an additional bullshit 470 byte header.

If I was going to write a tool to do all this for me, I'd do it in java...  If the file starts with the magic bytes FF F3, then it has a header that needs to be removed.  Then, I'd find the first instance of the magic bytes 52 49 46 46 to indicate the start of the sound wav, while storing the header in another file named original_filename.header.  But maybe all the headers in StreamSounds ARE the same, which would simplify things a little bit by hardcoding the header -- but I'd still code want the code it to double check that assumption. 

On second thought, I'd still code it without baking in the assumption that it knows what the header bytes/length are and just figure it out programmatically on a per file basis and store the header info as header_length.extension (instead of file_name.header) to greatly reduce the number of extra files created -- best of both worlds.

 

Tangential thought: Some sounds effects "pop" ingame when they start playing or when panning the camera near the output source (not the files I made to replace the above two, those work perfectly!), and I have wonder if it's related to their headers.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this