hpf + bpf
This commit is contained in:
parent
794bf86904
commit
6cf0b6f651
1 changed files with 29 additions and 29 deletions
|
|
@ -60,7 +60,7 @@ export class TriOsc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Lpf {
|
export class TwoPoleFilter {
|
||||||
s0 = 0;
|
s0 = 0;
|
||||||
s1 = 0;
|
s1 = 0;
|
||||||
update(s, cutoff, resonance = 0) {
|
update(s, cutoff, resonance = 0) {
|
||||||
|
|
@ -70,15 +70,10 @@ export class Lpf {
|
||||||
var c = Math.pow(0.5, (1 - cutoff) / 0.125);
|
var c = Math.pow(0.5, (1 - cutoff) / 0.125);
|
||||||
var r = Math.pow(0.5, (resonance + 0.125) / 0.125);
|
var r = Math.pow(0.5, (resonance + 0.125) / 0.125);
|
||||||
var mrc = 1 - r * c;
|
var mrc = 1 - r * c;
|
||||||
var v0 = this.s0;
|
|
||||||
var v1 = this.s1;
|
this.s0 = mrc * this.s0 - c * this.s1 + c * s; // bpf
|
||||||
// Apply the filter to the sample
|
this.s1 = mrc * this.s1 + c * this.s0; // lpf
|
||||||
v0 = mrc * v0 - c * v1 + c * s;
|
return this.s1; // return lpf by default
|
||||||
v1 = mrc * v1 + c * v0;
|
|
||||||
s = v1;
|
|
||||||
this.s0 = v0;
|
|
||||||
this.s1 = v1;
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -287,6 +282,7 @@ export class Slew {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// overdrive style distortion (adapted from noisecraft) currently unused
|
||||||
export function applyDistortion(x, amount) {
|
export function applyDistortion(x, amount) {
|
||||||
amount = Math.min(Math.max(amount, 0), 1);
|
amount = Math.min(Math.max(amount, 0), 1);
|
||||||
amount -= 0.01;
|
amount -= 0.01;
|
||||||
|
|
@ -332,16 +328,6 @@ export class Crush {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// (unused) overdrive-style distortion (adapted from noisecraft)
|
|
||||||
export class Overdrive {
|
|
||||||
update(input, amount = 0, postgain = 1) {
|
|
||||||
amount = Math.min(Math.max(amount, 0), 1);
|
|
||||||
amount -= 0.01;
|
|
||||||
const shape = (2 * amount) / (1 - amount);
|
|
||||||
return (((1 + shape) * input) / (1 + shape * Math.abs(input))) * postgain;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is the distort from superdough
|
// this is the distort from superdough
|
||||||
export class Distort {
|
export class Distort {
|
||||||
update(input, distort = 0, postgain = 1) {
|
update(input, distort = 0, postgain = 1) {
|
||||||
|
|
@ -394,9 +380,12 @@ const defaultDefaultValues = {
|
||||||
density: '.03',
|
density: '.03',
|
||||||
ftype: '12db',
|
ftype: '12db',
|
||||||
fanchor: 0,
|
fanchor: 0,
|
||||||
resonance: 1,
|
//resonance: 1, // superdough resonance is scaled differently
|
||||||
hresonance: 1,
|
resonance: 0,
|
||||||
bandq: 1,
|
//hresonance: 1, // superdough resonance is scaled differently
|
||||||
|
hresonance: 0,
|
||||||
|
// bandq: 1, // superdough resonance is scaled differently
|
||||||
|
bandq: 0,
|
||||||
channels: [1, 2],
|
channels: [1, 2],
|
||||||
phaserdepth: 0.75,
|
phaserdepth: 0.75,
|
||||||
shapevol: 1,
|
shapevol: 1,
|
||||||
|
|
@ -470,11 +459,7 @@ export class DoughVoice {
|
||||||
phaserrate,
|
phaserrate,
|
||||||
phasersweep,
|
phasersweep,
|
||||||
phasercenter,
|
phasercenter,
|
||||||
coarse,
|
|
||||||
crush,
|
|
||||||
shape,
|
shape,
|
||||||
distort,
|
|
||||||
pan,
|
|
||||||
vowel,
|
vowel,
|
||||||
room,
|
room,
|
||||||
roomfade,
|
roomfade,
|
||||||
|
|
@ -520,7 +505,9 @@ export class DoughVoice {
|
||||||
|
|
||||||
const SourceClass = oscillators[this.s] ?? TriOsc;
|
const SourceClass = oscillators[this.s] ?? TriOsc;
|
||||||
this._sound = new SourceClass();
|
this._sound = new SourceClass();
|
||||||
this._lpf = this.cutoff ? new Lpf() : null;
|
this._lpf = this.cutoff ? new TwoPoleFilter() : null;
|
||||||
|
this._hpf = this.hcutoff ? new TwoPoleFilter() : null;
|
||||||
|
this._bpf = this.bandf ? new TwoPoleFilter() : null;
|
||||||
this._adsr = new ADSR();
|
this._adsr = new ADSR();
|
||||||
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;
|
||||||
|
|
@ -548,7 +535,20 @@ export class DoughVoice {
|
||||||
// lpf
|
// lpf
|
||||||
if (this._lpf) {
|
if (this._lpf) {
|
||||||
const cutoff = this.freq2cutoff(this.cutoff);
|
const cutoff = this.freq2cutoff(this.cutoff);
|
||||||
s = this._lpf.update(s, cutoff, this.resonance);
|
this._lpf.update(s, cutoff, this.resonance);
|
||||||
|
s = this._lpf.s1;
|
||||||
|
}
|
||||||
|
// hpf
|
||||||
|
if (this._hpf) {
|
||||||
|
const cutoff = this.freq2cutoff(this.hcutoff);
|
||||||
|
this._hpf.update(s, cutoff, this.hresonance);
|
||||||
|
s = s - this._hpf.s1;
|
||||||
|
}
|
||||||
|
// bpf
|
||||||
|
if (this._bpf) {
|
||||||
|
const cutoff = this.freq2cutoff(this.bandf);
|
||||||
|
this._bpf.update(s, cutoff, this.bandq);
|
||||||
|
s = this._bpf.s0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._coarse && (s = this._coarse.update(s, this.coarse));
|
this._coarse && (s = this._coarse.update(s, this.coarse));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue