blob: 30972ba1e8537a34e8e95e57b8872150e83ad178 (
plain)
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
|
import Tone from "tone";
const oscillators = {};
let output;
let lastPlayed;
function load(out) {
output = out;
}
function play(freq) {
if (!output) {
return;
}
const osc = (oscillators[freq] = oscillators[freq] || {});
if (!osc.el) {
osc.el = new Tone.Oscillator(freq, "sine");
osc.el.connect(output);
}
osc.el.start();
osc.playing = true;
lastPlayed = osc;
return osc;
}
function pause(freq) {
if (!oscillators[freq]) return;
const osc = (oscillators[freq] = oscillators[freq] || {});
if (osc.el) osc.el.stop();
osc.playing = false;
return osc;
}
export default { play, pause, oscillators };
|