genish.js
Version:
58 lines (43 loc) • 1.44 kB
HTML
<html lang=en>
<head>
<meta charset='utf-8'>
<script src='../dist/gen.lib.js'></script>
</head>
<body>
<p style="width:25em;" >
<span style="font-weight:bold">Click/touch in the page to begin</span>.
This example shows how you can use the "input" ugen to plug regular Web Audio API
nodes into a AudioWorklet node created by genish.js.
If you open your developer's console, you should see the generated callback function.
</p>
</body>
<script>
const click = function() {
const ctx = utilities.ctx
// create a WAAPI oscillator
const sine = ctx.createOscillator()
sine.frequency.value = 2
// use this gain to scale the output of our oscillator
const gain = ctx.createGain()
gain.gain.value = 40
sine.connect( gain )
utilities.playWorklet(
cycle( add( 220, input('freqMod', 0, 0 ) ) ),
'test', // this name isn't really important
true // print generated code to developers console
).then( node => {
gain.connect( node )
sine.start()
console.log( 'playing...' )
})
window.removeEventListener( 'click', click )
}
window.onload = ()=> {
window.addEventListener( 'click', click )
genish.export( window )
// audio context will be stored in utilities.ctx
utilities.createContext()
}
</script>
</html>