From ef44717bb44d16ffb1c1bc6983cf10468fb3d0be Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Wed, 3 Apr 2024 11:01:08 +0100 Subject: [PATCH] Fix PR feedback - Fix missing typescript types - Use Safari 13 compatible OfflineAudioContext constructor - this may prove pointless due to lack of < 44100 sample rate support, but is an easier starting point to try things out. --- package-lock.json | 7 +++++++ package.json | 1 + src/board/audio/index.ts | 10 +++++----- src/board/wasm.ts | 7 ++----- src/jshal.d.ts | 9 ++------- src/simulator.ts | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4c8469a1..8fab2c2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "license": "MIT", "devDependencies": { + "@types/emscripten": "^1.39.10", "esbuild": "^0.14.49", "prettier": "2.6.0", "vitest": "^0.22.1" @@ -29,6 +30,12 @@ "@types/chai": "*" } }, + "node_modules/@types/emscripten": { + "version": "1.39.10", + "resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-1.39.10.tgz", + "integrity": "sha512-TB/6hBkYQJxsZHSqyeuO1Jt0AB/bW6G7rHt9g7lML7SOF6lbgcHvw/Lr+69iqN0qxgXLhWKScAon73JNnptuDw==", + "dev": true + }, "node_modules/@types/node": { "version": "18.7.14", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.14.tgz", diff --git a/package.json b/package.json index f16851ec..5856f89c 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "homepage": "https://github.com/microbit-foundation/micropython-microbit-v2-simulator#readme", "devDependencies": { + "@types/emscripten": "^1.39.10", "esbuild": "^0.14.49", "prettier": "2.6.0", "vitest": "^0.22.1" diff --git a/src/board/audio/index.ts b/src/board/audio/index.ts index 5278eab9..9c069671 100644 --- a/src/board/audio/index.ts +++ b/src/board/audio/index.ts @@ -201,11 +201,11 @@ export class BoardAudio { const recorder = this.context!.createScriptProcessor(2048, 1, 1); recorder.onaudioprocess = (e) => { const offlineContext = new (window.OfflineAudioContext || - window.webkitOfflineAudioContext)({ - sampleRate, - length: sampleRate * (e.inputBuffer.length / e.inputBuffer.sampleRate), - numberOfChannels: 1, - }); + window.webkitOfflineAudioContext)( + 1, + sampleRate * (e.inputBuffer.length / e.inputBuffer.sampleRate), + sampleRate + ); const source = offlineContext.createBufferSource(); source.buffer = e.inputBuffer; source.connect(offlineContext.destination); diff --git a/src/board/wasm.ts b/src/board/wasm.ts index 3b7f6a95..77eddec4 100644 --- a/src/board/wasm.ts +++ b/src/board/wasm.ts @@ -2,7 +2,7 @@ import { Board } from "."; import * as conversions from "./conversions"; import { FileSystem } from "./fs"; -export interface EmscriptenModule { +export interface SimulatorEmscriptenModule extends EmscriptenModule { cwrap: any; ExitStatus: Error; @@ -15,9 +15,6 @@ export interface EmscriptenModule { _microbit_hal_level_detector_callback(level: number): void; _microbit_radio_rx_buffer(): number; - HEAPU8: Uint8Array; - HEAPU32: Uint32Array; - // Added by us at module creation time for jshal to access. board: Board; fs: FileSystem; @@ -27,7 +24,7 @@ export interface EmscriptenModule { export class ModuleWrapper { private main: () => Promise; - constructor(private module: EmscriptenModule) { + constructor(private module: SimulatorEmscriptenModule) { const main = module.cwrap("mp_js_main", "null", ["number"], { async: true, }); diff --git a/src/jshal.d.ts b/src/jshal.d.ts index fe9ae15c..451b9c25 100644 --- a/src/jshal.d.ts +++ b/src/jshal.d.ts @@ -1,15 +1,10 @@ -import { EmscriptenModule } from "./board/wasm"; +import { SimulatorEmscriptenModule } from "./board/wasm"; global { // In reality this is a local variable as jshal.js is splatted into the generated code. - declare const Module: EmscriptenModule; + declare const Module: SimulatorEmscriptenModule; declare const LibraryManager: { library: any; }; - - // Just what we need. There are lots more Emscripten helpers available. - declare function UTF8ToString(ptr: number, len?: number); - declare function stringToUTF8(s: string, buf: number, len: number); - declare function lengthBytesUTF8(s: string); declare function mergeInto(library: any, functions: Record); } diff --git a/src/simulator.ts b/src/simulator.ts index c45f60e3..01097cc2 100644 --- a/src/simulator.ts +++ b/src/simulator.ts @@ -1,6 +1,6 @@ import * as conversions from "./board/conversions"; import { FileSystem } from "./board/fs"; -import { EmscriptenModule } from "./board/wasm"; +import { SimulatorEmscriptenModule } from "./board/wasm"; import { Board, createBoard, @@ -11,7 +11,7 @@ import { declare global { interface Window { // Provided by firmware.js - createModule: (args: object) => Promise; + createModule: (args: object) => Promise; } }