Skip to content

Commit

Permalink
subverting pedantic tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed Nov 6, 2024
1 parent ea541c4 commit 66b394b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 33 deletions.
54 changes: 27 additions & 27 deletions example/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// 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)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/dsp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
interface DspOptions {
audioContext?: AudioContext
}

// I inline worker, so no seperate file is needed.
const workletUrl = URL.createObjectURL(new Blob([`
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion src/framebuffer.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/input.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const input = (options:any = {}) => {};
interface InputOptions {
canvas?: HTMLElement
}

export function input(options:InputOptions = {}){};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lib": ["ESNext", "ESNext.Disposable", "dom"],
"moduleResolution": "NodeNext",
"declaration": true,
"strict": true,
"strict": false,
"allowImportingTsExtensions": true,
"noEmit": true
},
Expand Down
3 changes: 2 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export default defineConfig({
// base: '.',
root: './example',
build: {
outDir: '../docs'
outDir: '../docs',
emptyOutDir: true
},
resolve: {
alias: {
Expand Down

0 comments on commit 66b394b

Please sign in to comment.