mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 20:48:27 +00:00
disconnect worklet at scheduled time to destroy faster
This commit is contained in:
parent
5d55b9c9ef
commit
dad18a24fb
@ -186,6 +186,16 @@ export function getVibratoOscillator(param, value, t) {
|
|||||||
return vibratoOscillator;
|
return vibratoOscillator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ConstantSource inherits AudioScheduledSourceNode, which has scheduling abilities
|
||||||
|
// a bit of a hack, but it works very well :)
|
||||||
|
export function webAudioTimeout(audioContext, onComplete, startTime, stopTime) {
|
||||||
|
const constantNode = audioContext.createConstantSource();
|
||||||
|
constantNode.start(startTime);
|
||||||
|
constantNode.stop(stopTime);
|
||||||
|
constantNode.onended = () => {
|
||||||
|
onComplete();
|
||||||
|
};
|
||||||
|
}
|
||||||
const mod = (freq, range = 1, type = 'sine') => {
|
const mod = (freq, range = 1, type = 'sine') => {
|
||||||
const ctx = getAudioContext();
|
const ctx = getAudioContext();
|
||||||
const osc = ctx.createOscillator();
|
const osc = ctx.createOscillator();
|
||||||
|
|||||||
@ -1,6 +1,14 @@
|
|||||||
import { clamp, midiToFreq, noteToMidi } from './util.mjs';
|
import { clamp, midiToFreq, noteToMidi } from './util.mjs';
|
||||||
import { registerSound, getAudioContext, getWorklet } from './superdough.mjs';
|
import { registerSound, getAudioContext, getWorklet } from './superdough.mjs';
|
||||||
import { applyFM, gainNode, getADSRValues, getParamADSR, getPitchEnvelope, getVibratoOscillator } from './helpers.mjs';
|
import {
|
||||||
|
applyFM,
|
||||||
|
gainNode,
|
||||||
|
getADSRValues,
|
||||||
|
getParamADSR,
|
||||||
|
getPitchEnvelope,
|
||||||
|
getVibratoOscillator,
|
||||||
|
webAudioTimeout,
|
||||||
|
} from './helpers.mjs';
|
||||||
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
||||||
|
|
||||||
const getFrequencyFromValue = (value) => {
|
const getFrequencyFromValue = (value) => {
|
||||||
@ -78,7 +86,7 @@ export function registerSynthSounds() {
|
|||||||
const end = holdend + release + 0.01;
|
const end = holdend + release + 0.01;
|
||||||
const voices = clamp(unison, 1, 100);
|
const voices = clamp(unison, 1, 100);
|
||||||
|
|
||||||
let node = getWorklet(
|
let o = getWorklet(
|
||||||
ac,
|
ac,
|
||||||
'supersaw-oscillator',
|
'supersaw-oscillator',
|
||||||
{
|
{
|
||||||
@ -93,20 +101,32 @@ export function registerSynthSounds() {
|
|||||||
outputChannelCount: [2],
|
outputChannelCount: [2],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const gainAdjustment = 1 / Math.sqrt(voices);
|
|
||||||
getPitchEnvelope(node.parameters.get('detune'), value, begin, holdend);
|
|
||||||
getVibratoOscillator(node.parameters.get('detune'), value, begin);
|
|
||||||
applyFM(node.parameters.get('frequency'), value, begin);
|
|
||||||
const envGain = gainNode(1);
|
|
||||||
node = node.connect(envGain);
|
|
||||||
|
|
||||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.3 * gainAdjustment, begin, holdend, 'linear');
|
const gainAdjustment = 1 / Math.sqrt(voices);
|
||||||
|
getPitchEnvelope(o.parameters.get('detune'), value, begin, holdend);
|
||||||
|
const vibratoOscillator = getVibratoOscillator(o.parameters.get('detune'), value, begin);
|
||||||
|
const fm = applyFM(o.parameters.get('frequency'), value, begin);
|
||||||
|
let envGain = gainNode(1);
|
||||||
|
envGain = o.connect(envGain);
|
||||||
|
|
||||||
|
webAudioTimeout(
|
||||||
|
ac,
|
||||||
|
() => {
|
||||||
|
o.disconnect();
|
||||||
|
envGain.disconnect();
|
||||||
|
onended();
|
||||||
|
fm?.stop();
|
||||||
|
vibratoOscillator?.stop();
|
||||||
|
},
|
||||||
|
begin,
|
||||||
|
holdend,
|
||||||
|
);
|
||||||
|
|
||||||
|
getParamADSR(envGain.gain, attack, decay, sustain, release, 0, 0.3 * gainAdjustment, begin, holdend, 'linear');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
node,
|
node: envGain,
|
||||||
stop: (time) => {
|
stop: (time) => {},
|
||||||
// o.stop(time);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{ prebake: true, type: 'synth' },
|
{ prebake: true, type: 'synth' },
|
||||||
|
|||||||
@ -175,7 +175,6 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.phase = [];
|
this.phase = [];
|
||||||
this.logged = 0;
|
|
||||||
}
|
}
|
||||||
static get parameterDescriptors() {
|
static get parameterDescriptors() {
|
||||||
return [
|
return [
|
||||||
@ -230,6 +229,7 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
}
|
}
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
if (currentTime >= params.end[0]) {
|
if (currentTime >= params.end[0]) {
|
||||||
|
// this.port.postMessage({ type: 'onended' });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let frequency = params.frequency[0];
|
let frequency = params.frequency[0];
|
||||||
@ -246,9 +246,6 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
for (let n = 0; n < voices; n++) {
|
for (let n = 0; n < voices; n++) {
|
||||||
const isOdd = (n & 1) == 1;
|
const isOdd = (n & 1) == 1;
|
||||||
|
|
||||||
if (this.logged < 10) {
|
|
||||||
this.logged += 1;
|
|
||||||
}
|
|
||||||
//applies unison "spread" detune in semitones
|
//applies unison "spread" detune in semitones
|
||||||
const freq = frequency * Math.pow(2, getUnisonDetune(voices, freqspread, n) / 1.2);
|
const freq = frequency * Math.pow(2, getUnisonDetune(voices, freqspread, n) / 1.2);
|
||||||
let gainL = gain1;
|
let gainL = gain1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user