diff --git a/simulator/src/apu-worklet.ts b/simulator/src/apu-worklet.ts index 0b66b1f..ab78b3e 100644 --- a/simulator/src/apu-worklet.ts +++ b/simulator/src/apu-worklet.ts @@ -9,9 +9,14 @@ class APUProcessor extends AudioWorkletProcessor { super(); if (this.port != null) { - this.port.onmessage = (event: MessageEvent<{left: number[], right: number[]}>) => { - this.samplesLeft = this.samplesLeft.concat(event.data.left); - this.samplesRight = this.samplesRight.concat(event.data.right); + this.port.onmessage = (event: MessageEvent<"reset" | {left: number[], right: number[]}>) => { + if (event.data === "reset") { + this.samplesLeft = []; + this.samplesRight = []; + } else { + this.samplesLeft = this.samplesLeft.concat(event.data.left); + this.samplesRight = this.samplesRight.concat(event.data.right); + } }; } } @@ -24,13 +29,10 @@ class APUProcessor extends AudioWorkletProcessor { const pcmRight = this.samplesRight.splice(0, 128); for (let index = 0; index < pcmLeft.length; index += 1) { - pcmLeft[index] = pcmLeft[index] / 32767; - pcmRight[index] = pcmRight[index] / 32767; + outputLeft[index] = pcmLeft[index] / 32767; + outputRight[index] = pcmRight[index] / 32767; } - outputLeft.set(new Float32Array(pcmLeft)); - outputRight.set(new Float32Array(pcmRight)); - return true; } } diff --git a/simulator/src/apu.ts b/simulator/src/apu.ts index ccc1942..9eb7320 100644 --- a/simulator/src/apu.ts +++ b/simulator/src/apu.ts @@ -24,7 +24,6 @@ export class APU { } send(left: number[], right: number[]) { - console.log(left, right); this.processorPort!.postMessage({left, right}); } diff --git a/simulator/src/runtime.ts b/simulator/src/runtime.ts index b1a97c3..779cc25 100644 --- a/simulator/src/runtime.ts +++ b/simulator/src/runtime.ts @@ -223,6 +223,8 @@ export class Runtime { this.bluescreenOnError(start_function); } + this.apu.processorPort?.postMessage("reset"); + // new Int16Array(this.memory.buffer).slice(constants.ADDR_AUDIO_BUFFER, constants.ADDR_AUDIO_BUFFER + 2 * 512).fill(0); } diff --git a/src/badge/feature_test.zig b/src/badge/feature_test.zig index 60a61aa..b23aad7 100644 --- a/src/badge/feature_test.zig +++ b/src/badge/feature_test.zig @@ -160,6 +160,8 @@ const raw_data = std.mem.bytesAsSlice(i16, @embedFile("pepsi.raw")); var audio_offset: usize = 0; export fn audio(buffer: *volatile [2][512]i16) bool { + if (audio_offset >= raw_data.len) return false; + @memcpy(&buffer[0], raw_data[audio_offset..][0..512]); @memcpy(&buffer[1], raw_data[audio_offset..][0..512]);