format
This commit is contained in:
parent
0633954e24
commit
28c94efaa9
3 changed files with 195 additions and 201 deletions
|
|
@ -276,8 +276,8 @@ class TwoPoleFilter {
|
|||
s1 = 0;
|
||||
update(s, cutoff, resonance = 0) {
|
||||
// Out of bound values can produce NaNs
|
||||
resonance = clamp(resonance, 0, 1)
|
||||
cutoff = clamp(cutoff, 0, sampleRate / 2 - 1)
|
||||
resonance = clamp(resonance, 0, 1);
|
||||
cutoff = clamp(cutoff, 0, sampleRate / 2 - 1);
|
||||
const c = clamp(2 * Math.sin(cutoff * (_PI / sampleRate)), 0, 1.14);
|
||||
const r = Math.pow(0.5, (resonance + 0.125) / 0.125);
|
||||
const mrc = 1 - r * c;
|
||||
|
|
@ -289,14 +289,12 @@ class TwoPoleFilter {
|
|||
|
||||
class DJFProcessor extends AudioWorkletProcessor {
|
||||
static get parameterDescriptors() {
|
||||
return [
|
||||
{ name: 'value', defaultValue: 0.5 },
|
||||
];
|
||||
return [{ name: 'value', defaultValue: 0.5 }];
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.filters = [new TwoPoleFilter(), new TwoPoleFilter()]
|
||||
this.filters = [new TwoPoleFilter(), new TwoPoleFilter()];
|
||||
}
|
||||
|
||||
process(inputs, outputs, parameters) {
|
||||
|
|
@ -307,38 +305,34 @@ class DJFProcessor extends AudioWorkletProcessor {
|
|||
this.started = hasInput;
|
||||
|
||||
const value = clamp(parameters.value[0], 0, 1);
|
||||
let filterType = 'none'
|
||||
let cutoff
|
||||
let filterType = 'none';
|
||||
let cutoff;
|
||||
let v = 1;
|
||||
if (value > 0.5) {
|
||||
filterType = 'hipass'
|
||||
v = (value - .5) * 2
|
||||
filterType = 'hipass';
|
||||
v = (value - 0.5) * 2;
|
||||
} else if (value < 0.5) {
|
||||
filterType = 'lopass'
|
||||
v = value * 2
|
||||
filterType = 'lopass';
|
||||
v = value * 2;
|
||||
}
|
||||
cutoff = Math.pow((v * 11), 4)
|
||||
cutoff = Math.pow(v * 11, 4);
|
||||
|
||||
// let cutoff = parameters.frequency[0];
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
for (let n = 0; n < blockSize; n++) {
|
||||
if (filterType == 'none') {
|
||||
output[i][n] = input[i][n]
|
||||
output[i][n] = input[i][n];
|
||||
} else {
|
||||
this.filters[i].update(input[i][n], cutoff, 0.2)
|
||||
this.filters[i].update(input[i][n], cutoff, 0.2);
|
||||
if (filterType === 'lopass') {
|
||||
output[i][n] = this.filters[i].s1
|
||||
output[i][n] = this.filters[i].s1;
|
||||
} else if (filterType === 'hipass') {
|
||||
output[i][n] = input[i][n] - this.filters[i].s1
|
||||
output[i][n] = input[i][n] - this.filters[i].s1;
|
||||
} else {
|
||||
output[i][n] = input[i][n]
|
||||
output[i][n] = input[i][n];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue