From ce31f2d061ce30e5936c3d95b34d29e2c50dd0b5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 23 Jan 2025 08:34:42 +1300 Subject: [PATCH 1/8] 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 --- src/emulator.js | 24 +++++++++++++++++------- src/root.html | 3 +++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/emulator.js b/src/emulator.js index 6c9b281..c236924 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -1,10 +1,10 @@ +import $ from "jquery"; import _ from "underscore"; import {Cpu6502} from "jsbeeb/6502"; import * as canvasLib from "jsbeeb/canvas"; import {Video} from "jsbeeb/video"; import {Debugger} from "jsbeeb/web/debug"; -import {FakeSoundChip} from "jsbeeb/soundchip"; -import {FakeDdNoise} from "jsbeeb/ddnoise"; +import {AudioHandler} from "jsbeeb/web/audio-handler"; import * as models from "jsbeeb/models"; import {Cmos} from "jsbeeb/cmos"; import * as utils from "jsbeeb/utils"; @@ -98,8 +98,14 @@ export class Emulator { this.video = new Video(Model.isMaster, this.canvas.fb32, _.bind(this.paint, this)); - this.soundChip = new FakeSoundChip(); - this.ddNoise = new FakeDdNoise(); + const audioFilterFreq = 7000; + const audioFilterQ = 5; + const noSeek = false; + this.audioHandler = new AudioHandler($("#audio-warning"), audioFilterFreq, audioFilterQ, noSeek); + // Firefox will report that audio is suspended even when it will + // start playing without user interaction, so we need to delay a + // little to get a reliable indication. + window.setTimeout(() => this.audioHandler.checkStatus(), 1000); this.dbgr = new Debugger(this.video); const cmos = new Cmos({ @@ -120,8 +126,8 @@ export class Emulator { Model, this.dbgr, this.video, - this.soundChip, - this.ddNoise, + this.audioHandler.soundChip, + this.audioHandler.ddNoise, cmos, config, ); @@ -140,7 +146,7 @@ export class Emulator { } async initialise() { - await Promise.all([this.cpu.initialise(), this.ddNoise.initialise()]); + await Promise.all([this.audioHandler.initialise(), this.cpu.initialise()]); this.ready = true; } @@ -163,11 +169,13 @@ export class Emulator { start() { if (this.running) return; + this.audioHandler.unmute(); this.running = true; requestAnimationFrame(this.onAnimFrame); } pause() { + this.audioHandler.mute(); this.running = false; } @@ -299,6 +307,7 @@ export class Emulator { keyDown(event) { if (!this.running) return; + this.audioHandler.tryResume(); const code = this.keyCode(event); const processor = this.cpu; @@ -323,6 +332,7 @@ export class Emulator { } mouseMove(event) { + this.audioHandler.tryResume(); this.showCoords = true; const processor = this.cpu; const screen = this.root.find(".screen"); diff --git a/src/root.html b/src/root.html index 68fb768..c3c3e0b 100644 --- a/src/root.html +++ b/src/root.html @@ -6,6 +6,9 @@
+
+ Your browser has suspended audio -- mouse click or key press for sound. +
From 788100c3cc52fd6dc3419f39c2074a05081e8c50 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Mon, 21 Apr 2025 18:16:49 -0500 Subject: [PATCH 2/8] WIP --- package-lock.json | 6 +++--- package.json | 2 +- src/emulator.js | 1 + src/owlet-editor.less | 7 +++++++ src/root.html | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4f50c82..c5e065a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "base2048": "^2.0.2", "jquery": "^3.7.1", - "jsbeeb": "github:mattgodbolt/jsbeeb#275b99ddeaf096d2497f606a4ad0ce74991306e1", + "jsbeeb": "github:mattgodbolt/jsbeeb#77be55899c28223d964493c9ad8b60b1ffd37185", "monaco-editor": "^0.52.2", "promise": "^8.3.0", "resize-observer-polyfill": "^1.5.1", @@ -4026,8 +4026,8 @@ }, "node_modules/jsbeeb": { "version": "0.0.7", - "resolved": "git+ssh://git@github.com/mattgodbolt/jsbeeb.git#275b99ddeaf096d2497f606a4ad0ce74991306e1", - "integrity": "sha512-/uuR1mSdeH0FssBKNMHUdh3shd5YjKRuBsc0xzZzSopzIpUJwEwgRJAk1yTTbZOwz7/w7sL2+3Amx+3Otzf68g==", + "resolved": "git+ssh://git@github.com/mattgodbolt/jsbeeb.git#77be55899c28223d964493c9ad8b60b1ffd37185", + "integrity": "sha512-Y+KatevAkLPehlcHdZVUQ3gxhuVM4gzQ8akGAfOcCR8zon4BPjnaqI7bsOCKBH6XXr2TksW7njWq+nc22M1Zuw==", "license": "GPL-3.0-or-later", "dependencies": { "@popperjs/core": "^2.11.8", diff --git a/package.json b/package.json index 5e508f0..a69c30c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "dependencies": { "base2048": "^2.0.2", "jquery": "^3.7.1", - "jsbeeb": "github:mattgodbolt/jsbeeb#275b99ddeaf096d2497f606a4ad0ce74991306e1", + "jsbeeb": "github:mattgodbolt/jsbeeb#77be55899c28223d964493c9ad8b60b1ffd37185", "monaco-editor": "^0.52.2", "promise": "^8.3.0", "resize-observer-polyfill": "^1.5.1", diff --git a/src/emulator.js b/src/emulator.js index 1553b2e..78bc830 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -103,6 +103,7 @@ export class Emulator { const noSeek = false; this.audioHandler = new AudioHandler( $("#audio-warning"), + $("#audio-stats")[0], audioFilterFreq, audioFilterQ, noSeek, diff --git a/src/owlet-editor.less b/src/owlet-editor.less index 17f808f..5c3c084 100644 --- a/src/owlet-editor.less +++ b/src/owlet-editor.less @@ -134,6 +134,13 @@ canvas.screen { border: none; } +#audio-stats { + bottom: 0; + right: 0; + position: fixed; + display: none; +} + #about { padding: 32px; display: none; diff --git a/src/root.html b/src/root.html index d21f8be..a0fff22 100644 --- a/src/root.html +++ b/src/root.html @@ -57,6 +57,7 @@

+