HQ sound in native GBA games is entirely possible

Deleted member 42501

Well-Known Member
OP
Member
Joined
Jun 16, 2006
Messages
1,724
Trophies
2
XP
4,259
There are two sound drivers used in the GBA. The default one for most games is called MP2K/Sappy and is very crunchy. There is a better one that was reverse engineered from Golden Sun and applied to Pokemon:



Sound quality is noticeably better and its all been well documented:

https://www.pokecommunity.com/showthread.php?t=324673

https://github.com/ipatix/gba-hq-mixer

https://github.com/pret/pokeemerald/wiki/Implementing-ipatix's-High-Quality-Audio-Mixer

"All GBA games use the sound driver that comes in the GBA SDK, m4a (also known as mp2k or "Sappy"). While not a bad engine, it does have the issue of being notoriously noisy. In response to this, ipatix created a custom audio mixer for use in the m4a engine based on the custom engine of the Golden Sun games. This engine has two major benefits:


  1. Less noise. The SDK's audio mixer mixes every channel in 8-bit before also outputting at the final 8-bit DAC. What this means is that every additional DirectSound channel will add more noise, and with enough channels it can get pretty bad. This mixer avoids that issue by mixing the audio in a 16-bit space so that the only conversion to 8-bit is at the final DAC output; this means that no matter how many channels you have, the amount of noise will be the same (equivalent to having a single channel worth of noise in the original mixer).
  2. Better performance. The code is highly optimized and contains a self-modifying code loop that is loaded into RAM and allows for faster processing than the SDK mixer, even despite the new 16-bit arithmetic. For more details on how the mixer itself actually works, visit ipatix's repository for the mixer. However, none of this information is necessary if you just want to use it in your game, and with that said, we can now move on to the actual tutorial."


Theoretically we can combine this with OPEN_AGB_FIRM in the form of patches that add in the new calls as other titles have had it done before:

oDOnXgV.png


https://ffhacktics.com/smf/index.php?topic=12970.0

From a quick glance we'd need to find the address and replace via IPS. This will probably have to be done manually for each title so would be a community effort.

I do think its entirely feasible though as I've heard the new sounds hack applied to a few other titles and the difference is quality is almost DS level smooth in comparison to the crunch GBA sound. All of the background hiss is gone and we get 16 bit sound as opposed to an 8 bit mixdown.

Patch info for details of application:


https://www.romhacking.net/hacks/6951/

In combination with OPEN_AGB_FIRM it could be a game changer as the Gamma customization there makes the titles look amazing and this could do the same for sound using the IPS facility:

https://gbatemp.net/threads/open_agb_firm-discussion-thread.570844/




@godreborn @shoco @Dartz150 @NanashiFinal13 @PabloMK7 @Sono @DrgnMasterKota @IcySon55 @MasterFeizz
 

metroid maniac

An idiot with an opinion
Member
Joined
May 16, 2009
Messages
2,081
Trophies
2
XP
2,619
Country
Theoretically we can combine this with OPEN_AGB_FIRM in the form of patches that add in the new calls as other titles have had it done before:
I'm not sure what this has to do with open_agb_firm particularly. The ipatix sound driver runs on real GBA hardware and anything else that runs GBA games.
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,321
Country
United Kingdom
Interesting development, will have to do some reading. With some of the work done on sappy and general GBA assembly/quasi decompilation and code injection I wonder if a generic patcher (or tool to accelerate the creation of patches) could be created.

Also eagerly await the can't rip audio from this hack threads and debates on purity in the years to come.
 

metroid maniac

An idiot with an opinion
Member
Joined
May 16, 2009
Messages
2,081
Trophies
2
XP
2,619
Country
Interesting development, will have to do some reading. With some of the work done on sappy and general GBA assembly/quasi decompilation and code injection I wonder if a generic patcher (or tool to accelerate the creation of patches) could be created.

Also eagerly await the can't rip audio from this hack threads and debates on purity in the years to come.
According to the comments in this file, the HQ audio driver in that patch uses a little more RAM than the default driver which could complicate a generic patch.
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,321
Country
United Kingdom
According to the comments in this file, the HQ audio driver in that patch uses a little more RAM than the default driver which could complicate a generic patch.
Wonder if we could then use the RAM available in many flash carts for something here. Would be an amusing twist in the RAM expansion saga.
 
  • Like
Reactions: StrayGuitarist

DSoryu

GBA/NDS Maniac
Member
Joined
May 5, 2010
Messages
2,356
Trophies
2
Location
In my house
XP
4,757
Country
Mexico
I did some research about this method of GBA sound improvements with some interesting results, but halted the work to focus in other projects.

