This commit is contained in:
Felix Roos 2025-06-07 20:31:47 +02:00
parent 77463a199a
commit b000f2297d
No known key found for this signature in database

View file

@ -449,6 +449,7 @@ const defaultDefaultValues = {
fft: 8, fft: 8,
z: 'triangle', z: 'triangle',
pan: 0.5, pan: 0.5,
fmh: 1,
}; };
let getDefaultValue = (key) => defaultDefaultValues[key]; let getDefaultValue = (key) => defaultDefaultValues[key];
@ -518,6 +519,8 @@ export class DoughVoice {
roomsize, roomsize,
ir, ir,
analyze, analyze,
fmh,
fmi
*/ */
value.freq = getFrequency(value); value.freq = getFrequency(value);
Object.assign(this, value); Object.assign(this, value);
@ -550,6 +553,20 @@ export class DoughVoice {
const SourceClass = oscillators[this.s] ?? TriOsc; const SourceClass = oscillators[this.s] ?? TriOsc;
this._sound = new SourceClass(); this._sound = new SourceClass();
if (this.fmi) {
this._fm = new SineOsc();
this.fmh = this.fmh ?? getDefaultValue('fmh');
if (this.fmenv) {
this._fmenv = new ADSR();
[this.fmattack, this.fmdecay, this.fmsustain, this.fmrelease] = getADSRValues([
this.fmattack,
this.fmdecay,
this.fmsustain,
this.fmrelease,
]);
}
}
// filter setup // filter setup
this._lpf = this.cutoff ? new TwoPoleFilter() : null; this._lpf = this.cutoff ? new TwoPoleFilter() : null;
this.resonance = this.resonance ?? getDefaultValue('resonance'); this.resonance = this.resonance ?? getDefaultValue('resonance');
@ -613,13 +630,26 @@ export class DoughVoice {
return 0; return 0;
} }
let s = 0; let s = 0;
let gate = Number(t >= this._begin && t <= this._holdEnd);
let freq = this.freq;
if (this._fm) {
let fmi = this.fmi;
if (this._fmenv) {
const env = this._fmenv.update(t, gate, this.fmattack, this.fmdecay, this.fmsustain, this.fmrelease) ** 2;
fmi = /* 2 ** */ this.fmenv * env * fmi; // todo: find good scaling
}
const modfreq = freq * this.fmh;
const modgain = modfreq * fmi;
freq = freq + this._fm.update(modfreq) * modgain;
}
// sound source // sound source
if (this.s === 'pulse') { if (this.s === 'pulse') {
s = this._sound.update(this.freq, this.pw ?? 0.5); s = this._sound.update(freq, this.pw ?? 0.5);
} else { } else {
s = this._sound.update(this.freq); s = this._sound.update(freq);
} }
let gate = Number(t >= this._begin && t <= this._holdEnd);
s = s * this.gain * this.velocity; s = s * this.gain * this.velocity;
// lpf // lpf