fix click

This commit is contained in:
Jade (Rose) Rowland 2025-06-04 00:48:32 +01:00
parent 5336569c25
commit 5129fa6677
2 changed files with 10 additions and 8 deletions

View file

@ -146,6 +146,7 @@ export class ADSR {
startVal = 0;
update(curTime, gate, attack, decay, susVal, release) {
console.info('here')
switch (this.state) {
case 'off': {
if (gate > 0) {
@ -352,6 +353,7 @@ let getDefaultValue = (key) => defaultDefaultValues[key];
export class Dough {
init(value, sampleRate) {
// params without defaults:
/*
bank,
@ -447,12 +449,13 @@ export class Dough {
// not sure if gain is applied here
s = s * this.gain;
// envelope
let gate = Number(t >= this._begin && t <= this._end);
let gate = Number(t >= this._begin && t <= this._holdEnd);
/* Math.random() > 0.99 && console.log('gate', gate); */
const env = this._adsr.update(t, gate, this.attack, this.decay, this.sustain, this.release);
s = s * env;
s = s * this.postgain * 0.3;
s = s * this.postgain * .3
return s;
}
}

View file

@ -1,6 +1,5 @@
import { Pattern } from '@strudel/core';
import { connectToDestination, destroyAudioWorkletNode, getAudioContext } from 'superdough';
import { connectToDestination, destroyAudioWorkletNode, getAudioContext, webAudioTimeout } from 'superdough';
Pattern.prototype.supradough = function () {
return this.onTrigger((_, hap, __, cps, begin) => {
const { value } = hap;
@ -14,10 +13,11 @@ Pattern.prototype.supradough = function () {
)[3];
const duration = hap.duration / cps;
const holdend = begin + duration;
const end = holdend + release + 0.01;
const holdEnd = begin + duration;
const end = holdEnd + release + 0.01;
value._begin = begin; // these are needed for the gate signal
value._end = end;
value._holdEnd = holdEnd
let o = getWorklet(
ac,
@ -29,8 +29,7 @@ Pattern.prototype.supradough = function () {
);
o.port.postMessage(value); // send value to worklet
let timeoutNode = webAudioTimeout(ac, () => destroyAudioWorkletNode(o), begin, end);
timeoutNode.stop(end + 0.125);
webAudioTimeout(ac, () => destroyAudioWorkletNode(o), begin, end);
connectToDestination(o); // channels?
}, 1);
};