Crystalis (D)PCM Bug Fix Hack Help

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
Joelle (Lonkelle)
Posts: 5
Joined: Tue Feb 01, 2022 12:48 pm

Crystalis (D)PCM Bug Fix Hack Help

Post by Joelle (Lonkelle) »

It's been a long time since I've been on these forums, like 2004 (literally) long. But I signed up once again for help in the only way you guys can (and some of you I've talked to before are still around it looks like, I saw at least Tepples and Bregelad are still back here at a least).

Anyway, Crystalis is probably my favorite NES game and recently I heard something that I can't unhear. There's a noticeable (D)PCM buzz in the end of most of the drumlines (it's basically nonstop right in the beginning of the game in the wild). I don't know how I never heard it but now I can't stop wanting to fix it. I don't have my NES to test this out but there's a game genie code in an attempt to fix it (it fails to do anything tho: https://etherealgames.com/nes/c/crystal ... nie-codes/) so I'm guessing the bug exists on the real hardware as well.

I've set up FCEUX, I've pinpointed the writes to $4010 - $4015, but I'm not sure why it's buzzing like that in the first place. It's not all drums which leads me to believe it's a DMC length problem, but no matter what values I change in the PRG ROM, it doesn't seem to fix it. Unless, of course, I disable the PCM channel entirely but I'm trying to understand a little more about game audio engines, it's been a long time. But I promise I've programmed a full NES game before (Memblers tested it for me on real hardware so I'm legit - hahahah), I'm just rusty af right now and need help.

Has anyone else encountered this sort of audio bug in a commercial NES game before?
Last edited by Joelle (Lonkelle) on Wed Feb 02, 2022 12:32 pm, edited 1 time in total.
Joelle (Lonkelle)
Posts: 5
Joined: Tue Feb 01, 2022 12:48 pm

Re: Crystalis (D)PCM Bug Fix Hack Help

Post by Joelle (Lonkelle) »

Contacted the Game Genie code author about the PCM popping Game Genie code and they said "the buzzing is a side effect of 1 Bit sampling depth voltage..[my code] removes the heuristic effect and resets the $4011 register." In effect this does remove the pop but not from the encoded sample itself, and that "reduce" itself is the elimination of the pop." and they haven't tested God Slayer (the Japanese version of Crystals).

And this whole time I was thinking it was some type of "PCM" initialization / settings problem, but the Game Genie Code person told me it might just be bad samples in Cystalis itself.

It's just odd because the first 6 drum beats in the Crystalis intro all have clean ends, UNTIL the 8th drum beat, then the buzzing starts on the PCM channel (and is basically consistent in the first "Wild Fields" section of the game). So maybe some samples have bad beats.

Now I just need to figure out how to extract PCM samples from an NES rom like Crystalis. How hard can that be to remember? 😅
Last edited by Joelle (Lonkelle) on Wed Feb 02, 2022 12:32 pm, edited 1 time in total.
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Crystalis (D)PCM Bug Fix Hack Help

Post by Quietust »

Setting some breakpoints in the game's music code, it looks like it writes $00 -> $4013 every frame (which changes the PCM sample length to 1 byte the next time the sample restarts), but it also writes $1F -> $4015 four times every frame (which causes PCM samples to constantly restart if they were stopped).
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
Joelle (Lonkelle)
Posts: 5
Joined: Tue Feb 01, 2022 12:48 pm

Re: Crystalis (D)PCM Bug Fix Hack Help

Post by Joelle (Lonkelle) »

also writes $1F -> $4015 four times every frame
Found the RAM that writing $1F is dependent on, but still need to keep tracing back to figure out why it's writing it 4 times a frame at all in the first place. Dang this is kinda fun. Thanks for your help Quietust, when I was here in 2004 you always helped me back then too. V much appreciate it.
steve_hacks
Posts: 6
Joined: Tue May 14, 2019 1:25 pm

Re: Crystalis (D)PCM Bug Fix Hack Help

Post by steve_hacks »

Coincidentally, I've been working on disassembling Crystalis's sound code the last few weeks.

It looks like what's happening is that the "D1" instruction in the noise channel data (i.e. at $31072, $3107c, and others) triggers writing $00 followed immediately by $3e to $4013, setting DMC to a ~30ms sample. The next frame, at the very beginning of the audio processing (at $301f3), the game checks the $4015 status to see if DMC has any length left, and if so, it zeros out $4013 again, setting it to effectively a 1-byte sample at $3fa00, at which it (the DMA) reads $fe.

I don't know why this $fe value causes buzzing, unless there's some effect that happens when the DMC reaches the end of the sample that causes the level to change. But when I replace it with $ff, the buzz disappears entirely (I think?). Other values make the buzz a lot worse, such as $7f.

The game uses DMC in the BGM tracks as a "kick drum", sometimes (but not always) combined with a noise-channel "snare drum". The sample occupies about 1k of ROM between $3fa00 and $3fde1 (inclusive), but as far as I can tell, none of those bytes actually matter as far as the quality of the kick drum goes (I replaced it with random noise, constant zeros, and a chunk of assembly instructions, and nothing seemed to change). Only the first byte makes any difference, both for the kick (it's a lot softer with other values) and for the buzz.

To that end, I believe we (the randomizer, specifically) should be okay to continue using this for extra routines, as long as we leave $3fa00 as $ff.
Joelle (Lonkelle)
Posts: 5
Joined: Tue Feb 01, 2022 12:48 pm

Re: Crystalis (D)PCM Bug Fix Hack Help

Post by Joelle (Lonkelle) »

Oh hey Steve, I didn't know you used these forums. I literally only came back on here to post about the solution I shared with you on Discord so it's cool you're on these forums too. I used to use NesDev forums all the time when I was a kid. I even made a home-brew game when I was 15, but it's hardly any fun, I'm just happy I did It (hell, I still play on emulators if only for my own pride and vanity).

Anyway, the reason I'm here - just as an update for everyone, I actually finished the hack last night and it sounds worlds better to me. I've submitted the bug fix to RomHacking.net so the rest of the world can listen to the music, as it was intended, without the buzz.

https://twitter.com/Lonkelle/status/1490800635716984834

PS. I'll edit this post with the RHDN patch when they finish reviewing it.
Joelle (Lonkelle)
Posts: 5
Joined: Tue Feb 01, 2022 12:48 pm

Re: Crystalis (D)PCM Bug Fix Hack Help

Post by Joelle (Lonkelle) »

For everyone who comes here looking for the fix for this, I've packaged it up here: https://www.romhacking.net/hacks/6589/ - enjoy. Thanks Quietust / steve_hacks; I credited you both on the romhacking listing for helping me debug this. Really appreciate your help especially Quietust, I have appreciated your help since I was a 14 year old punk making NES homebrew! Glad you're still around - and I'm also kind of shocked your emulator is still the only one that properly emulates "random fixed color output from PPU reads". You and Kevin Horton discovered that in 2004, but no modern emulator can emulate the demos that work solely on Nintendulator.
User avatar
dink
Posts: 157
Joined: Sun Jan 12, 2020 8:42 pm

Re: Crystalis (D)PCM Bug Fix Hack Help

Post by dink »

Nice work on the Crystalis Patch!
I'm curious about the "random fixed color output from PPU reads" mode and possibly some demo name's that use it?
Post Reply