summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinyDragonHunter <32826900+ShinyDragonHunter@users.noreply.github.com>2018-12-19 05:15:55 +0000
committerShinyDragonHunter <32826900+ShinyDragonHunter@users.noreply.github.com>2018-12-19 05:15:55 +0000
commitb292a731064f1220a655d9359911cf50312d86e1 (patch)
tree1c06b4a3ee85eebe9f5a33fc7c190251843c3b6f
parentdc65aef8dc6c0a900c186ab54001b3f932c582a7 (diff)
Updated Reduce Noise and Improve Sound Quality (Implementing a New Mixer) (markdown)
-rw-r--r--Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md26
1 files changed, 13 insertions, 13 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
index 53137e6..9dbca6e 100644
--- a/Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md
+++ b/Reduce-Noise-and-Improve-Sound-Quality-(Implementing-a-New-Mixer).md
@@ -2,17 +2,17 @@ Many thanks to ipatix and Kurausukun. Without them, none of this would be possib
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:
+In [asm/m4a_1.s](https://github.com/pret/pokeemerald/blob/master/asm/m4a_1.s), replace everything in that file with the code in the link below:
-[Mixer code](https://gist.github.com/Kurausukun/004b2509e8655228e3feefcb6b04a4e9)
+[Mixer code](https://gist.github.com/ShinyDragonHunter/6571250991f4b0f560206e2201e27e55)
This is the code for the mixer.
-In src/m4a_2.c, change the size of SoundMainRAM_Buffer to
+In [src/m4a_2.c](https://github.com/pret/pokeemerald/blob/master/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:
+Again in [src/m4a_2.c](https://github.com/pret/pokeemerald/blob/master/src/m4a_2.c), add this line right below the line mentioned above:
```c
BSS_CODE ALIGNED(4) u32 hq_buffer_ptr[size] = {0};
```
@@ -38,11 +38,11 @@ Here, `[size]` is the length of one frame of audio, which varies by the sample r
```
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:
+Next, remove the following from [common_syms/m4a_2.txt](https://github.com/pret/pokeemerald/blob/master/common_syms/m4a_2.txt):
```
gSoundInfo
```
-Add then add the following to the end of sym_ewram.txt:
+Add then add the following to the end of [sym_ewram.txt](https://github.com/pret/pokeemerald/blob/master/sym_ewram.txt):
```
gSoundInfo:
.space 0xFB0
@@ -51,7 +51,7 @@ That's the mixer stuff out of the way, and if it was done correctly, the game sh
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:
+In [src/m4a_2.c](https://github.com/pret/pokeemerald/blob/master/src/m4a_2.c), look for:
```c
SoundInit(&gSoundInfo);
MPlayExtender(gCgbChans);
@@ -73,13 +73,13 @@ There's another call to set the sound frequency on line 372; while it appears th
Now all that's left, and this is optional as well, is fixing the reverb for your new sample rate. At rates other than the default rate of 13379Hz, the game's reverb sounds much less pronounced, and if you go high enough, it gets to the point that you can't even really tell it's there. This is honestly a matter of preference--some people think reverb sounds good, some people prefer not to have it--but for the sake of completeness and those who like reverb, I will explain how to get the reverb to sound like it does at the default sample rate.
-I talked about it like it's a huge deal, but there's actually not too much we need to change--in fact, the only thing that needs changing is the size of the direct sound buffer the game uses. This is defined in two different files--`constants/m4a_constants.inc` and `include/gba/m4a_internal.h`. Opening these files, you will see that the buffer's default size is 1584, or 0x630 in hex. Where does this number come from, you may ask--well it comes from the frame size I mentioned up above. The buffer is designed to last 7 frames in the game, plus some extra space at the end, so multiply your frame size to get the value you need. If we recall that the frame size of the default sample rate is 0xE0, we can do 0xE0 x 7, and we will find that it equals 0x620--which is 0x10 less than the original value (this is the extra space I mentioned). So find your sample rate in the table again, multiply it by 7, and replace the value in those two files with your new value. But we're not quite done yet!
+I talked about it like it's a huge deal, but there's actually not too much we need to change--in fact, the only thing that needs changing is the size of the direct sound buffer the game uses. This is defined in two different files--[constants/m4a_constants.inc](https://github.com/pret/pokeemerald/blob/master/constants/m4a_constants.inc) and [include/gba/m4a_internal.h](https://github.com/pret/pokeemerald/blob/master/include/gba/m4a_internal.h). Opening these files, you will see that the buffer's default size is 1584, or 0x630 in hex. Where does this number come from, you may ask--well it comes from the frame size I mentioned up above. The buffer is designed to last 7 frames in the game, plus some extra space at the end, so multiply your frame size to get the value you need. If we recall that the frame size of the default sample rate is 0xE0, we can do 0xE0 x 7, and we will find that it equals 0x620--which is 0x10 less than the original value (this is the extra space I mentioned). So find your sample rate in the table again, multiply it by 7, and replace the value in those two files with your new value. But we're not quite done yet!
-The last thing we need to do is update the mixer code to use this new value. By default, it uses a hardcoded 0x630 value to match the default buffer. Changing that is actually going to be harder than expected due to the way immediate values work in ARM. The statement in question can be found on line 963 of our new `asm/m4a_1.s`. If you're using anything under 36314Hz, you should be fine to just replace the value. However, for rates 36314Hz and above, the size of the buffer is too large to fit into the immediate field of a MOV instruction. Generally, the solution to this is finding values that can be bit-shifted to equal your new size. This works nicely for 36314Hz's buffer size of 0x10A0--you'll find that 0x85 << 5 = 0x10A0. And luckily, ARM lets us bit-shift right in the operand, so we can do:
+The last thing we need to do is update the mixer code to use this new value. By default, it uses a hardcoded 0x630 value to match the default buffer. Changing that is actually going to be harder than expected due to the way immediate values work in ARM. The statement in question can be found on line 963 of our new [asm/m4a_1.s](https://github.com/pret/pokeemerald/blob/master/asm/m4a_1.s). If you're using anything under 36314Hz, you should be fine to just replace the value. However, for rates 36314Hz and above, the size of the buffer is too large to fit into the immediate field of a `mov` instruction. Generally, the solution to this is finding values that can be bit-shifted to equal your new size. This works nicely for 36314Hz's buffer size of 0x10A0--you'll find that 0x85 << 5 = 0x10A0. And luckily, ARM lets us bit-shift right in the operand, so we can do:
+```asm
+mov r0, #0x85
+str r6, [r9, r0, lsl#5]
```
-MOV R0, #0x85
-STR R6, [R9, R0, LSL#5]
-```
-In place of the original STR command. For 40137Hz, 0x93 << 5 works. And for 42048Hz, you can do 0x134 << 4. Replace them just like the statement above, and you'll be good.
+In place of the original `str` command. For 40137Hz, 0x93 << 5 works. And for 42048Hz, you can do 0x134 << 4. Replace them just like the statement above, and you'll be good.
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. \ No newline at end of file