title
A prototype
((·))
let ctx window.addEventListener("mousedown", checkAudioCtx); window.addEventListener("keydown", checkAudioCtx); function checkAudioCtx(){ if(ctx == undefined || ctx.state == "closed" || ctx.state == "suspended"){ ctx = new(window.AudioContext || window.webkitAudioContext)(); console.log("context created"); } } function noiseOscillator(ctx, note, dur, res, noise, flat, dist){ // thx adl! let pattern = []; let i = 0; while (i < ctx.sampleRate/note) { let rdm_val = Math.random() - Math.random(); let val = (Math.sin(2*Math.PI*note * (i/ctx.sampleRate)) + rdm_val * noise) * dist; val = Math.floor(val * res)/res; for (var r = 0; r < flat; r++) { pattern.push(val > 1 ? 1 : val < -1 ? -1 : val); i++; } } const buffer = ctx.createBuffer(1, ctx.sampleRate*dur, ctx.sampleRate) for (let ch=0; ch
pattern.length-1 ? s - Math.floor(s/pattern.length) * pattern.length : s ]; } } return new AudioBufferSourceNode(ctx, {buffer:buffer}) }
snap
save
new
fork
download
html
css
js
output
gallery
config
➚ link to output
➚ snap player
font size
live reload
snap mode
layout
⤷ switch
★ info and code