Skip to content

Commit

Permalink
Fix PR feedback
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
microbit-matt-hillsdon committed Apr 3, 2024
1 parent 4f1baa3 commit ef44717
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/board/audio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions src/board/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -27,7 +24,7 @@ export interface EmscriptenModule {
export class ModuleWrapper {
private main: () => Promise<void>;

constructor(private module: EmscriptenModule) {
constructor(private module: SimulatorEmscriptenModule) {
const main = module.cwrap("mp_js_main", "null", ["number"], {
async: true,
});
Expand Down
9 changes: 2 additions & 7 deletions src/jshal.d.ts
Original file line number Diff line number Diff line change
@@ -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<string, function>);
}
4 changes: 2 additions & 2 deletions src/simulator.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,7 +11,7 @@ import {
declare global {
interface Window {
// Provided by firmware.js
createModule: (args: object) => Promise<EmscriptenModule>;
createModule: (args: object) => Promise<SimulatorEmscriptenModule>;
}
}

Expand Down

0 comments on commit ef44717

Please sign in to comment.