Documentation for Memblers 2A03 Sound Emulator for SNES

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
Rumbleminze
Posts: 6
Joined: Sun Nov 19, 2023 12:57 pm

Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Rumbleminze »

Hey all!

I've been working on a port of an NES game to the SNES, and it's 90% complete, I have everything working except for the music. I've tried mimicking the approach that Infidelity did for his MM4 port, which (I believe) uses Membler's 2A03 sound emulator, along with some custom code to translate the writes to the NES audio registers for the sound emulator.

While this approach has resulted in great success for sound effects, the music has the right melody/notes but clearly the wrong instruments or something.

I've tried poking around for any documentation or information about the sound emulator without much luck, so I'm not sure where things are going wrong. Is there any place for documentation that's around? Or if anyone has ideas on other things to look into to try to get music working accurately in the port, I'd take any suggestions!

Thanks in advance!
-Rumbleminze
User avatar
Individualised
Posts: 298
Joined: Mon Sep 05, 2022 6:46 am

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Individualised »

This isn't really enough information. What do you mean by "wrong instruments"? Are pulse waves playing with the wrong duty cycle, are you talking about instruments as in the instrument system of the game's sound engine, etc?
Rumbleminze
Posts: 6
Joined: Sun Nov 19, 2023 12:57 pm

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Rumbleminze »

I'm not quite sure how to describe it because my knowledge of the SNES sound systems is pretty sparse. Maybe a video would better explain what I'm hearing:

https://www.youtube.com/watch?v=m8XC-6WliE8

All the notes/melodies are there, but it's clearly the wrong sound.
Rumbleminze
Posts: 6
Joined: Sun Nov 19, 2023 12:57 pm

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Rumbleminze »

Maybe a better way of phrasing this, is that I believe I have properly loaded Membler's 2A03 NES sound emulator in my rom, but I want to learn how I translate what the NES's writes to 4000 - 4015 to the values they need to be to be sent to the SNES's audio register.

The code I have in place is a copy of what Infidelity used for MM4, but it doesn't seem to work for Kid Icarus. I end up with 0x16 bytes of data that get sent to `APUIO0`, and much of it sounds partially correct, but there's definite problems. Are there any resources for this? Or is it jus a matter of "learn more about the NES APU and the SNES S-SMP"?
User avatar
Memblers
Site Admin
Posts: 4035
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Memblers »

There's no documentation unfortunately, but I can say one of the less-intuitive things is handling writes to $4003/$4007/$400B/$400F. Since writing there triggers various things, and in normal operation, games often will write the same value to it repeatedly. In my NSF player, those register writes go to RAM and I scoop it all up when the frame is done. To detect new writes of the same value, I start each frame with those registers zero'd out, and if it's non-zero from a write happening (luckily for me, if an actual zero was written, there would be silence), I set a per-channel trigger bit. And that status info is in one of the bytes sent to the SPC every frame. If you replaced register writes with JSRs, then it's a little more straight-forward since you can now know when a write happens, without doing stupid tricks to detect it.

In my code, IIRC I had the length counter emulated in the 65816, while faster stuff like sweeps and linear counter are handled by the SPC using the timers. I suppose that length counter status gets sent to the SPC as well, has been a while since I looked at it. From what I remember, there are quite a few different ways various audio channel can be silenced (length counter, sweep, frequency, volume, $4015 bit, decay, linear counter...) so there's a lot of things being checked that might shut down the audio. I'm not sure what's going on here, but if we knew what exactly was causing it get silenced, that could give us a pretty good clue.

If by chance you're using my old original source code, I'd recommend upgrading to a version updated by Myself086, which has some worthwhile enhancements. Especially as it sounds a lot better when lower notes are played.
https://github.com/Myself086/Project-Nested
Rumbleminze
Posts: 6
Joined: Sun Nov 19, 2023 12:57 pm

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Rumbleminze »

Thanks for the pointers Memblers!

I was aware of ProjectNested, and I'll start with updating to that version, and see if I can get anything else working.

I hadn't been using JSRs for the write reassignment, but I like that approach so I'll switch to doing that, as it looks like it'll be helpful!

Thanks again!
Rumbleminze
Rumbleminze
Posts: 6
Joined: Sun Nov 19, 2023 12:57 pm

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Rumbleminze »

I wanted to follow up on this with my results, since I got it working earlier this week.

I ended up coming across an old thread where Infidelity was working through his MM4 port, which led me to this project:

https://github.com/mandraga/upernes

which had a compiled binary of Membler's assembler, and some code around usage/transformation. Once I incorporated that everything is sounding quite good!

https://www.youtube.com/watch?v=tya6n_WiNEQ
User avatar
Memblers
Site Admin
Posts: 4035
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Memblers »

Nice, glad to hear you got it to work. Porting a game from binary is quite an accomplishment, good luck with whatever work still remains.
Rumbleminze
Posts: 6
Joined: Sun Nov 19, 2023 12:57 pm

Re: Documentation for Memblers 2A03 Sound Emulator for SNES

Post by Rumbleminze »

Release version of my port is available now, for anyone that would like to give it a try, there's still some bugs, mostly minor ones and one annoying crash that happened once and I can't reproduce, but for now I've moved on to porting my randomizer into the SNES version.

Here's the IPS version of the patch:

https://romhacks.org/romhacks/kid-icarusnes-nes/

(just don't forget to rename it from `.nes` to `.sfc` =D)
Post Reply