Difference between revisions of "Sound Replacement Tutorial"

From Pikmin Technical Knowledge Base
Jump to navigation Jump to search
(linked spreadsheet)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
First, make sure you have Python installed. Then, download [https://cdn.discordapp.com/attachments/301121846944727040/358295103019679764/Pikmin2SoundHelperScripts.zip Yoshi2's sound helper] and extract the contents to your root's AudioRes folder. Run create_workshop.py, and wait for it to finish extracting everything.<br>
+
Want to change a sound effect in Pikmin 2? Want to add an entirely new sound?<br>
 +
Well, you've come to the right place, even if the latter is more work.<br>
 +
 
 +
<h1>Replacing Sounds</h1>
 +
Before any editing can be done, get [https://www.xayr.gay/tools/SoundModdingToolkit/ Xayr's toolkit].<br>
 +
As far as I know, it only works with Windows. <br>
 +
From this page, select the most recent version, and download the Pikmin 2 zip. <br>
 +
After extracting that, you'll need to get the Banks folder from Pikmin 2, as well as the .aaf file. <br>
 +
Both can be found in the AudioRes folder of an extracted Pikmin 2 root. <br>
 +
Once everything is in the tool's folder, simply run the initialize.bat. file. <br>
 +
Once it finishes, there should be an <b>Audio_Modding</b> folder present. <br>
 +
Inside it, the <b>0</b> folder has all the actual wave data, while the <b>IBNK0</b>-5 folders have instrument playback data. <br>
 +
There is also a <b>SoundTable</b> folder, which matters if you're adding an entirely new sound. <br>
 +
 
 +
If your goal is only to replace a sound file, your first goal should be to find the sound in the wav folder. <br>
 +
The Pikmin 2 SFX tab in [https://docs.google.com/spreadsheets/d/1s5wRceP34gaPr-CkNSnnlaCSEID5HjWTX4TSR_OxeqA/edit?usp=sharing/ this spreadsheet] contains what sound each ID corresponds to. <br>
 +
Once you know the ID of the sound you want to replace, put a new .wav file with the same name in the <b>0/custom</b> folder. <br>
 +
 
 +
If you know what you're doing with another game that also uses these sound systems (Pikmin 1, mario sunshine), you may be able to save some memory by taking the .adp <br>
 +
directly from that game, and replacing the .adp in the <b>0/ref</b> folder with your sound. This is because the .adp files use a better encoding than what can be done with <br>
 +
regular .wav files. I only recommend trying this if you're experienced with using Xayr's tools in multiple games and really need the memory savings. <br>
 +
 
 +
Once you're satisfied with the new sound effects, go back to the tool's root folder, and run the <b>rebuild_aaf.bat</b> file. <br>
 +
It can take a while, but once it finishes, the Banks folder and PSound.aaf should be updated with the new contents. <br>
 +
Simply copy them back into your extracted game root, and you should be good to go! <br>
 +
 
 +
If you do everything right, and music is completely silent in-game, you most likely made <b>wScene_0.aw</b> too big. In the standard game, it can only afford to be a bit larger <br>
 +
normal without problems arising, especially in challenge mode, where the key collected theme needs to load as well. <br>
 +
 
 +
<h1>Adding entirely new sounds</h1>
 +
Just changing normal sounds not good enough? Well get ready, because this is where things get complicated. <br>
 +
First, on top of the Xayr toolkit, you'll need [https://github.com/NerduMiner/p2setoolkit/releases/tag/v1.3/ NerduMiner's se.bms tools]. <br>
 +
Keep it outside of Xayr's tools. Next, extract <b>seq.arc</b> from Pikmin 2, and put its <b>se.bms</b> file into the tool's folder. <br>
 +
You'll need a [https://github.com/NerduMiner/p2setoolkit/blob/main/se.bms.info/ special info file] as well, which isn't part of the tools release. <br>
 +
Once both se.bms and the info file are in the tool's folder, you should be good to drag the se.bms onto build.bat. <br>
 +
It will generate a .txt file, which we will use later. <br>
 +
 
 +
Now that the other tool is set up, take your all new .wav file, and put it in the custom folder. Make sure it's name is an ID that isn't used at all normally. The first free ID in Pikmin 2 is <b>1423.wav</b>. <br>
 +
Next, you'll need to edit the <b>wavetable.json</b>, which is located in the 0 folder. <br>
 +
Go to the bottom of it, and copy paste the final entry, which should be <b>"265"</b>. <br>
 +
Make your new entry have <b>1423</b>, or whatever your new wave ID is as its name. <br>
 +
It's important that you know the <b>sample rate and sample count</b> of your custom sound. Something like Audacity can tell you this. (The outdated section actually explains this well). <br>
 +
Make sure they are correct in your new entry. Other than that, you probably don't want to touch the other values in the new entry. <br>
 +
 
 +
Next, enter the <b>0/scenes</b> folder, and open <b>wScene_0.aw.json</b> file. At the end of it's very long list of wave IDs, add the ID of your new wave. <br>
 +
The last ID is <b>1410</b>, normally. As is the case with json files, make sure you <b>add a comma</b> to 1410 after adding a new entry after it. <br>
 +
 
 +
Next, exit the 0 folder, and go into <b>IBNK0/include</b>. You could technically use any of the banks, or even add an all new one. But this bank has the most <br>
 +
free spots, and it saves se.bms math later. Adding an all new one, while organized, can be complicated. We need to add a new instrument here, but we need an ID that isn't used yet. <br>
 +
2, 4, 5, 6, 9, 10, 11, and 12 are all free, for example. Copy and paste <b>Inst_1.json</b>, and make it named the ID if your new instrument. For example, Your first new sound will probably use <b>Inst_2.json</b>. <br>
 +
Open the json, and scroll to the bottom, there should be a single instance of a <b>"WaveID"</b>, which you must change to the ID of the new sound effect you added earlier. <br>
 +
Now, go back to the IBNK0 folder, and open <b>ibnk.json</b>. You should see a list of all the used json files, make a copy of the first entry, for Inst_1, and make it say Inst_2, change the <b>"1"</b> in quotes at the beginning as well. <br>
 +
With this, the instrument data should be all good to go. <br>
 +
 
 +
(The rest of this is exclusively for sound effects, if you're adding an all new actual music instrument, you wouldn't need to do this) <br>
 +
Next, exit the 0 folder, and go into the <b>SoundTable/includes</b> folder. <br>
 +
It should have json files called 0x1, 0x2, and so on. These represent different categories of sounds. <br>
 +
Each one has data for a variety of sound effects, 0x6 has by far the most, because it's for the enemies. <br>
 +
Everything you need to know about this part of the data can be found at [https://pikmintkb.com/wiki/Se.bms this page]. <br>
 +
The category your new sound goes into usually doesn't matter much, but there are some niche situations where it matters. <br>
 +
For example, during the start of Day 1 cutscene, Pikmin sounds are muted, and wont play until the first text box, when sounds in other categories still do. <br>
 +
For this example, we will add a new sound to the enemy category, so open <b>0x6.json</b>. Adding sounds to the other categories may be problematic, because you would have to fix the "entryNumCategory" for everything in the later jsons. <br>
 +
First, there's a total entry count at the top of the file, increase this <b>by 1</b>. <br>
 +
Now, scroll all the way to the bottom of the json, and copy paste the last entry. By default, it should have <b>1037</b> for it's "entryNumCategory". <br>
 +
"entryNumCategory", "entryNum", and "entryNumGlobal" all need their values increased by <b>exactly 1</b>. The other values in it mostly don't matter, <br>
 +
although I think "type" may have some control over the sounds priority, which can lead to other sounds not playing. I'm not fully sure how this works yet. <br>
 +
Once this is done, 0x6.json should be good to go. <br>
 +
 
 +
The final step is to fix the <b>se.bms.txt</b> we made earlier. You'll want to consult [https://pikmintkb.com/wiki/Se.bms this page] again to see how this file works. <br>
 +
As of writing this, it doesn't have much for the enemy category, though. <br>
 +
After opening the .txt, search for <b>"@JUMPTABLE_60628h"</b>. This is the final sound in the normal game's jumptable for enemy sounds. The @ at the start is important, don't confuse the table entry with the data itself. <br>
 +
Copy the <b>"@JUMPTABLE_60628h"</b> line, and make a duplicate right after it. It needs a different name, so you might as well name it something logical, like <b>"@JUMPTABLE_NEWSOUND"</b>. This will make it easier to keep track of. <br>
 +
Now, search for <b>"JUMPTABLE_60628h"</b> again, and find the second instance of it, there should be a : at the end, and no @. <br>
 +
We want to add a new entry immediately before it, just after the <b>"return 0b"</b> line preceding it. <br>
 +
Copy paste the following text in, replacing <b>NEWSOUND</b> with whatever you call the new sound (keep in mind every new sound needs a unique ID): <br>
 +
 
 +
<b>JUMPTABLE_NEWSOUND: <br>
 +
opentrack 0b @TRACK_0_START_NEWSOUND<br>
 +
return 0b <br>
 +
TRACK_0_START_NEWSOUND: <br>
 +
call 0b @CALL_415h <br>
 +
param_set_16 6b 0h <br>
 +
noteon 64b 8b 127b 100b 0b <br>
 +
finish</b> <br>
 +
 
 +
The final step is to make the <b>param_set_16</b> line end in the ID of your new instrument. Note I said instrument (as in what was used for the <b>IBNK0 folder</b>), not the actual wave ID. <br>
 +
The ID of the bank itself is important as well, but if you used Bank ID 0, it doesn't matter. Just make it have the ID of the new instrument you added. For example, for <b>Inst_2</b> in IBNK0, <br>
 +
the line would look like: <br>
 +
<b>param_set_16 6b 2h</b> <br>
 +
Don't touch the <b>6b</b> part, or anything else here, besides the sound entry name. <br>
 +
Now, simply drag the <b>se.bms.txt onto build.bat</b>, and if it built correctly (make sure your new se.bms isn't 0kb), and put the new se.bms into the seq.arc archive. <br>
 +
Make sure you rebuild the .aaf and Banks folder with Xayr's tools, same as with replacing normal sounds. <br>
 +
 
 +
Now we need to tell the game where to actually use the new sound. This can be complicated if you aren't knowledgeable with code editing. Luckily, new enemy sounds can be played with only edits to the <b>AudioRes/key.arc</b> file. <br>
 +
I'll explain how to use key.arc sounds for the sake of this tutorial, but if you wanted new sounds for something other than enemies, you'll need <br>
 +
some code edits (with the exception of cutscene sound effects, but .stb is a whole mess of its own). <br>
 +
First, extract <b>key.arc</b>, and go into the folder of your enemy of choice. There should be a .bas file for every animation, more or less. <br>
 +
Xayr has a tool for editing [https://github.com/XAYRGA/bastool/ these files] as well, which you should probably use. Simply drag a <b>.bas</b> onto the tool .exe and you should get a new .json. <br>
 +
You can add or remove specific sounds to play through an animation; <b>SoundID</b> is what sound to play, and <b>FrameDelay</b> is when in the animation it should play. <br>
 +
Knowing the actual ID of your new sound can be a pain, the enemy category normally ends at <b>22923</b>, so the first new entry is <b>22924</b>, and so on from there. <br>
 +
If you're using a different category than the enemy one, you can use [https://pikmintkb.com/wiki/Se.bms/ this page] to see the final normal ID of each category. <br>
 +
Once that's all done, you can drag the .json onto the bas tool and get a new .bas file, put it back in the enemy's folder, and rebuild key.arc. <br>
 +
 
 +
At long last, you're ready to put everything together. Put the <b>key.arc, seq.arc, pSound.aaf, and Banks folder all back into AudioRes</b>. <br>
 +
If the stars happen to align, and everything miraculously works perfect, you should hear the new sound play in-game, when your enemy does the animation you changed the .bas for. <br>
 +
Do let me know if you have trouble with this, or if this guide is missing anything. - PikHacker
 +
 
 +
 
 +
<h1>Outdated</h1>
 +
The remainder of this page is <b>very outdated</b>, but I will leave it here for posterity. I highly recommend using the above guide instead.
 +
 
 +
This tutorial is designed to help you replace or mute sound files in Pikmin 2. These instructions should be relevant for Windows 7/10/11 users.<br>
 
<br>
 
<br>
In the waves folder are the extracted sounds, which you must replace with wavs that are at least very close in file size. It's reccomended that all your sounds are in mono, and are the same length and sample rate as the sounds they're replacing.<br>
+
First, make sure you have [https://www.digitalocean.com/community/tutorials/install-python-windows-10 Python installed]. Then, download [https://cdn.discordapp.com/attachments/301121846944727040/358295103019679764/Pikmin2SoundHelperScripts.zip Yoshi2's sound helper] and extract the contents to your root's <b>AudioRes</b> folder. You can use [https://gbatemp.net/download/gamecube-iso-tool.33956/ Gamecube ISO tool] to expose the game's file structure (additional info can be found in [https://pikmintkb.com/wiki/General_instructions General instructions]). Run <b>create_workshop.py</b>, and wait for it to finish extracting everything.<br>
 
<br>
 
<br>
To change the sample rate, go to Tracks>Resample in Audacity, and change the sample rate to whatever number you need it to be. Then, in the bottom rate, you should see a drop down called "Project Rate (Hz)". Change the number in that drop down to whatever sample rate you need the sound to be; it should be the same number you just used in resample.<br>
+
In the <b>waves</b> folder are the extracted sounds which you must replace with <b>.wav</b> files that are at least very close in file size. It's recommended that all your sounds are in mono the same length and sample rate as the sounds they're replacing.<br>
 
<br>
 
<br>
To change the track to mono, go to Tracks>Mix>Mix Stereo Down to Mono. Sometimes, the sound may already be at a good sample rate, and/or may already be in mono, so those steps aren't always needed.<br>
+
To change the sample rate, go to <b>Tracks</b> > <b>Resample...</b> in Audacity ([https://github.com/audacity/audacity/releases/download/Audacity-3.3.3/audacity-win-3.3.3-x64.exe Audacity 3.3.3]), and change the sample rate to match the existing sound file (ex. 22050 Hz). Next, click on the <b>Audio Setup</b> button and then <b>Audio Settings...</b> where you should see <b>Project Sample Rate.</b> You should change this number to the sample rate you need the sound to be (it should be the same number you just used in <b>Resample...</b>).<br>
 
<br>
 
<br>
You should also make sure your sound should be heard, in which case you should select the entire sound (Ctril+A) and do Effect>Amplify>OK.<br>
+
To change the track to mono, go to <b>Tracks</b> > <b>Mix</b> > <b>Mix Stereo Down to Mono</b>. If this option is greyed out then the track is already in mono.<br>
 
<br>
 
<br>
Finally, go to File>Export and then save it as a 16-bit PCM  wav. You should then replace the vanilla sound you want to replace with your edited sound. For an as-of-now incomplete list of which sound is which, go [[Guide_To_Sound_File_Names|here]]. Keep in mind the names of the sound files you are changing, because you'll need it for the next part.<br>
+
To modify the sound effect's volume, first click anywhere on the sound file and press <b>Ctrl + A</b>, then go to the toolbar and click on <b>Effect</b> > <b>Volume and Compression</b> > <b>Amplify</b> and modify the amplication (dB) desired. You can then click preview and apply.<br>
 
<br>
 
<br>
Next, go in the workshop folder and open wsys.xml in Notepad++. Find each sound you replaced, and do the following:<br>
+
Once finished, go to <b>File</b> > <b>Export</b> > <b>Export as WAV</b> and ensure the save as type is <b>WAV</b> and that encoding is set to <b>16-bit PCM</b>. Replace the vanilla sound <b>.wav</b> file with your edited sound. For a list of sounds in <b>wScene_0.aw</b>, go [[Guide_To_Sound_File_Names|here]]. Keep in mind the names of the sound files you are changing, as you will need it for the following steps.<br>
 
<br>
 
<br>
1) Replace the "repack" in the filepath with waves.<br>
+
Next, go in the workshop folder and open <b>wsys0.xml</b> in [https://notepad-plus-plus.org/downloads/ Notepad++].  Find each sound you replaced and do the following:<br>
 
<br>
 
<br>
2) Replace the ".raw" at the end of the sound file name with ".wav".<br>
+
1). Replace <b>\repack\</b> in the file path with <b>\waves\</b><br>
 
<br>
 
<br>
3) Remove the "rate=XXXXX " part. This will make the program automatically calculate the sound's sample rate when it repacks the sounds. If you don't do this, then the sound may be at the wrong pitch or speed in-game.<br>
+
2). Replace <b>.raw</b> at the end of the sound file name with <b>.wav</b><br>
 
<br>
 
<br>
4) Certain sounds have a "loop point" that you can change. If you needed to make one of your sounds longer than the sound it's replacing, you should change this. To help determine which sample count you want it to loop at, go in Audacity, and at the bottom where it shows the current time the sound is at, click on the small arrow and change the units to samples instead of hh:mm:ss + milliseconds. Now, whenever you select a part of your sound in Audacity, you can see which sample point you are at, and thus it's much easier to make a custom loop.<br>
+
3). Remove <b>rate="XXXXX"</b>. This will make the program automatically calculate the sound's sample rate when it repacks the sounds. If you don't remove this, then the sound may be at the wrong pitch or speed in-game<br>
 
<br>
 
<br>
Once you've done all that for each sound you've replaced, go back to the AudioRes folder and run rebuild_soundfiles.py. This script may take a while to execute, but once it's done, go in the newly created output folder. Copy every new aw file into AudioRes/banks, and copy PSound.aaf into the AudioRes folder itself.<br>
+
4). Certain sounds have a "loop point" that you can change. If you needed to make one of your sounds longer than the sound it's replacing, you should change this. To help determine which sample count you want it to loop at, open the sound file in Audacity, and at the bottom where it shows the current time the sound is at, click on the small down arrow at the end and change it to <b>hh:mm:ss + milliseconds</b>. Now whenever you select a part of your sound in Audacity, you can see which sample point you are at which should make it much easier to create a custom loop<br>
 
<br>
 
<br>
After this, you can rebuild the iso, and if your wav files weren't too big before, then everything should work perfectly!
+
Once you've followed these steps for each sound you've replaced, go back to the <b>AudioRes</b> folder and run <b>rebuild_soundfiles.py</b>. Once the script is finished, open the newly created <b>output</b> folder. Copy every new <b>.aw</b> file into <b>AudioRes/banks</b>, and copy <b>PSound.aaf</b> into the <b>AudioRes</b> folder.<br>
 +
<br>
 +
Finally you can save your <b>.iso</b> as trimmed using [https://gbatemp.net/download/gamecube-iso-tool.33956/ Gamecube ISO tool] and if your <b>.wav</b> files aren't too big then everything should work perfectly!

Latest revision as of 03:35, 25 April 2024

Want to change a sound effect in Pikmin 2? Want to add an entirely new sound?
Well, you've come to the right place, even if the latter is more work.

Replacing Sounds

Before any editing can be done, get Xayr's toolkit.
As far as I know, it only works with Windows.
From this page, select the most recent version, and download the Pikmin 2 zip.
After extracting that, you'll need to get the Banks folder from Pikmin 2, as well as the .aaf file.
Both can be found in the AudioRes folder of an extracted Pikmin 2 root.
Once everything is in the tool's folder, simply run the initialize.bat. file.
Once it finishes, there should be an Audio_Modding folder present.
Inside it, the 0 folder has all the actual wave data, while the IBNK0-5 folders have instrument playback data.
There is also a SoundTable folder, which matters if you're adding an entirely new sound.

If your goal is only to replace a sound file, your first goal should be to find the sound in the wav folder.
The Pikmin 2 SFX tab in this spreadsheet contains what sound each ID corresponds to.
Once you know the ID of the sound you want to replace, put a new .wav file with the same name in the 0/custom folder.

If you know what you're doing with another game that also uses these sound systems (Pikmin 1, mario sunshine), you may be able to save some memory by taking the .adp
directly from that game, and replacing the .adp in the 0/ref folder with your sound. This is because the .adp files use a better encoding than what can be done with
regular .wav files. I only recommend trying this if you're experienced with using Xayr's tools in multiple games and really need the memory savings.

Once you're satisfied with the new sound effects, go back to the tool's root folder, and run the rebuild_aaf.bat file.
It can take a while, but once it finishes, the Banks folder and PSound.aaf should be updated with the new contents.
Simply copy them back into your extracted game root, and you should be good to go!

If you do everything right, and music is completely silent in-game, you most likely made wScene_0.aw too big. In the standard game, it can only afford to be a bit larger
normal without problems arising, especially in challenge mode, where the key collected theme needs to load as well.

Adding entirely new sounds

Just changing normal sounds not good enough? Well get ready, because this is where things get complicated.
First, on top of the Xayr toolkit, you'll need NerduMiner's se.bms tools.
Keep it outside of Xayr's tools. Next, extract seq.arc from Pikmin 2, and put its se.bms file into the tool's folder.
You'll need a special info file as well, which isn't part of the tools release.
Once both se.bms and the info file are in the tool's folder, you should be good to drag the se.bms onto build.bat.
It will generate a .txt file, which we will use later.

Now that the other tool is set up, take your all new .wav file, and put it in the custom folder. Make sure it's name is an ID that isn't used at all normally. The first free ID in Pikmin 2 is 1423.wav.
Next, you'll need to edit the wavetable.json, which is located in the 0 folder.
Go to the bottom of it, and copy paste the final entry, which should be "265".
Make your new entry have 1423, or whatever your new wave ID is as its name.
It's important that you know the sample rate and sample count of your custom sound. Something like Audacity can tell you this. (The outdated section actually explains this well).
Make sure they are correct in your new entry. Other than that, you probably don't want to touch the other values in the new entry.

Next, enter the 0/scenes folder, and open wScene_0.aw.json file. At the end of it's very long list of wave IDs, add the ID of your new wave.
The last ID is 1410, normally. As is the case with json files, make sure you add a comma to 1410 after adding a new entry after it.

Next, exit the 0 folder, and go into IBNK0/include. You could technically use any of the banks, or even add an all new one. But this bank has the most
free spots, and it saves se.bms math later. Adding an all new one, while organized, can be complicated. We need to add a new instrument here, but we need an ID that isn't used yet.
2, 4, 5, 6, 9, 10, 11, and 12 are all free, for example. Copy and paste Inst_1.json, and make it named the ID if your new instrument. For example, Your first new sound will probably use Inst_2.json.
Open the json, and scroll to the bottom, there should be a single instance of a "WaveID", which you must change to the ID of the new sound effect you added earlier.
Now, go back to the IBNK0 folder, and open ibnk.json. You should see a list of all the used json files, make a copy of the first entry, for Inst_1, and make it say Inst_2, change the "1" in quotes at the beginning as well.
With this, the instrument data should be all good to go.

(The rest of this is exclusively for sound effects, if you're adding an all new actual music instrument, you wouldn't need to do this)
Next, exit the 0 folder, and go into the SoundTable/includes folder.
It should have json files called 0x1, 0x2, and so on. These represent different categories of sounds.
Each one has data for a variety of sound effects, 0x6 has by far the most, because it's for the enemies.
Everything you need to know about this part of the data can be found at this page.
The category your new sound goes into usually doesn't matter much, but there are some niche situations where it matters.
For example, during the start of Day 1 cutscene, Pikmin sounds are muted, and wont play until the first text box, when sounds in other categories still do.
For this example, we will add a new sound to the enemy category, so open 0x6.json. Adding sounds to the other categories may be problematic, because you would have to fix the "entryNumCategory" for everything in the later jsons.
First, there's a total entry count at the top of the file, increase this by 1.
Now, scroll all the way to the bottom of the json, and copy paste the last entry. By default, it should have 1037 for it's "entryNumCategory".
"entryNumCategory", "entryNum", and "entryNumGlobal" all need their values increased by exactly 1. The other values in it mostly don't matter,
although I think "type" may have some control over the sounds priority, which can lead to other sounds not playing. I'm not fully sure how this works yet.
Once this is done, 0x6.json should be good to go.

The final step is to fix the se.bms.txt we made earlier. You'll want to consult this page again to see how this file works.
As of writing this, it doesn't have much for the enemy category, though.
After opening the .txt, search for "@JUMPTABLE_60628h". This is the final sound in the normal game's jumptable for enemy sounds. The @ at the start is important, don't confuse the table entry with the data itself.
Copy the "@JUMPTABLE_60628h" line, and make a duplicate right after it. It needs a different name, so you might as well name it something logical, like "@JUMPTABLE_NEWSOUND". This will make it easier to keep track of.
Now, search for "JUMPTABLE_60628h" again, and find the second instance of it, there should be a : at the end, and no @.
We want to add a new entry immediately before it, just after the "return 0b" line preceding it.
Copy paste the following text in, replacing NEWSOUND with whatever you call the new sound (keep in mind every new sound needs a unique ID):

JUMPTABLE_NEWSOUND:
opentrack 0b @TRACK_0_START_NEWSOUND
return 0b
TRACK_0_START_NEWSOUND:
call 0b @CALL_415h
param_set_16 6b 0h
noteon 64b 8b 127b 100b 0b
finish

The final step is to make the param_set_16 line end in the ID of your new instrument. Note I said instrument (as in what was used for the IBNK0 folder), not the actual wave ID.
The ID of the bank itself is important as well, but if you used Bank ID 0, it doesn't matter. Just make it have the ID of the new instrument you added. For example, for Inst_2 in IBNK0,
the line would look like:
param_set_16 6b 2h
Don't touch the 6b part, or anything else here, besides the sound entry name.
Now, simply drag the se.bms.txt onto build.bat, and if it built correctly (make sure your new se.bms isn't 0kb), and put the new se.bms into the seq.arc archive.
Make sure you rebuild the .aaf and Banks folder with Xayr's tools, same as with replacing normal sounds.

Now we need to tell the game where to actually use the new sound. This can be complicated if you aren't knowledgeable with code editing. Luckily, new enemy sounds can be played with only edits to the AudioRes/key.arc file.
I'll explain how to use key.arc sounds for the sake of this tutorial, but if you wanted new sounds for something other than enemies, you'll need
some code edits (with the exception of cutscene sound effects, but .stb is a whole mess of its own).
First, extract key.arc, and go into the folder of your enemy of choice. There should be a .bas file for every animation, more or less.
Xayr has a tool for editing these files as well, which you should probably use. Simply drag a .bas onto the tool .exe and you should get a new .json.
You can add or remove specific sounds to play through an animation; SoundID is what sound to play, and FrameDelay is when in the animation it should play.
Knowing the actual ID of your new sound can be a pain, the enemy category normally ends at 22923, so the first new entry is 22924, and so on from there.
If you're using a different category than the enemy one, you can use this page to see the final normal ID of each category.
Once that's all done, you can drag the .json onto the bas tool and get a new .bas file, put it back in the enemy's folder, and rebuild key.arc.

At long last, you're ready to put everything together. Put the key.arc, seq.arc, pSound.aaf, and Banks folder all back into AudioRes.
If the stars happen to align, and everything miraculously works perfect, you should hear the new sound play in-game, when your enemy does the animation you changed the .bas for.
Do let me know if you have trouble with this, or if this guide is missing anything. - PikHacker


Outdated

The remainder of this page is very outdated, but I will leave it here for posterity. I highly recommend using the above guide instead.

This tutorial is designed to help you replace or mute sound files in Pikmin 2. These instructions should be relevant for Windows 7/10/11 users.

First, make sure you have Python installed. Then, download Yoshi2's sound helper and extract the contents to your root's AudioRes folder. You can use Gamecube ISO tool to expose the game's file structure (additional info can be found in General instructions). Run create_workshop.py, and wait for it to finish extracting everything.

In the waves folder are the extracted sounds which you must replace with .wav files that are at least very close in file size. It's recommended that all your sounds are in mono the same length and sample rate as the sounds they're replacing.

To change the sample rate, go to Tracks > Resample... in Audacity (Audacity 3.3.3), and change the sample rate to match the existing sound file (ex. 22050 Hz). Next, click on the Audio Setup button and then Audio Settings... where you should see Project Sample Rate. You should change this number to the sample rate you need the sound to be (it should be the same number you just used in Resample...).

To change the track to mono, go to Tracks > Mix > Mix Stereo Down to Mono. If this option is greyed out then the track is already in mono.

To modify the sound effect's volume, first click anywhere on the sound file and press Ctrl + A, then go to the toolbar and click on Effect > Volume and Compression > Amplify and modify the amplication (dB) desired. You can then click preview and apply.

Once finished, go to File > Export > Export as WAV and ensure the save as type is WAV and that encoding is set to 16-bit PCM. Replace the vanilla sound .wav file with your edited sound. For a list of sounds in wScene_0.aw, go here. Keep in mind the names of the sound files you are changing, as you will need it for the following steps.

Next, go in the workshop folder and open wsys0.xml in Notepad++. Find each sound you replaced and do the following:

1). Replace \repack\ in the file path with \waves\

2). Replace .raw at the end of the sound file name with .wav

3). Remove rate="XXXXX". This will make the program automatically calculate the sound's sample rate when it repacks the sounds. If you don't remove this, then the sound may be at the wrong pitch or speed in-game

4). Certain sounds have a "loop point" that you can change. If you needed to make one of your sounds longer than the sound it's replacing, you should change this. To help determine which sample count you want it to loop at, open the sound file in Audacity, and at the bottom where it shows the current time the sound is at, click on the small down arrow at the end and change it to hh:mm:ss + milliseconds. Now whenever you select a part of your sound in Audacity, you can see which sample point you are at which should make it much easier to create a custom loop

Once you've followed these steps for each sound you've replaced, go back to the AudioRes folder and run rebuild_soundfiles.py. Once the script is finished, open the newly created output folder. Copy every new .aw file into AudioRes/banks, and copy PSound.aaf into the AudioRes folder.

Finally you can save your .iso as trimmed using Gamecube ISO tool and if your .wav files aren't too big then everything should work perfectly!