MiSTer-devel / Gameboy_MiSTer

Gameboy for MiSTer
105 stars 49 forks source link

Noise in the wave channel in some cases (CH3) #102

Closed brNX closed 1 year ago

brNX commented 4 years ago

Noise in the channel 3 (and probably the remaining noise in the others) is related to the missing filter (capacitor) present in the (per-channel) DAC , you can clearly hear it in this test rom sndtest.zip.

https://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware#Obscure_Behavior

static double capacitor = 0.0;

double high_pass( double in, bool dacs_enabled )
{
     double out = 0.0;
     if ( dacs_enabled )
     {
         out = in - capacitor;

         // capacitor slowly charges to 'in' via their difference
         capacitor = in - out * 0.999958; // use 0.998943 for MGB&CGB
     }
     return out;
}

The charge factor can be calculated for any output sampling rate as 0.999958^(4194304/rate). So if you were applying high_pass() at 44100 Hz, you'd use a charge factor of 0.996.

maij commented 2 years ago

I have been looking into the Gameboy APU recently, and I have tried various highpass filtering and I don't think that is the solution to the noise on the wave channel. N.B. on a real DMG/CGB there are two identical highpass filters on the left and right output channels; there isn't one filter per DAC.

Currently I don't know what the cause of the noisy wave channel is but I will keep looking.

paulb-nl commented 1 year ago

Fixed in release 20230102 with a6f94d64636a4614c7e7b0b35db522b06fbbeb1b