mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-13 14:48:36 +00:00
cleaning
This commit is contained in:
parent
1666b50857
commit
c2df8aa6b9
@ -25,11 +25,51 @@ const waveforms = ['triangle', 'square', 'sawtooth', 'sine'];
|
||||
const noises = ['pink', 'white', 'brown', 'crackle'];
|
||||
|
||||
export function registerSynthSounds() {
|
||||
[...waveforms].forEach((s) => {
|
||||
registerSound(
|
||||
s,
|
||||
(t, value, onended) => {
|
||||
const [attack, decay, sustain, release] = getADSRValues(
|
||||
[value.attack, value.decay, value.sustain, value.release],
|
||||
'linear',
|
||||
[0.001, 0.05, 0.6, 0.01],
|
||||
);
|
||||
|
||||
let sound;
|
||||
sound = getOscillator(s, t, value);
|
||||
let { node: o, stop, triggerRelease } = sound;
|
||||
|
||||
// turn down
|
||||
const g = gainNode(0.3);
|
||||
|
||||
const { duration } = value;
|
||||
|
||||
o.onended = () => {
|
||||
o.disconnect();
|
||||
g.disconnect();
|
||||
onended();
|
||||
};
|
||||
|
||||
const envGain = gainNode(1);
|
||||
let node = o.connect(g).connect(envGain);
|
||||
const holdEnd = t + duration;
|
||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 1, t, holdEnd, 'linear');
|
||||
const envEnd = holdEnd + release + 0.01;
|
||||
triggerRelease?.(envEnd);
|
||||
stop(envEnd);
|
||||
return {
|
||||
node,
|
||||
stop: (releaseTime) => {},
|
||||
};
|
||||
},
|
||||
{ type: 'synth', prebake: true },
|
||||
);
|
||||
});
|
||||
registerSound(
|
||||
'supersaw',
|
||||
(begin, value, onended) => {
|
||||
const ac = getAudioContext();
|
||||
let { note, freq, duration } = value;
|
||||
let { note, freq, duration, n = 2 } = value;
|
||||
note = note || 36;
|
||||
if (typeof note === 'string') {
|
||||
note = noteToMidi(note); // e.g. c3 => 48
|
||||
@ -58,7 +98,9 @@ export function registerSynthSounds() {
|
||||
frequency: freq,
|
||||
begin,
|
||||
end,
|
||||
detune: 0,
|
||||
detune: Math.min(200, Math.max(0, n * 0.1)),
|
||||
// voices: n,
|
||||
// spread: 0,
|
||||
},
|
||||
{
|
||||
outputChannelCount: [2],
|
||||
@ -68,7 +110,7 @@ export function registerSynthSounds() {
|
||||
const envGain = gainNode(1);
|
||||
node = node.connect(envGain);
|
||||
|
||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.1, begin, holdend, 'linear');
|
||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.3, begin, holdend, 'linear');
|
||||
|
||||
return {
|
||||
node,
|
||||
|
||||
@ -170,7 +170,7 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||
|
||||
{
|
||||
name: 'spread',
|
||||
defaultValue: 0.6,
|
||||
defaultValue: 0.4,
|
||||
min: 0,
|
||||
max: 1,
|
||||
},
|
||||
@ -202,6 +202,7 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||
const detune = params.detune[0];
|
||||
let spread = params.spread[0];
|
||||
spread = spread * 0.5 + 0.5;
|
||||
const gainAdjustment = Math.max(0.75, 1 - (voices - 1) * 0.05);
|
||||
|
||||
for (let n = 0; n < voices; n++) {
|
||||
let adj = 0;
|
||||
@ -217,8 +218,8 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||
this.phase[n] = this.phase[n] ?? Math.random();
|
||||
const v = saw(this.phase[n], dt);
|
||||
|
||||
output[0][i] = output[0][i] + v * (1 - balance);
|
||||
output[1][i] = output[1][i] + v * balance;
|
||||
output[0][i] = (output[0][i] + v * (1 - balance)) * gainAdjustment;
|
||||
output[1][i] = (output[1][i] + v * balance) * gainAdjustment;
|
||||
|
||||
this.phase[n] += dt;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user