Yes, it is posible to build a database to patch the games on runtime, the only downside would be to gather enough interested people to document each game so we can cover up every game from the GBA library, and afaik, this engine is only patchable if the base game has the "sappy" sound engine, so there's also that.

I have a video showing how this works with Castlevania: Harmony of Dissonance as an example because this engine not only does improve the sound quality, but also allows to have room for more sound output "channels" (those are not actual channels, is just that two sounds are mixed in a single channel) so you can make things like this:



My plan is to remaster the entire soundtrack from the Castlevania Games with music I re-arranged and improve some tracks on HoD, so it would be interesting to see how this performs at runtime.
 

Deleted member 42501

Well-Known Member
OP
Member
Joined
Jun 16, 2006
Messages
1,724
Trophies
2
XP
4,259
Great contributions. I do think its entirely feasible but its not going to be a one click solution due to the process at work.

Probably best we start off with the bigger titles or whatever members have their own passion for like @Dartz150 shows. The sound difference is immense.

Also, quoting this to bring it over to the relevant thread:

Per ipatix/gba-hq-mixer/readme.md:
In order to maximize performance for this timing critical step, this mixer code (which is what we'll replace) is copied to IWRAM and runtime. This creates somewhat of a challange to replace the function since you can no longer simply replace a function in ROM and you're good. Free IWRAM space is usually fairly limited in most games (32 KiB total) and it's not always obvious which space is free.
Since the original code also resides in IWRAM you might consider that the new code simply goes into place of the old one. Unfortunately this usually does not work out since my code is generally a bit larger. So you'll have to find additional space for the code. The final size required depends on the configuration, so you should assemble the file like above and check the actual number of bytes required.

There's going to be a lot of legwork going into a Patch Database for this, since each game would have to be investigated by hand (per pret, they forked off a customized version of the ipatix patch for Pokemon Emerald; I'm not seeing an equivalent in the RS or FRLG projects but that could just be small reference pools)

The application to other titles shows that it is entirely possible on real hardware. For anyone reading who codes an emulator/core it would most likely be even easier as you could create a module that intercepts and redirects the calls to use the new engine externally like a filter or plugin. No memory limits of running native then.

This thread is just for the real hardware side so we could boost the sound on 3DS as the OAF corrections make the picture look good.

I do think that by starting it we could get a good catalog of basic factors together of what to look for, what is doable etc.. that would make contributing solutions a lot easier. The linked documents cover a lot of ground but a clear IF AND OR THEN to get an outline would be good for interested newcomers.

Try one of the HQ sound patches thats already out. Pokemon sounds amazing now as it was horrible on 3DS before. Add in the Gamma correction and its better than a GBA is. How does Twilight Menu get better quality sound that a DS? Is there something there that could help? @RocketRobz
 

metroid maniac

An idiot with an opinion
Member
Joined
May 16, 2009
Messages
2,081
Trophies
2
XP
2,619
Country
The application to other titles shows that it is entirely possible on real hardware. For anyone reading who codes an emulator/core it would most likely be even easier as you could create a module that intercepts and redirects the calls to use the new engine externally without memory limits of running native.
mGBA's XQ audio does something like this, but it's experimental.
 

Deleted member 42501

Well-Known Member
OP
Member
Joined
Jun 16, 2006
Messages
1,724
Trophies
2
XP
4,259
Interesting.

Can anyone get profi200s attention to see whats possible on the OPEN_AGB_FIRM side? The ability to load IPS patches on boot is very handy but seeing as we're dealing with bare metal its limited in game.

Still would be good to get his input as his work is very good over standard.

Another interesting resource:

https://gc-forever.com/wiki/index.php?title=Game_Boy_Interface/Standard_Edition#Sound_emulation

Taken from here:

https://github.com/profi200/open_agb_firm/issues/92

The 3DS doesn't filter so its sound is noticeably crunchy. I wonder if its possible to implement OAF using Twilight Menu for more resources? @RocketRobz



I'd like to start with a patch for Minish Cap as a POC.
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,310
Country
Hungary
It is possible to implement load-time patching, as the main FCRAM is attached to a cartridge emulator residing inside of the SoC (meaning the cartridge runs from 3DS RAM). The only reason it only works at load-time, is because once the GBA mode is started, the FCRAM is removed from the 3DS side, and mapped to the cartridge emulator instead, meaning we can't do shenanigans to rewrite the cartridge contents at runtime.

This is also why only a few limited save chip options are available, as only those are built into the cartridge emulator hardware.
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,310
Country
Hungary
Can someone please test this?
I don't know if it actually works or not, as in mGBA it sounds basically the same, but on GBA SP (speaker or headphones) it actually sounds worse.

