-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
751 lines (726 loc) · 25.6 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
<!doctype html>
<html lang="en" class="h-100" data-bs-theme="auto">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="color-scheme" content="light dark" />
<meta name="description" content="Reverb effect written in JavaScript." />
<meta name="author" content="Masashi Yoshikawa" />
<!-- ogp -->
<meta property="og:title" content="JavaScript Reverb Effect Test" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://logue.github.io/Reverb.js/" />
<meta
property="og:image"
content="https://repository-images.githubusercontent.com/194181712/20bdd780-9995-11e9-8811-42e3b44d1cec"
/>
<meta property="og:site_name" content="Logue's Lab" />
<meta
property="og:description"
content="Reverb effect written in JavaScript."
/>
<meta property="fb:app_id" content="129144050466298" />
<meta
property="article:publisher"
content="https://www.facebook.com/logue256"
/>
<meta name="twitter:card" content="Summary" />
<meta name="twitter:site" content="@logue256" />
<meta name="twitter:title" content="JavaScript Reverb Effect Test" />
<meta name="twitter:url" content="https://logue.dev/Reverb.js/" />
<meta
name="twitter:description"
content="Reverb effect written in JavaScript."
/>
<meta
name="twitter:image"
content="https://repository-images.githubusercontent.com/194181712/20bdd780-9995-11e9-8811-42e3b44d1cec"
/>
<title>Reverb.js Demo</title>
<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-2Y2FW3QEG4"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-2Y2FW3QEG4');
</script>
<!-- Bootstrap core CSS -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"
integrity="sha256-9kPW/n5nn53j4WMRYAxe9c1rCY96Oogo/MKSVdKzPmI="
crossorigin="anonymous"
/>
</head>
<body class="d-flex flex-column h-100">
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<div class="container-fluid d-flex justify-content-between">
<a class="navbar-brand" href="#">Reverb.js</a>
<button
aria-controls="navbarCollapse"
aria-expanded="false"
aria-label="Toggle navigation"
class="navbar-toggler"
data-bs-target="#navbarCollapse"
data-bs-toggle="collapse"
type="button"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse flex-grow-0" id="navbarCollapse">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="./">Demo</a>
</li>
<li class="nav-item">
<a
aria-current="page"
class="nav-link"
href="./localaudio.html"
>
LocalAudio Demo
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/logue/Reverb.js">
<em class="bi bi-github"></em>
</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a
aria-expanded="false"
class="nav-link dropdown-toggle"
data-bs-toggle="dropdown"
href="#"
id="navbarDarkDropdownMenuLink"
role="button"
>
See Also
</a>
<ul
class="dropdown-menu dropdown-menu-end"
aria-labelledby="navbarDarkDropdownMenuLink"
>
<li>
<a
class="dropdown-item"
href="https://github.com/logue/smfplayer.js/"
>
smfplayer.js
</a>
</li>
<li>
<a
class="dropdown-item"
href="https://github.com/logue/sf2synth.js/"
>
sf2synth.js
</a>
</li>
<li>
<a
class="dropdown-item"
href="https://github.com/logue/Reverb.js/"
>
Reverb.js
</a>
</li>
<li>
<a
class="dropdown-item"
href="https://github.com/logue/MabiMmlEmu/"
>
MabiMmlEmu
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!-- Begin page content -->
<main role="main" class="flex-shrink-0 my-3">
<div class="container-fluid bg-body-tertiary p-5 mb-3">
<h1 class="display-5 fw-bold">Reverb.js Demo</h1>
<p class="fs-4">Refer to the console log for the values.</p>
<button id="play" type="button" class="btn btn-primary btn-lg" disabled>
<em class="bi bi-play"></em>
Play
</button>
</div>
<div class="container">
<div class="row">
<div class="col">
<h2>Reverb Control</h2>
<p>
Changing these values will regenerate the impulse response each
time, but due to its nature, it will take some time to see the
effect. It may be helpful to maximize the value of Wet.
</p>
<div class="form-check form-switch">
<input id="reverb" type="checkbox" class="form-check-input" />
<label class="form-check-label" for="reverb">Reverb</label>
</div>
<div class="form-check form-switch">
<input type="checkbox" class="form-check-input" id="reverse" />
<label class="form-check-label" for="reverse">
Reverse Inpulse Response
</label>
</div>
</div>
<div class="col">
<div class="overflow-auto">
<canvas id="graph" width="512" height="256"></canvas>
</div>
<p class="text-right">
The sound uses the drum part of
<a
href="https://soundcloud.com/logue256/autumn-wind"
rel="noopener"
target="_blank"
>
<em class="bi bi-soundwave"></em>
Autmun Wind
</a>
.
</p>
</div>
</div>
<section class="mb-3">
<h3>Impulse response generation algorithm settings</h3>
<p>
<a
href="https://github.com/thi-ng/umbrella/tree/develop/packages/colored-noise"
target="_blank"
rel="noopener"
>
@thi.ng/colored-noise
<em class="bi bi-box-arrow-up-right"></em>
</a>
is used for random noise generation process used for impulse
response generation. These settings are the parameters of the noise
generation process.
</p>
<fieldset>
<legend>Noise algorithm</legend>
<div class="row align-items-center">
<div class="col-auto">
<div class="form-check">
<input
class="form-check-input"
type="radio"
name="noise"
id="blue"
value="blue"
/>
<label class="form-check-label" for="blue">
<em
class="bi bi-square-fill"
style="color: var(--bs-blue)"
></em>
Blue Noise
</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input
class="form-check-input"
type="radio"
name="noise"
id="green"
value="green"
/>
<label class="form-check-label" for="green">
<em
class="bi bi-square-fill"
style="color: var(--bs-green)"
></em>
Green Noise
</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input
class="form-check-input"
type="radio"
name="noise"
id="pink"
value="pink"
/>
<label class="form-check-label" for="pink">
<em
class="bi bi-square-fill"
style="color: var(--bs-pink)"
></em>
Pink Noise
</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input
class="form-check-input"
type="radio"
name="noise"
id="red"
value="red"
/>
<label class="form-check-label" for="red">
<em
class="bi bi-square-fill"
style="color: var(--bs-red)"
></em>
Red (Brown) Noise
</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input
class="form-check-input"
type="radio"
name="noise"
id="violet"
value="violet"
/>
<label class="form-check-label" for="violet">
<em
class="bi bi-square-fill"
style="color: var(--bs-purple)"
></em>
Violet Noise
</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input
class="form-check-input"
type="radio"
name="noise"
id="white"
value="white"
checked
/>
<label class="form-check-label" for="white">
<em class="bi bi-square"></em>
White Noise
</label>
</div>
</div>
</div>
<p class="small">
<a
href="https://en.wikipedia.org/wiki/Colors_of_noise"
rel="noopener"
target="_blank"
>
What is colord noise?
<em class="bi bi-box-arrow-up-right"></em>
</a>
</p>
</fieldset>
<div class="row">
<div class="col-md">
<label for="peaks" class="form-label">Random noise peaks</label>
<input
type="number"
class="form-control"
id="peaks"
value="2"
step="1"
min="0"
max="64"
disabled
/>
<div id="scale-help" class="form-text">
The number of frequency band peaks when generating noise. This
value is ignored for white noise.
</div>
</div>
<div class="col-md">
<label for="scale" class="form-label">Random noise scales</label>
<input
type="number"
class="form-control"
id="scale"
value="1"
step="1"
min="0"
max="64"
/>
</div>
<div class="col-md">
<label for="randomAlgorithm" class="form-label">
Random Generator
</label>
<select id="randomAlgorithm" class="form-select" disabled>
<option value="SYSTEM" selected="selected">
SYSTEM (Default)
</option>
<option value="CRYPTO">CRYPTO</option>
</select>
</div>
</div>
</section>
<section class="mb-3">
<h3>Impulse response setting</h3>
<p>
Generate damped sound from the generated noise and make it an
impulse response. These are its settings.
</p>
<div class="row">
<div class="col-md">
<label for="time" class="form-label" aria-describedby="time-help">
Time
</label>
<input
type="range"
class="form-range"
title="1.1"
value="2"
min="0"
max="50"
id="time"
/>
<div id="time-help" class="form-text">Room size</div>
</div>
<div class="col-md">
<label for="decay" class="form-label">Decay</label>
<input
type="range"
class="form-range"
title="2"
value="2"
min="0"
max="100"
id="decay"
/>
<div id="decay-help" class="form-text">
Hardness of room wall size
</div>
</div>
<div class="col-md">
<label for="delay" class="form-label">Delay</label>
<input
type="range"
class="form-range"
title="0"
value="0"
min="0"
max="100"
id="delay"
/>
<div id="delay-help" class="form-text">
Delays due to obstacles in front of room walls
</div>
</div>
<div class="col-md">
<label for="mix" class="form-label">Dry / Wet</label>
<input
type="range"
id="mix"
class="form-range"
min="0"
max="1"
step="0.05"
value="0.5"
title="0.5"
/>
<div id="delay-help" class="form-text">
Closer to the original sound or closer to the effector
</div>
</div>
</div>
</section>
<section class="mb-3">
<h3>Filter for Impulse response</h3>
<p>
If the value of the filter is allpass, the filtering will be
bypassed.
</p>
<div class="row">
<div class="col-md">
<label for="filter" class="form-label">Filter Type</label>
<select id="filter" class="form-select">
<option value="allpass" selected="selected">
allpass (Through)
</option>
<option value="bandpass">bandpass</option>
<option value="highpass">highpass</option>
<option value="highshelf">highshelf</option>
<option value="lowpass">lowpass</option>
<option value="lowshelf">lowshelf</option>
<option value="notch">notch</option>
<option value="peaking">peaking</option>
</select>
</div>
<div class="col-md">
<label for="freq" class="form-label">Filter frequency</label>
<input
type="range"
class="form-range"
value="2500"
min="20"
max="5000"
step="5"
id="freq"
title="2500"
/>
</div>
<div class="col-md">
<label for="freq" class="form-label">Q value</label>
<input
type="range"
class="form-range"
value="1"
min=".0001"
max="10"
step=".0005"
id="q"
title="1"
/>
</div>
</div>
</section>
</div>
</main>
<footer class="footer mt-auto py-3 bg-body-tertiary">
<div class="container">
<address class="text-muted">
© 2019-2025 by
<a href="http://logue.dev/">Logue</a>
. Licensed under the
<a href="http://opensource.org/licenses/mit-license.php">
MIT License
</a>
.
</address>
</div>
</footer>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"
></script>
<script type="module">
import Reverb from './src/Reverb';
const audioFile = new URL('/demo.flac', import.meta.url).href;
document.getElementById('play').setAttribute('disabled', 'disabled');
document.addEventListener('touchstart', initAudioContext);
function initAudioContext() {
document.removeEventListener('touchstart', initAudioContext);
// wake up AudioContext
const emptySource = ctx.createBufferSource();
emptySource.start();
emptySource.stop();
}
window.addEventListener('load', async () => {
// Setup Audio Context
const AudioCtx = new window.AudioContext();
// Defreeze AudioContext for iOS.
document.addEventListener('touchstart', initAudioContext);
function initAudioContext() {
document.removeEventListener('touchstart', initAudioContext);
// wake up AudioContext
const emptySource = AudioCtx.createBufferSource();
emptySource.start();
emptySource.stop();
}
// Setup Reverb Class
const reverb = new Reverb(AudioCtx);
console.info(
`Reverb.js loaded. (version: ${Reverb.version} / build: ${Reverb.build})`
);
const AudioSrc = AudioCtx.createBufferSource();
// Load audio file and decode asyncly.
const LoadSample = async url => {
return new Promise(resolve => {
fetch(url)
.then(response => response.arrayBuffer())
.then(arraybuf =>
AudioCtx.decodeAudioData(
arraybuf,
buffer => {
document.getElementById('play').removeAttribute('disabled');
resolve(buffer);
},
e => alert(e)
)
)
.catch(e => alert(e));
});
};
// Draw FFT to canvas
// Code taken from https://www.g200kg.com/jp/docs/webaudio/filter.html
const AnalyserNode = AudioCtx.createAnalyser();
const canvas = document.getElementById('graph');
const canvasContext = canvas.getContext('2d');
const analysedata = new Float32Array(1024);
const DrawGraph = () => {
AnalyserNode.getFloatFrequencyData(analysedata);
// Background
canvasContext.fillStyle = '#343a40';
canvasContext.fillRect(0, 0, canvas.width, canvas.height);
// FFT Graph
canvasContext.fillStyle = document.getElementById('reverb').checked
? '#17a2b8'
: '#28a745';
for (let i = 0; i < canvas.width; ++i) {
const f = (AudioCtx.sampleRate * i) / (canvas.width * 2);
const y = canvas.height / 2 + (analysedata[i] + 48.16) * 2.56;
canvasContext.fillRect(i, canvas.height - y, 1, y);
}
// y axis (dB)
for (let d = -50; d < 50; d += 10) {
const y = (canvas.height / 2 - (d * canvas.height) / 100) | 0;
// Line
canvasContext.fillStyle = '#6c757d';
canvasContext.fillRect(20, y, canvas.width, 1);
// Label
canvasContext.fillStyle = '#fd7e14';
canvasContext.fillText(d + 'dB', 5, y);
}
canvasContext.fillStyle = '#ffc107';
canvasContext.fillRect(20, canvas.height / 2, canvas.width, 1);
// x axis (frequency)
for (let f = 2200; f < AudioCtx.sampleRate / 2; f += 2000) {
const x = ((f * (canvas.width * 2)) / AudioCtx.sampleRate) | 0;
// Line
canvasContext.fillStyle = '#6c757d';
canvasContext.fillRect(x, 0, 1, canvas.height - 10);
// Label
if (x % 4 == 0) {
canvasContext.fillStyle = '#e83e8c';
canvasContext.fillText(
f / 1000 + 'kHz',
x - 10,
canvas.height - 1
);
}
}
};
// Reverb switch handler
const setReverb = () => {
AudioSrc.disconnect();
if (document.getElementById('reverb').checked) {
// Connect Reverb
reverb.connect(AudioSrc).connect(AnalyserNode);
} else {
reverb.disconnect(AudioSrc).connect(AnalyserNode);
}
AnalyserNode.connect(AudioCtx.destination);
};
const sound = await LoadSample(audioFile);
// Draw FFT
setInterval(DrawGraph, 10);
// Play button
document.getElementById('play').addEventListener(
'click',
event => {
if (event.target != event.currentTarget) return;
if (AudioSrc.buffer == null) {
AudioSrc.buffer = sound;
AudioSrc.loop = true;
setReverb();
AudioSrc.start();
}
if (AudioCtx.state === 'running') {
AudioCtx.suspend().then(() => {
event.target.innerHTML = '<em class="bi bi-play"></em> Play';
});
} else if (AudioCtx.state === 'suspended') {
AudioCtx.resume().then(() => {
event.target.innerHTML = '<em class="bi bi-pause"></em> Pause';
});
}
},
false
);
// Reverb switch button
document.getElementById('reverb').addEventListener('click', setReverb);
// Reverse checkbox
document
.getElementById('reverse')
.addEventListener('click', e => reverb.reverse(e.target.checked));
// Reverb dualation time
document.getElementById('time').addEventListener('change', e => {
reverb.time(e.target.value);
e.target.title = e.target.value;
});
// Decay time
document.getElementById('decay').addEventListener('change', e => {
reverb.decay(e.target.value);
e.target.title = e.target.value;
});
// Delay time
document.getElementById('delay').addEventListener('change', e => {
reverb.delay(e.target.value);
e.target.title = e.target.value;
});
// Filter select box
document.getElementById('filter').addEventListener('change', e => {
reverb.filterType(e.target.value);
e.target.title = e.target.value;
});
// Filter frequency
document.getElementById('freq').addEventListener('change', e => {
reverb.filterFreq(e.target.value);
e.target.title = e.target.value;
});
// Filter quality
document.getElementById('q').addEventListener('change', e => {
reverb.filterQ(e.target.value);
e.target.title = e.target.value;
});
// Dry/Wet
document.getElementById('mix').addEventListener('change', e => {
reverb.mix(e.target.value);
e.target.title = e.target.value;
});
// Noise Type
document.querySelectorAll('[name=noise]').forEach(dom =>
dom.addEventListener('click', e => {
document.getElementById('peaks').disabled =
e.target.value === 'white';
reverb.setNoise(e.target.value);
})
);
document.getElementById('peaks').addEventListener('change', e => {
reverb.peaks(e.target.value);
console.log('peaks');
e.target.title = e.target.value;
});
document.getElementById('scale').addEventListener('change', e => {
reverb.scale(e.target.value);
e.target.title = e.target.value;
});
document
.getElementById('randomAlgorithm')
.addEventListener('change', e => {
reverb.randomAlgorithm(e.target.value);
e.target.title = e.target.value;
});
});
</script>
</body>
</html>