I have an odd situation that I can’t seem to figure out what’s happening.
I call for a sound effect to be played at 00:30 later. It’s something like this:
a.play(30, x, x);
But because of certain changes, I would like to stop that before it has started at 00:20… so I call
a.stop(); //instead of using dispose because I might need to use this sound again
But the sound still plays…and I couldn’t stop it from playing.
Unfortunately that doesn’t work in my case. Here is the issue, it’s an automated piano-playing system. So it’s calling all the notes at once based on the database (with onsets and pitches) I have. The methods above still can’t kill the sound.
for (var i = 0; i < pitches.length; i++) {
btff[thenote].setVolume(1, 0.01);
btff[thenote].play(onsets[i] / 1000 * usertempo, 0, lengths[i] / 1000 * usertempo);}
Think you would better to not use BABYLON.Sound, but WebAudio directly. Once something is scheduled on the audioContext, there is no way to stop it. It can be delayed using context.suspend(), but will resume later.
You can actually just context.close(), & then create a new context. Not sure if you can do that to the BABYLON.Sound context cleanly.
Gotta say BABYLON.Sound is geared to playing sound files, not making music with many, many short duration buffers. I see you are an actual musician. If you are ok with using audio that you did not originate, WebAudioFonts is a library which handles what you wish to do in a more direct way.
I am doing not doing 88 keys, just 72, but here is a test file I made about 6 weeks ago. https://youtu.be/O-pK260uKxw
Once you have an instrument you want (that’s why I asked if you were ok with not originating the audio), view the corresponding code from the repo to get you started.
I think thenote inside the timeout function is executed not like thenote outside the timeout function… Is there a way to pass thenote inside the settimeout function?
when I tried console.log(thenote) inside and outside the settimeout function…they are different. one updates, the other got stuck
I think thenote inside the timeout function is executed not like thenote outside the timeout function… Is there a way to pass thenote inside the settimeout function?
when I tried console.log(thenote) inside and outside the settimeout function…they are different. one updates, the other got stuck