This commit is contained in:
Jade (Rose) Rowland 2025-09-24 00:24:25 -07:00
parent 0633954e24
commit 28c94efaa9
3 changed files with 195 additions and 201 deletions

View file

@ -749,7 +749,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
} }
if (djf != null) { if (djf != null) {
orbitBus.getDjf(djf, t) orbitBus.getDjf(djf, t);
} }
// analyser // analyser

View file

@ -26,14 +26,14 @@ export class Orbit {
} }
getDjf(value, t = 0) { getDjf(value, t = 0) {
if (this.djfNode == null){ if (this.djfNode == null) {
this.djfNode = getWorklet(this.audioContext, 'djf-processor', {value}) this.djfNode = getWorklet(this.audioContext, 'djf-processor', { value });
this.summingNode.disconnect() this.summingNode.disconnect();
this.summingNode.connect(this.djfNode) this.summingNode.connect(this.djfNode);
this.djfNode.connect(this.output) this.djfNode.connect(this.output);
} }
const val = this.djfNode.parameters.get('value') const val = this.djfNode.parameters.get('value');
val.setValueAtTime(value, t) val.setValueAtTime(value, t);
} }
getDelay(delaytime = 0, feedback = 0.5, t) { getDelay(delaytime = 0, feedback = 0.5, t) {

View file

@ -276,8 +276,8 @@ class TwoPoleFilter {
s1 = 0; s1 = 0;
update(s, cutoff, resonance = 0) { update(s, cutoff, resonance = 0) {
// Out of bound values can produce NaNs // Out of bound values can produce NaNs
resonance = clamp(resonance, 0, 1) resonance = clamp(resonance, 0, 1);
cutoff = clamp(cutoff, 0, sampleRate / 2 - 1) cutoff = clamp(cutoff, 0, sampleRate / 2 - 1);
const c = clamp(2 * Math.sin(cutoff * (_PI / sampleRate)), 0, 1.14); const c = clamp(2 * Math.sin(cutoff * (_PI / sampleRate)), 0, 1.14);
const r = Math.pow(0.5, (resonance + 0.125) / 0.125); const r = Math.pow(0.5, (resonance + 0.125) / 0.125);
const mrc = 1 - r * c; const mrc = 1 - r * c;
@ -289,14 +289,12 @@ class TwoPoleFilter {
class DJFProcessor extends AudioWorkletProcessor { class DJFProcessor extends AudioWorkletProcessor {
static get parameterDescriptors() { static get parameterDescriptors() {
return [ return [{ name: 'value', defaultValue: 0.5 }];
{ name: 'value', defaultValue: 0.5 },
];
} }
constructor() { constructor() {
super(); super();
this.filters = [new TwoPoleFilter(), new TwoPoleFilter()] this.filters = [new TwoPoleFilter(), new TwoPoleFilter()];
} }
process(inputs, outputs, parameters) { process(inputs, outputs, parameters) {
@ -307,38 +305,34 @@ class DJFProcessor extends AudioWorkletProcessor {
this.started = hasInput; this.started = hasInput;
const value = clamp(parameters.value[0], 0, 1); const value = clamp(parameters.value[0], 0, 1);
let filterType = 'none' let filterType = 'none';
let cutoff let cutoff;
let v = 1; let v = 1;
if (value > 0.5) { if (value > 0.5) {
filterType = 'hipass' filterType = 'hipass';
v = (value - .5) * 2 v = (value - 0.5) * 2;
} else if (value < 0.5) { } else if (value < 0.5) {
filterType = 'lopass' filterType = 'lopass';
v = value * 2 v = value * 2;
} }
cutoff = Math.pow((v * 11), 4) cutoff = Math.pow(v * 11, 4);
// let cutoff = parameters.frequency[0]; // let cutoff = parameters.frequency[0];
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
for (let n = 0; n < blockSize; n++) { for (let n = 0; n < blockSize; n++) {
if (filterType == 'none') { if (filterType == 'none') {
output[i][n] = input[i][n] output[i][n] = input[i][n];
} else { } else {
this.filters[i].update(input[i][n], cutoff, 0.2) this.filters[i].update(input[i][n], cutoff, 0.2);
if (filterType === 'lopass') { if (filterType === 'lopass') {
output[i][n] = this.filters[i].s1 output[i][n] = this.filters[i].s1;
} else if (filterType === 'hipass') { } 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 { } else {
output[i][n] = input[i][n] output[i][n] = input[i][n];
} }
} }
} }
} }
return true; return true;