Skip to content

Repository files navigation

Sonis

A TypeScript audio computation graph compiler with a shared offline and AudioWorklet interpreter.

bun install
bun run build
bun run test
import { audio, mul, sin, phasor, OfflineRenderer, writeWav } from '@sonis/core'
import { writeFileSync } from 'node:fs'

const graph = audio((c) => {
  const freq = c.param('freq', 440)
  const gain = c.param('gain', 0.2)
  return mul(sin(mul(phasor(freq, { key: 'osc' }), Math.PI * 2)), gain)
})

const renderer = new OfflineRenderer({ sampleRate: 48000 })
const buf = renderer.renderSync(graph, { duration: 1 })
writeFileSync('sine.wav', writeWav(buf))

In a browser, initialize a renderer, then connect from a user gesture:

import { RealtimeRenderer } from '@sonis/core'

const rt = new RealtimeRenderer()
await rt.setGraph(graph)
playButton.onclick = () => rt.connect()
rt.setParam('freq', 523.25, { rampSec: 0.02 })
// await rt.setGraph(nextGraph) // reuse oscillator keys to preserve phase
// await rt.dispose()

Serve the built renderer-web/dist/worklet.js as a browser asset. Pass its URL as workletUrl if your bundler does not preserve module-relative assets. Graph and AudioContext sample rates must match. Audio output is mono.

See implementation decisions for automation, state migration, numerical conventions, and verification limits.

Run bun run dev and open the Vite URL for the playground. Listening room plays an original four-bar trap loop with modeled percussion, plucked strings, and 808 bass. Use S to solo, M to mute, and export eight bars of the mix or an isolated voice. Engine tests contains the sine, filtered-noise, and feedback checks. The instrument models are a starting point for listening and refinement; their realism has not been validated.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages