diff --git a/example/demo.ts b/example/demo.ts index 97441e0..29e79b1 100644 --- a/example/demo.ts +++ b/example/demo.ts @@ -7,33 +7,33 @@ const canvas = document.getElementById('fb'); const audioContext = new AudioContext(); // add initial devices like /dev/null, etc -await configure({ addDevices: true }); +configure({ addDevices: true }).then(() => { + // mount framebuffer & dsp + fs.mounts.get('/dev').createDevice('/fb0', framebuffer({ canvas })); + fs.mounts.get('/dev').createDevice('/dsp', dsp({ audioContext })); -// mount framebuffer & dsp -fs.mounts.get('/dev').createDevice('/fb0', framebuffer({ canvas })); -fs.mounts.get('/dev').createDevice('/dsp', dsp({ audioContext })); - -// example: write static to framebuffer -const screen = new Uint8Array(canvas.width * canvas.height * 4); -function makestaticFb() { - for (let i = 0; i < screen.byteLength; i += 4) { - screen[i] = Math.random() * 255; - screen[i + 1] = Math.random() * 255; - screen[i + 2] = Math.random() * 255; - screen[i + 3] = 255; + // example: write static to framebuffer + const screen = new Uint8Array(canvas.width * canvas.height * 4); + function makestaticFb() { + for (let i = 0; i < screen.byteLength; i += 4) { + screen[i] = Math.random() * 255; + screen[i + 1] = Math.random() * 255; + screen[i + 2] = Math.random() * 255; + screen[i + 3] = 255; + } + fs.promises.writeFile('/dev/fb0', screen); + requestAnimationFrame(makestaticFb); } - fs.promises.writeFile('/dev/fb0', screen); - requestAnimationFrame(makestaticFb); -} -makestaticFb(); + makestaticFb(); -// example: write static to audio -const audioBuffer = new ArrayBuffer(audioContext.sampleRate * 4) -const audioBytes = new Uint8Array(audioBuffer) -const audioFloats = new Float32Array(audioBuffer) -setInterval(() => { - for (let i in audioFloats){ - audioFloats[i] = Math.random() * 2 - 1 - } - fs.promises.writeFile('/dev/dsp', audioBytes) -}, 1000) \ No newline at end of file + // example: write static to audio + const audioBuffer = new ArrayBuffer(audioContext.sampleRate * 4) + const audioBytes = new Uint8Array(audioBuffer) + const audioFloats = new Float32Array(audioBuffer) + setInterval(() => { + for (let i in audioFloats){ + audioFloats[i] = Math.random() * 2 - 1 + } + fs.promises.writeFile('/dev/dsp', audioBytes) + }, 1000) +}) diff --git a/package.json b/package.json index d3a09cb..0a3392d 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "format:check": "prettier --check .", "lint": "eslint src", "build": "tsc -p tsconfig.json", - "build:docs": "vite build site", + "build:docs": "vite build", "test": "tsx --test --experimental-test-coverage", "prepublishOnly": "npm run build", "start": "vite", diff --git a/src/dsp.ts b/src/dsp.ts index dfc9e9d..c8ac171 100644 --- a/src/dsp.ts +++ b/src/dsp.ts @@ -1,3 +1,7 @@ +interface DspOptions { + audioContext?: AudioContext +} + // I inline worker, so no seperate file is needed. const workletUrl = URL.createObjectURL(new Blob([` @@ -34,7 +38,7 @@ registerProcessor('zenfs-dsp', ZenFSDsp) `], { type: 'application/javascript' })) -export const dsp = (options:any = {}) => { +export const dsp = (options:DspOptions = {}) => { const audioCtx = options.audioContext || new AudioContext() const audioBuffer = new ArrayBuffer(audioCtx.sampleRate * 4) diff --git a/src/framebuffer.ts b/src/framebuffer.ts index d5b8309..87112ec 100644 --- a/src/framebuffer.ts +++ b/src/framebuffer.ts @@ -1,4 +1,8 @@ -export function framebuffer(options:any = {}) { +interface FramebufferOptions { + canvas?: HTMLCanvasElement +} + +export function framebuffer(options:FramebufferOptions = {}) { if (!options.canvas) { options.canvas = document.createElement('canvas') document.body.appendChild(options.canvas) diff --git a/src/input.ts b/src/input.ts index 78227c8..137855b 100644 --- a/src/input.ts +++ b/src/input.ts @@ -1 +1,5 @@ -export const input = (options:any = {}) => {}; +interface InputOptions { + canvas?: HTMLElement +} + +export function input(options:InputOptions = {}){}; diff --git a/tsconfig.json b/tsconfig.json index 9f1a5a1..a741baf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "lib": ["ESNext", "ESNext.Disposable", "dom"], "moduleResolution": "NodeNext", "declaration": true, - "strict": true, + "strict": false, "allowImportingTsExtensions": true, "noEmit": true }, diff --git a/vite.config.js b/vite.config.js index 16db22e..d0c1152 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,7 +4,8 @@ export default defineConfig({ // base: '.', root: './example', build: { - outDir: '../docs' + outDir: '../docs', + emptyOutDir: true }, resolve: { alias: {