rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.89k stars 160 forks source link

Can we manage playing sequence of short duration MP3 files ? #71

Closed shivrajsa closed 6 years ago

shivrajsa commented 7 years ago

I have a app developed using MIDI.js where I can create sequence of notes (for song) & play with useful parameters. Mainly I can manage duration of each note.

Can we achieve same using this library? I have set of all MP3 files for notes, is it possible to play them in sequence while controlling duration for each note ? Please guide.

rserota commented 7 years ago

when you call play(), you can set a wait parameter, which causes the note to not be triggered immediately, but after the amount of time specified by wait. Similarly, you can pass an exactTime paremeter into play(), which uses the webAudio clock to trigger the sound at a specific time. Either of those options should do what you need to do. Here's an example:

var bell = new Wad({source: 'http://mysite/com/bell.wav"}) bell.play({wait : 0, env : {hold : .5}}) bell.play({wait : .5, env : {hold : .5}}) bell.play({wait : 1, env : {hold : 1}}) bell.play({wait : 1.5, env : {hold : .5}})

In the above code, the bell sound is triggered 4 times, every half-second. The third time it is triggered, it plays for twice as long as the other 3 times it is triggered.

shivrajsa commented 7 years ago

@rserota Can I use 'for' looop to use bell.play({wait : 0, env : {hold : .5}}) to play array of notes & wait parameter

rserota commented 7 years ago

You sure can. You could try something like this:

var notes = [{pitch: "C4", wait: 1}, {pitch: "D4", wait: 2}, {pitch: "E4", wait: 3}];
for (var i = 0; i < notes.length; i++){
   bell.play(notes[i])
}