Skip to content

Commit

Permalink
Small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperAuguste committed May 19, 2024
1 parent b708d02 commit d3c7cb2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
18 changes: 10 additions & 8 deletions simulator/src/apu-worklet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
}
Expand All @@ -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;
}
}
Expand Down
1 change: 0 additions & 1 deletion simulator/src/apu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class APU {
}

send(left: number[], right: number[]) {
console.log(left, right);
this.processorPort!.postMessage({left, right});
}

Expand Down
2 changes: 2 additions & 0 deletions simulator/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions src/badge/feature_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit d3c7cb2

Please sign in to comment.