summaryrefslogtreecommitdiff
path: root/Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md
diff options
context:
space:
mode:
Diffstat (limited to 'Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md')
-rw-r--r--Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md76
1 files changed, 76 insertions, 0 deletions
diff --git a/Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md b/Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md
new file mode 100644
index 0000000..21df1b7
--- /dev/null
+++ b/Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md
@@ -0,0 +1,76 @@
+Many thanks to ipatix and Kurausukun. Without them, none of this would be possible.
+
+Anyway, these changes will allow the game to have reduced noise and output sound at a higher base frequency.
+
+In asm/m4a_1.s, replace everything in that file with the code in the link below:
+
+[Mixer code](https://gist.github.com/ShinyDragonHunter/b65599431adfaefead614763bf1b9f92)
+
+This is the code for the mixer.
+
+In src/m4a_2.c, change the size of SoundMainRAM_Buffer to
+```c
+0xC00
+```
+Again in src/m4a_2.c, add this line right below the line mentioned above:
+```c
+BSS_CODE ALIGNED(4) u32 hq_buffer_ptr[size] = {0};
+```
+With the aforementioned changes, it should look like this:
+```c
+BSS_CODE ALIGNED(4) char SoundMainRAM_Buffer[0xC00] = {0};
+BSS_CODE ALIGNED(4) u32 hq_buffer_ptr[size] = {0};
+```
+Here, `[size]` is the length of one frame of audio, which varies by the sample rate you use. Here is a list of the possible sample rates and their corresponding frame sizes:
+```
+5734Hz: 0x60
+7884Hz: 0x84 (This mode is not aligned to the buffer length and is not supported by the mixer)
+10512Hz: 0xB0
+13379Hz: 0xE0 (This is the default engine rate; without any modifications, this is what the GBA Pokemon games use)
+15768Hz: 0x108
+18157Hz: 0x130
+21024Hz: 0x160
+26758Hz: 0x1C0
+31536Hz: 0x210
+36314Hz: 0x260
+40137Hz: 0x2A0
+42048Hz: 0x2C0
+```
+Just find the sample rate you're using and use its corresponding frame size as the size of the array. For example, for the default sample rate, the size of the array is 0xE0 (note that the size of the array actually needs to be the frame size x 4; this is why this array is of type `u32` rather than `char` or `u8`).
+
+Next, remove the following from common_syms/m4a_2.txt:
+```
+gSoundInfo
+```
+Add then add the following to the end of sym_ewram.txt:
+```
+gSoundInfo:
+ .space 0xFB0
+```
+That's the mixer stuff out of the way, and if it was done correctly, the game shouldn't be producing as much quantization noise.
+
+Optionally, you can also change the audio engine's sample rate if you're using higher-quality samples. However, be warned; this means that any fixed-frequency samples (most percussion samples) will be played at this frequency; if you keep these samples at a lower sample rate, they will get pitched up and not sound right. Resample your samples to the rate you're making the engine use, or use higher quality samples and downsample them to the proper rate.
+
+In src/m4a_2.c, look for:
+```c
+ SoundInit(&gSoundInfo);
+ MPlayExtender(gCgbChans);
+ m4aSoundMode(SOUND_MODE_DA_BIT_8
+ | SOUND_MODE_FREQ_13379
+ | (12 << SOUND_MODE_MASVOL_SHIFT)
+ | (5 << SOUND_MODE_MAXCHN_SHIFT));
+```
+For the sake of this tutorial, we'll be changing it to 36314Hz. So in that file, it would look like this:
+```c
+ SoundInit(&gSoundInfo);
+ MPlayExtender(gCgbChans);
+ m4aSoundMode(SOUND_MODE_DA_BIT_8
+ | SOUND_MODE_FREQ_36314
+ | (12 << SOUND_MODE_MASVOL_SHIFT)
+ | (5 << SOUND_MODE_MAXCHN_SHIFT));
+```
+There's another call to set the sound frequency on line 372; while it appears this code never actually affects anything since it gets overridden by the above change, for fool-proofing and if you're paranoid like me, you can change that one to match as well.
+
+And I believe that's that. If everything was done correctly (or I didn't screw something up), you will have much less noise in your sound.
+
+NOTE: The current code for the mixer does not support reverb, but the code exists and can be added without too much trouble. This will happen at a later date, and when it does, this tutorial will be updated. \ No newline at end of file