-
Notifications
You must be signed in to change notification settings - Fork 2
/
noise-machine.js
85 lines (73 loc) · 2.16 KB
/
noise-machine.js
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
/**
* Formant is a noise machine, drived by the sine. What is that?
* 1. What if to try micro-stretching/shrinking the main sine’s flow?
* - That theory seems to accord with qm - each moment there is a probability of finding one or another frequency;
* - That seems to be logical, as frequencies, which are different scales of time
*
* IT WORKS!!!!!
* I need only to:
* - map controlling values to 0..1 range
* - map frequency to speed param
* - create huuuge infrastructure of engaging them.
* That seems to be ok to update formats not really often, in that buffer matrix.
*/
var AudioBuffer = require('audio-buffer');
var ctx = require('audio-context');
// var Spectrogram = require('audio-spectrogram');
var util = require('audio-buffer-utils');
var Generator = require('audio-generator');
var Speaker = require('audio-speaker');
var random = require('distributions-normal-random/lib/number');
var Spectrum = require('audio-spectrum');
var Waveform = require('audio-waveform');
var spectrum = Spectrum({
fftSize: 512,
smoothingTimeConstant: .9
});
var waveform = Waveform({
size: 128
});
document.body.appendChild(spectrum.canvas);
document.body.appendChild(waveform.canvas);
//try to walk on the sine with different speed
var f = 440;
var phase = 0;
var lastTime = 0;
var pi2 = Math.PI * 2;
var speed = 9000; //rad/step
var q = 10000;
Generator(function (time) {
var dt = time - lastTime;
lastTime = time;
dt += random(0, 1/q);
phase += speed * dt;
phase = (phase) % pi2;
var value = Math.cos(phase);
return value;
})
// .pipe(spectrum)
// .pipe(waveform)
.pipe(Speaker());
//add a bit of interface
if (typeof document !== 'undefined') {
var speedEl = document.createElement('input');
speedEl.type = 'range';
speedEl.min = 100;
speedEl.max = 20000;
speedEl.step = 5;
speedEl.value = speed;
speedEl.addEventListener('input', function (e) {
speed = parseInt(speedEl.value);
});
document.body.appendChild(speedEl);
var qEl = document.createElement('input');
qEl.type = 'range';
qEl.min = 1;
qEl.max = 1000000;
qEl.step = 100;
qEl.value = q;
qEl.addEventListener('input', function (e) {
q = parseInt(qEl.value);
});
document.body.appendChild(qEl);
}