And yes, it's a save file, I did not upload the wrong file. Need European Emerald ROM (BPEE00) with SHA-256 A9DEC84DFE7F62AB2220BAFAEF7479DA0929D066ECE16A6885F6226DB19085AF.
  • after loading in, immediately start walking right until the dialog pops up
  • after dialog pops up, press A
  • lower your volume until you're kicked back to the room
  • set your volume back to what it was
  • enjoy?
It may take multiple tries.
 

Attachments

  • pokeace.zip
    3.9 KB · Views: 33

DSoryu

GBA/NDS Maniac
Member
Joined
May 5, 2010
Messages
2,356
Trophies
2
Location
In my house
XP
4,757
Country
Mexico
Can someone please test this?
I don't know if it actually works or not, as in mGBA it sounds basically the same, but on GBA SP (speaker or headphones) it actually sounds worse.

And yes, it's a save file, I did not upload the wrong file. Need European Emerald ROM (BPEE00) with SHA-256 A9DEC84DFE7F62AB2220BAFAEF7479DA0929D066ECE16A6885F6226DB19085AF.
  • after loading in, immediately start walking right until the dialog pops up
  • after dialog pops up, press A
  • lower your volume until you're kicked back to the room
  • set your volume back to what it was
  • enjoy?
It may take multiple tries.

Wow, interesting and cool way to execute this!!

I've tested this on different alternatives and these are the results:

  • GBA AGB-01: Sounds somewhat better, the GB Channels sound crispier and the FIFO ones more clear, a bit of aliasing though.
  • GBA SP AGS 101: Works but despite the sound being a bit better, there's aliasing noise in the background.
  • Gameboy micro: It has the best result among every GBA model, but the volume sounds somewhat loud, aliasing hardly noticeable.
  • Nintendo DS Lite: Same as GBA SP but the sound seems less aliased (?)
  • Nintendo DSi thru GBARunner2: It hangs/crashes with earrape garbage sounds exactly when the egg opens.
  • GBA Consolizer: Sames as GBARunner2
  • Gamecube Gameboy Player: Sames as GBARunner2.
  • 3DS thru OAF: The sound improves a lot, with a bit of aliasing in the background.
  • 3DS thru mGBA: Not audible differences.
  • 3DS thru gpSP: Same as GBARunner2
  • No$GBA: Sounds fine but without noticeable differences.
  • VisualBoyAdvance: Same as GBARunner2
And on every platform where this works, it hangs (just freezes, no garbage earrape) after you go outside of a Pokémon Center.
 
Last edited by DSoryu,

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,310
Country
Hungary
Wow, interesting and cool way to execute this!!

I've tested this on different alternatives and these are the results:

  • GBA AGB-01: Sounds somewhat better, the GB Channels sound crispier and the FIFO ones more clear, a bit of aliasing though.
  • GBA SP AGS 101: Works but despite the sound being a bit better, there's aliasing noise in the background.
  • Gameboy micro: It has the best result among every GBA model, but the volume sounds somewhat loud, aliasing hardly noticeable.
  • Nintendo DS Lite: Same as GBA SP but the sound seems less aliased (?)
  • Nintendo DSi thru GBARunner2: It hangs/crashes with earrape garbage sounds exactly when the egg opens.GBA Consolizer: Sames as GBARunner2
  • Gamecube Gameboy Player: Sames as GBARunner2.
  • 3DS thru OAF: The sound improves a lot, with a bit of aliasing in the background.
  • 3DS thru mGBA: Not audible differences.
  • 3DS thru gpSP: Same as GBARunner2
  • No$GBA: Sounds fine but without noticeable differences.
  • VisualBoyAdvance: Same as GBARunner2
And on every platform where this works, it hangs (just freezes, no garbage earrape) after you go outside of a Pokémon Center.

Oh yeah, I forgot to say that Pokémon Center are a bit weird, as they hang for a really long time (on authentic GBA it just hangs for a second).
Also yeah, DO NOT visit the link cable area, as that is where I store the code, LMAO. I don't understand gas (I only know how to use ARMIPS), so I wasn't able to hack the code to be in a safe space at multiple locations :/
If I had the code in ARMIPS format then I could absolutely hack it into multiple sections into IWRAM in a way where it would not interfere with a singleplayer experience (I store the code in the link cable and wireless adapter buffers).

As for the ACE I'm using, no wonder some emulators crap out, as the code executes from 0x0300FFFF (?), but the valid IWRAM range is 0x03000000 to 0x03007FFF. Although don't think that is the main culprit though, as the GBA BIOS accesses the exception handler location at 0x04000000[-4] (which is the same as 0x03007FFC), so I guess those emulators don't emulate the ARM7 bit1 PC bug properly, which is what causes invalid ARM code to be executed? It's a guesswork at this point.
 

