-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
232 lines (212 loc) Β· 6.96 KB
/
index.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebAudio Dattorro</title>
<style type="text/css">
* { font-family: sans-serif; }
label, input+span { font-family: monospace; line-height: 2.2ex;}
input { height: 2.2ex; width: 50%;}
pre { font-family: monospace; font-size: 120%; background: black; color: white; padding: 15px 15px;
word-break: break-all;
white-space: pre-wrap;
}
body {
margin: 20px auto;
max-width: 880px;
padding: 5px;
}
div>label {
width: 34%;
display: inline-block;
}
#controls>div {
display: flex;
align-items:center;
}
#clips { display: inline-block; }
</style>
</head>
<body>
<div id="clips"></div>
<button id="mic">Toggle Mic</button>
<br><br>
<div id="controls">
<div>
<label>PreDelay _____(π» 0 β¬
β‘ srπΊ): </label>
<input type="range" id="pd" name="preDelay" max="47999" step="1">
<span></span>
</div>
<div>
<label>PreLPF _______(π» 0 β¬
β‘ 1 πΊ): </label>
<input type="range" id="bw" name="bandwidth" max="1" step="0.000001">
<span></span>
</div>
<div>
<label>PreDiffuse1 __(π 0 β¬
πβ‘ 1 π): </label>
<input type="range" id="fi" name="inputDiffusion1" max="1" step="0.000001">
<span></span>
</div>
<div>
<label>PreDiffuse2 __(π 0 β¬
πβ‘ 1 π): </label>
<input type="range" id="si" name="inputDiffusion2" max="1" step="0.000001">
<span></span>
</div>
<div>
<label>DecayRate ____(π 0 β¬
β‘ 1 π¨): </label>
<input type="range" id="dc" name="decay" min="0" max="1" step="0.000001">
<span></span>
</div>
<div>
<label>DecayDiffuse _(π 0 β¬
πβ‘ 1 π): </label>
<input type="range" id="ft" name="decayDiffusion1" max="0.999999" step="0.000001">
<span></span>
</div>
<div>
<label>DecayDiffuse2_(π 0 β¬
πβ‘ 1 π): </label>
<input type="range" id="st" name="decayDiffusion2" max="0.999999" step="0.000001">
<span></span>
</div>
<div>
<label>Damping ______(π» 0 β¬
β‘ 1 π): </label>
<input type="range" id="dp" name="damping" max="1" step="0.000001">
<span></span>
</div>
<div>
<label>ExcursionRate (π€ 0 β¬
β‘ 32π): </label>
<input type="range" id="ex" name="excursionRate" max="2" step="0.01">
<span></span>
</div>
<div>
<label>ExcursionDepth(π€ 0 β¬
β‘ 32π): </label>
<input type="range" id="ed" name="excursionDepth" max="2" step="0.01">
<span></span>
</div>
<div>
<label>Dry __________(π» 0 β¬
β‘ 1 πΊ): </label>
<input type="range" id="dr" name="dry" max="1" step="0.000001">
<span></span>
</div>
<div>
<label>Wet __________(π» 0 β¬
β‘ 1 πΊ): </label>
<input type="range" id="we" name="wet" max="1" step="0.000001" >
<span></span>
</div>
<br>
<div>
<label>π· Presets</label>
<button id="smol">roomy owo</button>
<button id="bige">churchy uwu</button>
<button id="frez">freezy ewe</button>
<button id="ether">ethery @w@</button>
</div>
</div>
<div>
<h2>
Dattorro's Reverb π£ // [<a href="https://github.com/khoin/DattorroReverbNode">git repo</a>]
</h2>
<h4>
a faithful implementation entirely in Javascript in AudioWorklet. flexible — freezable — fast — free!
</h4>
<p>
πͺ flexible (compared to ConvolverNode) <br>
π¨ freezable (just set decayRate to 1!) <br>
π
fast? maybe... (0.5ms on 10ms budget, my <a href="https://share.firefox.dev/3eS7XBP">set up</a>) (let me know if you do profile it!)<br>
π free! (public domain)
</p>
<h3>π¨ usage</h3>
<pre>
aC.addModule('dattorroReverb.js').then(() => {
let reverb = new AudioWorkletNode(aC, 'DattorroReverb', { outputChannelCount: [2] });
fromNode.connect(reverb);
reverb.connect(toNode);
});
</pre>
<div style="width: 33%; float:left; ">
<h3>π reference</h3>
<p>
Jon Dattorro's paper [<a href="https://ccrma.stanford.edu/~dattorro/EffectDesignPart1.pdf">pdf linky</a>]
</p>
<h3>β license & πΎ source</h3>
<p> public domain + no-liability </p>
</div>
<div style="width: 66%; float: left; padding: 0 1%; box-sizing: border-box;">
<h3>πΌ music</h3>
<p>clips are from Placeboing on Freesound under CC 0 and Kikuo's Mikukikuo5 under CC BY-NC-SA.</p>
<ul>
<li>Placeboing [<a href="https://freesound.org/people/placeboing/sounds/338387/">Freesound</a>]</li>
<li>MAWARU [<a href="https://kikuo.bandcamp.com/track/mawaru">Bandcamp</a>]</li>
<li>Sea is [<a href="https://kikuo.bandcamp.com/track/sea-is">Bandcamp</a>]</li>
</ul>
</div>
</div>
</body>
<script type="module">
const aC = new AudioContext();
const presets = [
[ 1525 , 0.5683, 0.4666, 0.5853, 0.3226, 0.6954, 0.6022, 0.6446, 0 , 0 , 0.2921, 0.4361 ],
[ 0 , 0.928 , 0.7331, 0.4534, 0.8271, 0.7839, 0.1992, 0.5975, 0 , 0 , 0.0042, 0.9000 ],
[ 0 , 0.999 , 0.75 , 0.625 , 1 , 0.5 , 0.711 , 0.005 , 0.3, 1.4 , 0.915 , 0.194 ],
[ 0 , 0.999 , 0.23 , 0.667 , 0.86 , 0.7 , 0.5 , 0.3 , 0.7, 1.2 , 0.53 , 0.30 ]
];
let audios = ['placeboing', 'kikuo', 'kikuo2', 'sine'].map(a => new Audio(`./resources/${a}.wav`));
let micState = false;
Promise.all([
aC.audioWorklet.addModule('dattorroReverb.js')
]).then(_ => {
let esrc = audios.map(a => aC.createMediaElementSource(a));
let m = undefined;
let mg = aC.createGain();
let mx = aC.createGain();
let reverb = new AudioWorkletNode(aC, 'DattorroReverb', { outputChannelCount: [2] });
esrc.forEach(src => src.connect(mx));
mg.connect(reverb);
mx.connect(reverb);
reverb.connect(aC.destination);
audios.forEach((aud, i) => {
let btn = document.createElement("button");
btn.innerText = `Play ${aud.src.split("/").pop()}`;
btn.onclick = _ => aC.resume() & audios[i].play();
clips.appendChild(btn);
})
mic.onclick = _ => {
if (micState) {
mg.gain.linearRampToValueAtTime(0, aC.currentTime + 0.1);
mic.style.background = '';
micState = false;
} else {
if(m == undefined)
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
m = aC.createMediaStreamSource(stream);
m.connect(mg);
}).catch(() => {
mic.style.background = '';
alert("Failed getting microphone.");
micState = false;
});
mg.gain.linearRampToValueAtTime(1, aC.currentTime + 0.1);
mic.style.background = 'darksalmon';
micState = true;
}
}
const pull = _ =>
[...document.querySelectorAll("input")]
.forEach(r => (r.value = reverb.parameters.get(r.name).value) & (r.nextElementSibling.innerText = r.value));
const push = _ =>
[...document.querySelectorAll("input")]
.forEach(r => reverb.parameters.get(r.name).linearRampToValueAtTime(r.value, aC.currentTime+0.190));
[...document.querySelectorAll("input")]
.forEach(r => r.onmousemove = e => push() & (r.nextElementSibling.innerText = r.value));
[smol, bige, frez, ether]
.forEach((b, i) =>
b.onclick = e => {
[pd, bw, fi, si, dc, ft, st, dp, ex, ed, dr, we].forEach((p, j) => p.value = presets[i][j]);
push();
setTimeout(pull, 200);
});
pull();
}, e => {
console.error(e);
});
</script>
</html>