Close

Audio

A project log for VerilogBoy - GameBoy on FPGA

A Pi emulating a GameBoy sounds cheap. What about an FPGA?

wenting-zhangWenting Zhang 04/11/2018 at 19:470 Comments

I am almost finishing the audio part (depend on how to define audio). Currently all 4 channels are working fine with no audible problems (I am not sure how accurate it really is, but it literally "sounds" good.) The original Game Boy sound system is kind of buggy (See "Obscure Behavior" at http://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware ), and I am not currently trying to implement these bugs. Since these bugs are inconsistent among different models of Game Boys, I guess not many games are actually making using of these quirks.

There are several things in the audio part worth noting. The first is that the duty cycle. The pandocs and the Game Boy Programming Manual are describing the duty cycle setting totally different. The pandocs is defining the duty cycle to be the percentage is LOW while the GBPM is defining it to be the percentage is HIGH. I guess I would have to do some probing to figure this out.

The next problem is mixing. I am guessing that the GameBoy are using OpAmps to mixing things together rather than using digital adder. Both documents claims that each channel have a dedicated DAC. The presence of the Vin function could also be a suggestion that they are mixing in an analog manner. Also I believe that they are using a PGA to control the volume rather than digital multiplier. (If the mixer is OpAmp, then the volume control could not be a multiplier, after all). But apparently I cannot do this with an FPGA, so I am using adder and multiplier to do the job. 

Another problem is the signal sign. Audio processing nowadays usually use a signed number to represent the level. The Game Boy could possibly do the same thing (offset binary, not 2's compliment), but I think they didn't. The reason are this: The advantage of using a signed number is that it would have a constant zero level (Vmax/2), rather than a variable zero level (Vsignal/2), but the disadvantage is that it would be hard to do the volume control. For a square wave, controlling the volume would be easy when it comes to unsigned number: it simply output the volume when the waveform is high, and 0 when it is low. If it is a signed number, we can possibly do the same thing, output Vol/2 when it is high and -Vol/2 when it is low, at a cost of losing 1 bit of volume precision which is undesirable. (The reason is simple, if it is signed number, output would make sense only if Vhigh = -Vlow, this would make some combination of high and low value unusable). As a result, the Game Boy should be using unsigned number rather than signed.

Last, the current design of Sound module is using around 600 Virtex-5 LUTs, expect the number to be higher for Spartan-3E LUTs or Cyclone II LEs. This number include output adder and multipliers.

Discussions