kivan117 / kgb

Gameboy Emulator
MIT License
2 stars 0 forks source link

final fantasy adventure (FFA) ch1,2 static noise #46

Open ITotalJustice opened 2 years ago

ITotalJustice commented 2 years ago

FFA sets ch1,2 to a high enough frequency that on normal hardware, it would be inaudible. the current apu impl causes the duty to be rapidly changed, which causes a high pitch static-like noise when playing.

one way of solving this (which is what i do) is this.

enum { MAX_SAMPLE_RATE = 8 };  // min = 8 (FFA), max = 16 (Zelda LA title screen)

const uint16_t ch1_freq = get_ch1_freq(gb);
const uint16_t ch2_freq = get_ch2_freq(gb);
const uint16_t ch3_freq = get_ch3_freq(gb);
const uint32_t ch4_freq = get_ch4_freq(gb);

const bool ch1_audible = ch1_freq >= MAX_SAMPLE_RATE;
const bool ch2_audible = ch2_freq >= MAX_SAMPLE_RATE;
const bool ch3_audible = ch3_freq >= MAX_SAMPLE_RATE;
const bool ch4_audible = ch4_freq >= MAX_SAMPLE_RATE;

then i just multiply the channel sample with the matching bool, to toggle sound on or off.

ITotalJustice commented 2 years ago

i have updated the post so that it's a little more clear

kivan117 commented 1 year ago

Thanks for opening this. I intend to implement a low pass filter to remove aliasing when I rewrite the APU. I believe that will also remove the artifacts heard in this instance.