Skip to content

Commit 17e9983

Browse files
committed
Hook up sound from jsbeeb
This patch does get us working sound, but during loading a modal full-window error pops up: Uncaught runtime errors: ERROR The operation was aborted. Clicking the X in the top right continues to a working owlet. I've failed to work out where this is coming from. Fixes #80
1 parent e8f392d commit 17e9983

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/emulator.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import $ from "jquery";
12
import _ from "underscore";
23
import {Cpu6502} from "jsbeeb/6502";
34
import * as canvasLib from "jsbeeb/canvas";
45
import {Video} from "jsbeeb/video";
56
import {Debugger} from "jsbeeb/web/debug";
6-
import {FakeSoundChip} from "jsbeeb/soundchip";
7-
import {FakeDdNoise} from "jsbeeb/ddnoise";
7+
import {AudioHandler} from "jsbeeb/web/audio-handler";
88
import * as models from "jsbeeb/models";
99
import {Cmos} from "jsbeeb/cmos";
1010
import * as utils from "jsbeeb/utils";
@@ -98,8 +98,14 @@ export class Emulator {
9898

9999
this.video = new Video(Model.isMaster, this.canvas.fb32, _.bind(this.paint, this));
100100

101-
this.soundChip = new FakeSoundChip();
102-
this.ddNoise = new FakeDdNoise();
101+
const audioFilterFreq = 7000;
102+
const audioFilterQ = 5;
103+
const noSeek = false;
104+
this.audioHandler = new AudioHandler($("#audio-warning"), audioFilterFreq, audioFilterQ, noSeek);
105+
// Firefox will report that audio is suspended even when it will
106+
// start playing without user interaction, so we need to delay a
107+
// little to get a reliable indication.
108+
window.setTimeout(() => this.audioHandler.checkStatus(), 1000);
103109

104110
this.dbgr = new Debugger(this.video);
105111
const cmos = new Cmos({
@@ -118,8 +124,8 @@ export class Emulator {
118124
Model,
119125
this.dbgr,
120126
this.video,
121-
this.soundChip,
122-
this.ddNoise,
127+
this.audioHandler.soundChip,
128+
this.audioHandler.ddNoise,
123129
cmos,
124130
config,
125131
);
@@ -138,7 +144,7 @@ export class Emulator {
138144
}
139145

140146
async initialise() {
141-
await Promise.all([this.cpu.initialise(), this.ddNoise.initialise()]);
147+
await Promise.all([this.audioHandler.initialise(), this.cpu.initialise()]);
142148
this.ready = true;
143149
}
144150

@@ -157,11 +163,13 @@ export class Emulator {
157163

158164
start() {
159165
if (this.running) return;
166+
this.audioHandler.unmute();
160167
this.running = true;
161168
requestAnimationFrame(this.onAnimFrame);
162169
}
163170

164171
pause() {
172+
this.audioHandler.mute();
165173
this.running = false;
166174
}
167175

@@ -293,6 +301,7 @@ export class Emulator {
293301

294302
keyDown(event) {
295303
if (!this.running) return;
304+
this.audioHandler.tryResume();
296305

297306
const code = this.keyCode(event);
298307
const processor = this.cpu;
@@ -317,6 +326,7 @@ export class Emulator {
317326
}
318327

319328
mouseMove(event) {
329+
this.audioHandler.tryResume();
320330
this.showCoords = true;
321331
const processor = this.cpu;
322332
const screen = this.root.find(".screen");

src/root.html

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
</div>
77

88
<div>
9+
<div id="audio-warning" class="alert alert-warning initially-hidden">
10+
Your browser has suspended audio -- mouse click or key press for sound.
11+
</div>
912
</div>
1013
<div class="toolbar" id="emu_toolbar">
1114
<button data-action="run" title="Run the program (ctrl-enter)"><i class="fa-solid fa-play" style="pointer-events: none;"></i></button>

0 commit comments

Comments
 (0)