Deleted member 42501

Well-Known Member
OP
Member
Joined
Jun 16, 2006
Messages
1,724
Trophies
2
XP
4,259
I didn't find the sound quality as noticeably different like the video in OP. Are you using that method @Sono or something else? Bit less hiss but not the same fidelity of sound as the mods. Using O_A_F on n3DS, headphones not supported so main speakers.

Interesting application though. Lateral thinking on display.
 
  • Like
Reactions: Sono

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,310
Country
Hungary
I didn't find the sound quality as noticeably different like the video in OP. Are you using that method @Sono or something else? Bit less hiss but not the same fidelity of sound as the mods. Using O_A_F on n3DS, headphones not supported so main speakers.

Interesting application though. Lateral thinking on display.

Edit: I bodged your patch into Emerald using ACE. The audio engine is loaded only at start, so I can overwrite it with no issues.

I think what's happening is that Emerald's samples might simply just already be bad and noisy, so trying to make it sound better using a better mixer has no noticable effect because the samples in the game are already bad. In fact, I think this might be the case, as it's extremely suspicious to me that using this patch INCREASES noise.
Makes me feel like they have *planned* for this high-noise engine, and mastered the files in such a way that it's already fighting against the noisy engine, because it's extremely suspicious that upon even closer examination, sound effects sound slightly better, but the music has a constant noisy hissing in the background with the patch.

Although the other problem might be that while I'm using unused buffers, there are two variables which get checked every frame, which then causes undefined behavior and memory corruption (as either parts of the buffer, and/or those variables get reset), but in certain buffers this memory corruption happens in just a way where it doesn't cause a crash, but causes the audio code to be corrupted.

Sadly I'll need to reverse-engineer the assembly code, as I don't understand the gas syntax, and I'll have to port it to ARMIPS, so I could make this in-memory patch much safer, where I can leave out those two variables which keep causing me trouble.


And as a sidenote, I also have to find a new entrypoint, as the current entrypoint is not reusable (after the egg hatches, the entrypoint is gone), and I have an original Emerald cartridge, meaning that I can't just patch the ROM itself. Also my fake Pokémon cart doesn't have an SRAM battery (it saves back into the ROM), so I can't test on that either, as I can't flash my save to it.
 
Last edited by Sono,

Deleted member 42501

Well-Known Member
OP
Member
Joined
Jun 16, 2006
Messages
1,724
Trophies
2
XP
4,259
Yeah, thats makes sense. Sort of like how they skewed the color palettes on some titles to compensate for the earlier GBA screens.

mbxh0ygcjt131.png


I do suspect there is more to this as the write ups are quite detailed and a case by case thing. I just tried out M3 and its almost totally free of hiss now:

https://mother4ever.net/mother3-hq/

So your thinking about the samples and how the sound is processed is likely correct. Turds and polish come to mind.

Minish Cap sounds so bad on 3DS. Oddly none of these titles sounded that bad on OG hardware or maybe I never noticed as the speakers were different and I was less finicky. Mario vs DK is beyond harsh though and even distorts at any volume.
 
  • Like
Reactions: Sono

fleroviux

New Member
Newbie
Joined
Mar 4, 2023
Messages
1
Trophies
0
Age
27
XP
21
Country
Germany
In my emulator NanoBoyAdvance I have implemented a high-quality audio mixer for MP2K/Sappy (roundabout 1.5 years ago).
It works by detecting calls to m4aSoundMain (more accurately SoundMainRAM) and reimplementing MP2K's mixer in native C++ code with enhancements such as rendering at a higher sample rate (64 kHz), using floating-point arithmetic and cubic sample interpolation.

Most of the relevant code can be found here:
github . com / nba-emu / NanoBoyAdvance / blob / master / src / nba / src / hw / apu / hle / mp2k.cpp
(I have to obfuscate the link because of the lame anti-spam protection)

I have some examples of the improved audio quality in this video:
 

Deleted member 42501

Well-Known Member
OP
Member
Joined
Jun 16, 2006
Messages
1,724
Trophies
2
XP
4,259
Interesting approach, exactly what I had in mind as its better than patching each game. Question is can @Sono or another dev think of a way to implement this?

Are the DS and GBA sides of the 3DS totally sandboxed? What I'm thinking is would it be better (possible?) to run OAF hooked into DS mode for more resources available ala Adrenaline on Vita?
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: https://youtu.be/MddR6PTmGKg?si=mU2EO5hoE7XXSbSr