
I'm implementing an FPGA version of the Genesis for a class project (building off of Gregory Estrade's project http://code.google.com/p/fpgagen/), and I've been working on adding the YM2612 core to the system. I've got the operator and channel calculations working thanks in large part to Nemesis's posts in the big YM2612 thread and the MAME source code. Where I'm getting stuck now is sending the channel output to the audio codec on the FPGA board. I read that the base output frequency of the YM2612 is roughly 53 kHz. My initial impression was that this was a sample of the channel output every 24 cycles, and I tried to send this directly to my audio codec which is sampling at 48 kHz. This of course does not produce enough samples, and I realized that I needed to resample the output from the FM clock rate (1.27 MHz) to 48 kHz. I confirmed this in Audacity and by slowing down the YM2612 clock by 24x (so that the channel is updated at 53 kHz) I was able to get the grand piano test note to play.
I now need to speed the YM2612 back up to its original rate and get the data to the slower audio codec. I think that a sufficiently large FIFO buffer could work, but I have a few questions about how this is implemented. In the MAME code, they have an output buffer of size 2160, which is "large enough to hold a whole frame at original chips rate." What exactly does this mean? Also, the MAME core has the luxury of starting and stopping the YM2612 for a specified number of samples, while the FPGA version is running constantly (technically, I could mimic this behavior but that would seem to be counter-intuitive). How do I keep the buffer from overflowing, other than stopping writes on Key Off? What about long held-out notes?
I'm somewhat new to audio, so I could be making some false assumptions, which I would be very grateful for anyone to correct. I'm curious about how the Sega Genesis itself handles this, and what the 53 kHz output frequency is supposed to mean (does the Genesis do its own internal resampling?). Thanks for any help you can provide! I'll be sure to release the source code for the project once everything's finished and cleaned up, if anyone's interested
