adding loopBegin and loopEnd

This commit is contained in:
Raphael Forment 2023-09-10 18:34:21 +02:00
parent abaeb52b7c
commit 3582ae9163
2 changed files with 9 additions and 10 deletions

View File

@ -882,6 +882,8 @@ const generic_params = [
['zdelay'], ['zdelay'],
['tremolo'], ['tremolo'],
['zzfx'], ['zzfx'],
['loopBegin'],
['loopEnd'],
]; ];
// TODO: slice / splice https://www.youtube.com/watch?v=hKhPdO0RKDQ&list=PL2lW1zNIIwj3bDkh-Y3LUGDuRcoUigoDs&index=13 // TODO: slice / splice https://www.youtube.com/watch?v=hKhPdO0RKDQ&list=PL2lW1zNIIwj3bDkh-Y3LUGDuRcoUigoDs&index=13

View File

@ -207,7 +207,9 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
n = 0, n = 0,
note, note,
speed = 1, // sample playback speed speed = 1, // sample playback speed
loopBegin = 0,
begin = 0, begin = 0,
loopEnd = 1,
end = 1, end = 1,
} = value; } = value;
// load sample // load sample
@ -242,19 +244,14 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
// rather than the current playback rate, so even if the sound is playing at twice its normal speed, // rather than the current playback rate, so even if the sound is playing at twice its normal speed,
// the midway point through a 10-second audio buffer is still 5." // the midway point through a 10-second audio buffer is still 5."
const offset = begin * bufferSource.buffer.duration; const offset = begin * bufferSource.buffer.duration;
bufferSource.start(time, offset);
const bufferDuration = bufferSource.buffer.duration / bufferSource.playbackRate.value; const bufferDuration = bufferSource.buffer.duration / bufferSource.playbackRate.value;
/*if (loop) { if (loop) {
// TODO: idea for loopBegin / loopEnd
// if one of [loopBegin,loopEnd] is <= 1, interpret it as normlized
// if [loopBegin,loopEnd] is bigger >= 1, interpret it as sample number
// this will simplify perfectly looping things, while still keeping the normalized option
// the only drawback is that looping between samples 0 and 1 is not possible (which is not real use case)
bufferSource.loop = true; bufferSource.loop = true;
bufferSource.loopStart = offset; bufferSource.loopStart = loopBegin * bufferDuration - offset;
bufferSource.loopEnd = offset + duration; bufferSource.loopEnd = loopEnd * bufferDuration - offset;
duration = loop * duration; duration = loop * duration;
}*/ }
bufferSource.start(time, offset);
const { node: envelope, stop: releaseEnvelope } = getEnvelope(attack, decay, sustain, release, 1, t); const { node: envelope, stop: releaseEnvelope } = getEnvelope(attack, decay, sustain, release, 1, t);
bufferSource.connect(envelope); bufferSource.connect(envelope);
const out = ac.createGain(); // we need a separate gain for the cutgroups because firefox... const out = ac.createGain(); // we need a separate gain for the cutgroups because firefox...