rough filter envelope implementation
This commit is contained in:
parent
6cf0b6f651
commit
e4cd5dc552
1 changed files with 52 additions and 8 deletions
|
|
@ -505,10 +505,44 @@ export class DoughVoice {
|
||||||
|
|
||||||
const SourceClass = oscillators[this.s] ?? TriOsc;
|
const SourceClass = oscillators[this.s] ?? TriOsc;
|
||||||
this._sound = new SourceClass();
|
this._sound = new SourceClass();
|
||||||
|
|
||||||
|
// filter setup
|
||||||
this._lpf = this.cutoff ? new TwoPoleFilter() : null;
|
this._lpf = this.cutoff ? new TwoPoleFilter() : null;
|
||||||
|
if (this.lpenv) {
|
||||||
|
this._lpenv = new ADSR();
|
||||||
|
[this.lpattack, this.lpdecay, this.lpsustain, this.lprelease] = getADSRValues([
|
||||||
|
this.lpattack,
|
||||||
|
this.lpdecay,
|
||||||
|
this.lpsustain,
|
||||||
|
this.lprelease,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
this._hpf = this.hcutoff ? new TwoPoleFilter() : null;
|
this._hpf = this.hcutoff ? new TwoPoleFilter() : null;
|
||||||
|
if (this.hpenv) {
|
||||||
|
this._hpenv = new ADSR();
|
||||||
|
[this.hpattack, this.hpdecay, this.hpsustain, this.hprelease] = getADSRValues([
|
||||||
|
this.hpattack,
|
||||||
|
this.hpdecay,
|
||||||
|
this.hpsustain,
|
||||||
|
this.hprelease,
|
||||||
|
]);
|
||||||
|
}
|
||||||
this._bpf = this.bandf ? new TwoPoleFilter() : null;
|
this._bpf = this.bandf ? new TwoPoleFilter() : null;
|
||||||
|
if (this.bpenv) {
|
||||||
|
this._bpenv = new ADSR();
|
||||||
|
[this.bpattack, this.bpdecay, this.bpsustain, this.bprelease] = getADSRValues([
|
||||||
|
this.bpattack,
|
||||||
|
this.bpdecay,
|
||||||
|
this.bpsustain,
|
||||||
|
this.bprelease,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// gain envelope
|
||||||
this._adsr = new ADSR();
|
this._adsr = new ADSR();
|
||||||
|
|
||||||
|
// fx setup
|
||||||
this._coarse = this.coarse ? new Coarse() : null;
|
this._coarse = this.coarse ? new Coarse() : null;
|
||||||
this._crush = this.crush ? new Crush() : null;
|
this._crush = this.crush ? new Crush() : null;
|
||||||
this._distort = this.distort ? new Distort() : null;
|
this._distort = this.distort ? new Distort() : null;
|
||||||
|
|
@ -532,21 +566,36 @@ export class DoughVoice {
|
||||||
} else {
|
} else {
|
||||||
s = this._sound.update(this.freq);
|
s = this._sound.update(this.freq);
|
||||||
}
|
}
|
||||||
|
let gate = Number(t >= this._begin && t <= this._holdEnd);
|
||||||
|
s = s * this.gain * this.velocity;
|
||||||
|
|
||||||
// lpf
|
// lpf
|
||||||
if (this._lpf) {
|
if (this._lpf) {
|
||||||
const cutoff = this.freq2cutoff(this.cutoff);
|
let cutoff = this.freq2cutoff(this.cutoff);
|
||||||
|
if (this._lpenv) {
|
||||||
|
const env = this._lpenv.update(t, gate, this.lpattack, this.lpdecay, this.lpsustain, this.lprelease) ** 2;
|
||||||
|
cutoff = cutoff + env * this.lpenv * cutoff; // todo proper scaling
|
||||||
|
}
|
||||||
this._lpf.update(s, cutoff, this.resonance);
|
this._lpf.update(s, cutoff, this.resonance);
|
||||||
s = this._lpf.s1;
|
s = this._lpf.s1;
|
||||||
}
|
}
|
||||||
// hpf
|
// hpf
|
||||||
if (this._hpf) {
|
if (this._hpf) {
|
||||||
const cutoff = this.freq2cutoff(this.hcutoff);
|
let cutoff = this.freq2cutoff(this.hcutoff);
|
||||||
|
if (this._hpenv) {
|
||||||
|
const env = this._hpenv.update(t, gate, this.hpattack, this.hpdecay, this.hpsustain, this.hprelease) ** 2;
|
||||||
|
cutoff = cutoff + env * this.hpenv * cutoff; // todo proper scaling
|
||||||
|
}
|
||||||
this._hpf.update(s, cutoff, this.hresonance);
|
this._hpf.update(s, cutoff, this.hresonance);
|
||||||
s = s - this._hpf.s1;
|
s = s - this._hpf.s1;
|
||||||
}
|
}
|
||||||
// bpf
|
// bpf
|
||||||
if (this._bpf) {
|
if (this._bpf) {
|
||||||
const cutoff = this.freq2cutoff(this.bandf);
|
let cutoff = this.freq2cutoff(this.bandf);
|
||||||
|
if (this._bpenv) {
|
||||||
|
const env = this._bpenv.update(t, gate, this.bpattack, this.bpdecay, this.bpsustain, this.bprelease) ** 2;
|
||||||
|
cutoff = cutoff + env * this.bpenv * cutoff; // todo proper scaling
|
||||||
|
}
|
||||||
this._bpf.update(s, cutoff, this.bandq);
|
this._bpf.update(s, cutoff, this.bandq);
|
||||||
s = this._bpf.s0;
|
s = this._bpf.s0;
|
||||||
}
|
}
|
||||||
|
|
@ -555,11 +604,6 @@ export class DoughVoice {
|
||||||
this._crush && (s = this._crush.update(s, this.crush));
|
this._crush && (s = this._crush.update(s, this.crush));
|
||||||
this._distort && (s = this._distort.update(s, this.distort, this.distortvol));
|
this._distort && (s = this._distort.update(s, this.distort, this.distortvol));
|
||||||
|
|
||||||
// not sure if gain/velocity is applied here
|
|
||||||
s = s * this.gain * this.velocity;
|
|
||||||
// envelope
|
|
||||||
let gate = Number(t >= this._begin && t <= this._holdEnd);
|
|
||||||
|
|
||||||
/* Math.random() > 0.99 && console.log('gate', gate); */
|
/* Math.random() > 0.99 && console.log('gate', gate); */
|
||||||
const env = this._adsr.update(t, gate, this.attack, this.decay, this.sustain, this.release);
|
const env = this._adsr.update(t, gate, this.attack, this.decay, this.sustain, this.release);
|
||||||
s = s * env;
|
s = s * env;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue