-
Notifications
You must be signed in to change notification settings - Fork 14
/
sine_worklet.htm
57 lines (43 loc) · 1.4 KB
/
sine_worklet.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!doctype 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>