Page 1 of 1

Need help w/YM2413

Posted: Mon Jul 14, 2014 8:05 pm
by neologix
Ok, so I know the YM2413 isn't strictly Genesis, being a Japanese SMS-only chip for the most part. I asked this question on SMS Power but so far have gotten no response, probably due to a huge likelihood that the intersection of devs with any YM2413 knowledge, devs with C/C++ knowledge, and devs with JavaScript knowledge is only...myself. :(

I'm almost done with porting the MAME/SMSPlus/Genesis Plus GX YM2413 (ym2413.c rather than emu2413.c) to my web VGM player but it sounds all wrong (ignore me muting all YM2413 channels except channel 1 for now). The songs to listen to are in the "test" playlist:
  • test-ym2413.vgm (an A440 played with the "guitar" instrument for 2/10ths of a second)
  • BIOS.vgm (the SMS Space Harrier BIOS).
  • Green Hills Zone OPLL.vgm (ValleyBell's OPLL cover); GHZ sounds particularly incorrect.
MaliceX/DJTuBig pointed out over IRC it might have to do with FNUM calculation, but I went over that bit a couple of times and couldn't tell if it was the problem area or not. It also looks like setting instrument values is borked, but I don't know how to fix it. I have an update to the script that's still bad but not quite as much, but keep in mind I'm leaving only channel 1 active on YM2413 during development phase. My complete lack of familiarity with the YM2413 vs the YM2612 is very apparent in this process :(

Please help me figure out what needs to be fixed so I can move on to adding unzip, writing a basic sampler script to handle YM2612 DAC, and finalizing VGM 1.50 spec on the web player, thanks!

Posted: Mon Jul 14, 2014 11:21 pm
by Nemesis
Make things as simple as possible. Setup a single operator directly outputting a sine wave at a given frequency. Check the audio output and make sure the frequency is correct. If it isn't, you've either got a problem with your phase generator (IE, bad FNUM calculation, wrong clock rate, etc), or a problem resampling the output of the YM2612. Look there for the problem. If the frequency is correct, you've probably got a problem with the input between operators. Doublecheck the way you feed the output of one operator into the input of another, and make sure all your algorithm patterns are correct.

If after everything, you still can't find the problem, use the debugger. You're porting an existing core. Try adding some debug output logging into the working cores in mame or genesis plus gx or whatever, and compare those numbers with your own. Somewhere something's not going to match up. If you need to, step through line by line in the debugger until you find the difference.

Posted: Tue Jul 15, 2014 12:14 pm
by Gigasoft
I can't see any problem with the calculation. Could you be reading the VGM file wrong?

Posted: Tue Jul 15, 2014 9:21 pm
by neologix
@Gigasoft - the VGM file parsing doesn't show problems, and the actual sample generation is all in the chip's code. I'm looking at calculation right now to make sure I didn't mistype something.

@Nemesis - (I think you meant YM2413 ;) ) I really wish I could simplify the thing at this stage (especially with regards to testing op connection), but until I get working output I don't feel comfortable beyond actively muting all channels except ch 1 yet. So far adding logging results in me finding that my calculate function results in zeroes for output, so I'm already seeing results. This is very similar to what happened with my YM2612 script, so I hope I can narrow things down from this point.

Posted: Wed Jul 16, 2014 11:42 pm
by neologix
Update: IT NOW WORKS!!! ^____^

The problem was porting YM2413Write. It seems writing to a register was originally done in two separate steps: latch the register's address OR set the chip's status, THEN write the value to the register. Status wasn't being set to 1 until after certain writes because I originally ported it wrong.

I've now simplified it to a one-step write-to-register, always keeping status at 1, and IT FINALLY WORKS.

Now both the YM2413 and YM2612 need some fine-tuning to fix minor errors in the generated FM waves, but I'm just glad to have reached this point. ^_^