Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/superdough/sampler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
// destructure adsr here, because the default should be different for synths and samples
let [attack, decay, sustain, release] = getADSRValues([value.attack, value.decay, value.sustain, value.release]);

const { bufferSource, sliceDuration, offset } = await getSampleBufferSource(value, bank, resolveUrl);
const sbs = await getSampleBufferSource(value, bank, resolveUrl);
const { bufferSource, sliceDuration, offset, bufferDuration } = sbs;

// asny stuff above took too long?
// any stuff above took too long?
if (ac.currentTime > t) {
logger(`[sampler] still loading sound "${s}:${n}"`, 'highlight');
// console.warn('sample still loading:', s, n);
return;
}
if (!bufferSource) {
Expand All @@ -317,13 +317,16 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
let vibratoOscillator = getVibratoOscillator(bufferSource.detune, value, t);

const time = t + nudge;

bufferSource.start(time, offset);

const envGain = ac.createGain();
const node = bufferSource.connect(envGain);

const clipDeltaSeconds = 1.5;

// if none of these controls is set, the duration of the sound will be set to the duration of the sample slice
if (clip == null && loop == null && value.release == null) {
if (clip == null && loop == null && value.release == null && bufferDuration < clipDeltaSeconds) {
duration = sliceDuration;
}
let holdEnd = t + duration;
Expand Down