I have followed this tutorial and come up with that code:
context = new AudioContext();
play(frequency) {
const o = this.context.createOscillator();
const g = this.context.createGain();
o.connect(g);
g.connect(this.context.destination);
g.gain.exponentialRampToValueAtTime(
0.00001, this.context.currentTime + 1
);
o.frequency.value = frequency;
o.start(0);
}
This way I can play any notes from tutorial table by passing the values 1175
, 2794
, etc
I decided to create an array of notes and just called my play
function in the loop and it is just didn't work as all the notes just played at once with no delay.
How would you play the array of notes in a sequence?
I also was looking in to that article but still cant figure out how I can adapt my code above to that.
You can play notes in sequence with an additional parameter time in your play function.This way you can control start time and end time for each note in the sequence.
However, if you need a more precise/robust scheduler, you can use a library like WAAClock.js or take inspiration from Chris Wilson metronome to build your own.