-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.32 KB
/
index.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
var instruments = require('@mohayonao/wave-tables');
function getPeriodicWave(ctx, name) {
var instrument_obj = instruments[name]
var wave = ctx.createPeriodicWave(
Float32Array.from(instrument_obj.real),
Float32Array.from(instrument_obj.imag)
);
return wave;
}
function getInstrumentNames() {
return Object.keys(instruments);
}
function getAllPeriodicWaves(ctx) {
let instrument_names = getInstrumentNames();
let periodic_waves = []
instrument_names.forEach(function (name) {
periodic_waves[name] = getPeriodicWave(ctx, name);
});
return periodic_waves;
}
function getWaveOscillator(ctx, name) {
let oscillator = ctx.createOscillator();
let wave = getPeriodicWave(ctx, name)
oscillator.setPeriodicWave(wave);
return oscillator;
}
function getAllWaveOscillators(ctx) {
let instrument_names = getInstrumentNames();
let oscillators = []
instrument_names.forEach(function (name) {
oscillators[name] = getWaveOscillator(ctx, name);
});
return oscillators;
}
module.exports.getInstrumentNames = getInstrumentNames;
module.exports.getAllPeriodicWaves = getAllPeriodicWaves;
module.exports.getAllWaveOscillators = getAllWaveOscillators;
module.exports.getPeriodicWave = getPeriodicWave;
module.exports.getWaveOscillator = getWaveOscillator;