diff --git a/frontends/web/ts/gb.ts b/frontends/web/ts/gb.ts index 41554b48703c259db429f696ae82603c91b32ae8..9a5729e93347fa537a54acf80d1dc594cda83234 100644 --- a/frontends/web/ts/gb.ts +++ b/frontends/web/ts/gb.ts @@ -548,6 +548,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { set frequency(value: number) { value = Math.max(value, 0); this.logicFrequency = value; + this.gameBoy?.set_clock_freq(value); this.trigger("frequency", value); } diff --git a/src/apu.rs b/src/apu.rs index 0473b30fa23a3e39211dd99490869bf61a8f1c3c..1d7c5f9fc464a65be0a434c7ca984b8add81e345 100644 --- a/src/apu.rs +++ b/src/apu.rs @@ -312,9 +312,10 @@ impl Apu { self.audio_buffer.push_back(self.output()); } - // @TODO the CPU clock is hardcoded here, we must handle situations - // where there's some kind of overclock, and for that to happen the - // current CPU clock must be propagated here + // calculates the rate at which a new audio sample should be + // created based on the (base/CPU) clock frequency and the + // sampling rate, this is basically the amount of APU clock + // calls that should be performed until an audio sample is created self.output_timer += (self.clock_freq as f32 / self.sampling_rate as f32) as i16; } }