Helps create baudio style musics
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
LICENSE
index.js
index.mjs
package.json
readme.md
test.js

readme.md

Ultra thin baudio style wrapper around ScriptProcessorNode

Setup

# Fetch latest from github
npm i thewhodidthis/sound

Usage

import createSignal from '@thewhodidthis/sound'

const audio = new AudioContext()
const fader = audio.createGain()

const sound = createSignal(t => Math.sin(t * Math.PI * 880))

fader.gain.value = 0

sound.connect(fader)
fader.connect(audio.destination)

let isBusy = false

document.addEventListener('click', () => {
    const time = audio.currentTime

    if (isBusy) {
        fader.gain.setTargetAtTime(0, time, 0.25)
    } else {
        fader.gain.setTargetAtTime(1, time, 1)
    }

    isBusy = !isBusy
}, false)