mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 05:28:41 +00:00
stereo
This commit is contained in:
parent
7f60a9e52b
commit
78a6ec2f98
@ -50,8 +50,8 @@ function loadWorklets() {
|
|||||||
return workletsLoading;
|
return workletsLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getWorklet(ac, processor, params) {
|
export function getWorklet(ac, processor, params, config) {
|
||||||
const node = new AudioWorkletNode(ac, processor);
|
const node = new AudioWorkletNode(ac, processor, config);
|
||||||
Object.entries(params).forEach(([key, value]) => {
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
node.parameters.get(key).value = value;
|
node.parameters.get(key).value = value;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -52,7 +52,20 @@ export function registerSynthSounds() {
|
|||||||
const holdend = begin + duration;
|
const holdend = begin + duration;
|
||||||
const end = holdend + release + 0.01;
|
const end = holdend + release + 0.01;
|
||||||
|
|
||||||
let node = getWorklet(ac, 'better-oscillator', { frequency: freq, wave: i, begin, end });
|
let node = getWorklet(
|
||||||
|
ac,
|
||||||
|
'better-oscillator',
|
||||||
|
{
|
||||||
|
frequency: freq,
|
||||||
|
wave: i,
|
||||||
|
begin,
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
outputChannelCount: [2],
|
||||||
|
// numberOfOutputs: 1,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const envGain = gainNode(1);
|
const envGain = gainNode(1);
|
||||||
node = node.connect(envGain);
|
node = node.connect(envGain);
|
||||||
@ -69,7 +82,7 @@ export function registerSynthSounds() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{ type: 'synth', prebake: true },
|
// { prebake: true },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -148,7 +148,8 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
this.phase = [];
|
this.phase = [];
|
||||||
this.sync_phase = 0;
|
this.sync_phase = 0;
|
||||||
this.prev_sync_phase = 0;
|
this.prev_sync_phase = 0;
|
||||||
this.adj = [];
|
this.freq = [];
|
||||||
|
this.balance = [];
|
||||||
}
|
}
|
||||||
static get parameterDescriptors() {
|
static get parameterDescriptors() {
|
||||||
return [
|
return [
|
||||||
@ -209,23 +210,31 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
const output = outputs[0];
|
const output = outputs[0];
|
||||||
const numSaws = 7;
|
const numSaws = 7;
|
||||||
const detune = 0.5;
|
const detune = 0.5;
|
||||||
const spread = 0.5;
|
const spread = 0.6;
|
||||||
|
|
||||||
for (let n = 0; n < numSaws; n++) {
|
for (let n = 0; n < numSaws; n++) {
|
||||||
this.adj[n] = 0;
|
let adj = 0;
|
||||||
|
const isOdd = n % 2 === 1;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
this.adj[n] = n % 2 === 1 ? n * detune : -((n - 1) * detune);
|
adj = isOdd ? n * detune : -((n - 1) * detune);
|
||||||
}
|
}
|
||||||
|
this.freq[n] = frequency + adj * 0.01 * frequency;
|
||||||
|
// if (isOdd) {
|
||||||
|
// this.balance[n][0] =
|
||||||
|
// }
|
||||||
|
this.balance[n] = isOdd ? 1 - spread : spread;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < output[0].length; i++) {
|
for (let i = 0; i < output[0].length; i++) {
|
||||||
let out = 0;
|
let outL = 0;
|
||||||
|
let outR = 0;
|
||||||
for (let n = 0; n < numSaws; n++) {
|
for (let n = 0; n < numSaws; n++) {
|
||||||
const freq = frequency + this.adj[n];
|
const dt = this.freq[n] / sampleRate;
|
||||||
const dt = freq / sampleRate;
|
const osc = polySaw(this.phase[n], this.freq[n] / sampleRate);
|
||||||
|
outL = outL + osc * (1 - this.balance[n]);
|
||||||
|
outR = outR + osc * this.balance[n];
|
||||||
|
|
||||||
out = out + polySaw(this.phase[n], freq / sampleRate);
|
// out = out + polySaw(this.phase[n], this.freq[n] / sampleRate);
|
||||||
|
|
||||||
this.phase[n] = this.phase[n] ?? Math.random();
|
this.phase[n] = this.phase[n] ?? Math.random();
|
||||||
|
|
||||||
@ -235,7 +244,16 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
this.phase[n] = this.phase[n] - 1;
|
this.phase[n] = this.phase[n] - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output[0][i] = out;
|
|
||||||
|
output[0][i] = outL;
|
||||||
|
output[1][i] = outR;
|
||||||
|
// for (let c = 0; c < output.length; c++) {
|
||||||
|
// let modifier = c === 0 ? 1 - spread : spread;
|
||||||
|
// output[c][i] = out * modifier;
|
||||||
|
// }
|
||||||
|
// for (let c = 0; c < outputs.length; c++) {
|
||||||
|
// outputs[c][0][i] = out;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user