Merge pull request #217 from tidalcycles/webdirt-feature-parity

sampler features + fixes
This commit is contained in:
Felix Roos 2022-09-22 00:03:30 +02:00 committed by GitHub
commit 5e76bc3f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -153,6 +153,8 @@ try {
console.warn('could not load AudioWorklet effects coarse, crush and shape', err); console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
} }
const cutGroups = [];
Pattern.prototype.out = function () { Pattern.prototype.out = function () {
return this.onTrigger(async (t, hap, ct, cps) => { return this.onTrigger(async (t, hap, ct, cps) => {
const hapDuration = hap.duration / cps; const hapDuration = hap.duration / cps;
@ -187,6 +189,10 @@ Pattern.prototype.out = function () {
begin = 0, begin = 0,
end = 1, end = 1,
vowel, vowel,
unit,
nudge = 0, // TODO: is this in seconds?
cut,
loop,
} = hap.value; } = hap.value;
const { velocity = 1 } = hap.context; const { velocity = 1 } = hap.context;
gain *= velocity; // legacy fix for velocity gain *= velocity; // legacy fix for velocity
@ -254,15 +260,28 @@ Pattern.prototype.out = function () {
return; return;
} }
bufferSource.playbackRate.value = Math.abs(speed) * bufferSource.playbackRate.value; bufferSource.playbackRate.value = Math.abs(speed) * bufferSource.playbackRate.value;
// TODO: nudge, unit, cut, loop if (unit === 'c') {
let duration = soundfont || clip ? hapDuration : bufferSource.buffer.duration; // are there other units?
// let duration = bufferSource.buffer.duration; bufferSource.playbackRate.value = bufferSource.playbackRate.value * bufferSource.buffer.duration;
const offset = begin * duration; }
duration = ((end - begin) * duration) / Math.abs(speed); let duration = soundfont || clip ? hapDuration : bufferSource.buffer.duration / bufferSource.playbackRate.value;
if (soundfont || clip) { // "The computation of the offset into the sound is performed using the sound buffer's natural sample rate,
bufferSource.start(t, offset); // duration does not work here for some reason // rather than the current playback rate, so even if the sound is playing at twice its normal speed,
} else { // the midway point through a 10-second audio buffer is still 5."
bufferSource.start(t, offset, duration); const offset = begin * duration * bufferSource.playbackRate.value;
duration = (end - begin) * duration;
if (loop) {
bufferSource.loop = true;
bufferSource.loopStart = offset;
bufferSource.loopEnd = offset + duration;
duration = loop * duration;
}
t += nudge;
bufferSource.start(t, offset);
if (cut !== undefined) {
cutGroups[cut]?.stop(t); // fade out?
cutGroups[cut] = bufferSource;
} }
chain.push(bufferSource); chain.push(bufferSource);
if (soundfont || clip) { if (soundfont || clip) {