mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 05:28:41 +00:00
working
This commit is contained in:
parent
8a7d72bf24
commit
7383dca9ee
@ -26,47 +26,51 @@ const noises = ['pink', 'white', 'brown', 'crackle'];
|
|||||||
|
|
||||||
export function registerSynthSounds() {
|
export function registerSynthSounds() {
|
||||||
[...waveforms].forEach((s, i) => {
|
[...waveforms].forEach((s, i) => {
|
||||||
registerSound(s, (begin, value, onended) => {
|
registerSound(
|
||||||
const ac = getAudioContext();
|
s,
|
||||||
let { note, freq, duration } = value;
|
(begin, value, onended) => {
|
||||||
note = note || 36;
|
const ac = getAudioContext();
|
||||||
if (typeof note === 'string') {
|
let { note, freq, duration } = value;
|
||||||
note = noteToMidi(note); // e.g. c3 => 48
|
note = note || 36;
|
||||||
}
|
if (typeof note === 'string') {
|
||||||
// get frequency
|
note = noteToMidi(note); // e.g. c3 => 48
|
||||||
if (!freq && typeof note === 'number') {
|
}
|
||||||
freq = midiToFreq(note); // + 48);
|
// get frequency
|
||||||
}
|
if (!freq && typeof note === 'number') {
|
||||||
|
freq = midiToFreq(note); // + 48);
|
||||||
|
}
|
||||||
|
|
||||||
// set frequency
|
// set frequency
|
||||||
freq = Number(freq);
|
freq = Number(freq);
|
||||||
|
|
||||||
const [attack, decay, sustain, release] = getADSRValues(
|
const [attack, decay, sustain, release] = getADSRValues(
|
||||||
[value.attack, value.decay, value.sustain, value.release],
|
[value.attack, value.decay, value.sustain, value.release],
|
||||||
'linear',
|
'linear',
|
||||||
[0.001, 0.05, 0.6, 0.01],
|
[0.001, 0.05, 0.6, 0.01],
|
||||||
);
|
);
|
||||||
|
|
||||||
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 });
|
||||||
|
|
||||||
const envGain = gainNode(1);
|
const envGain = gainNode(1);
|
||||||
node = node.connect(envGain);
|
node = node.connect(envGain);
|
||||||
|
|
||||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.3, begin, holdend, 'linear');
|
getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.3, begin, holdend, 'linear');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
node,
|
node,
|
||||||
stop: (time) => {
|
stop: (time) => {
|
||||||
// o.stop(time);
|
// o.stop(time);
|
||||||
},
|
},
|
||||||
triggerRelease: (time) => {
|
triggerRelease: (time) => {
|
||||||
// envGain?.stop(time);
|
// envGain?.stop(time);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
},
|
||||||
|
{ type: 'synth', prebake: true },
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
[...noises].forEach((s) => {
|
[...noises].forEach((s) => {
|
||||||
|
|||||||
@ -111,29 +111,6 @@ class DistortProcessor extends AudioWorkletProcessor {
|
|||||||
|
|
||||||
registerProcessor('distort-processor', DistortProcessor);
|
registerProcessor('distort-processor', DistortProcessor);
|
||||||
|
|
||||||
// class SupersawProcessor extends AudioWorkletProcessor {
|
|
||||||
// static get parameterDescriptors() {
|
|
||||||
// return [
|
|
||||||
// { name: 'distort', defaultValue: 0 },
|
|
||||||
// { name: 'postgain', defaultValue: 1 },
|
|
||||||
// ];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// constructor() {
|
|
||||||
// super();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// process(inputs, outputs, parameters) {
|
|
||||||
// const output = outputs[0];
|
|
||||||
// let saw = (x, t) => ((x * t % 1) - 0.5) * 2
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// registerProcessor('supersaw-processor', SupersawProcessor);
|
|
||||||
|
|
||||||
const saw = (v) => v - Math.floor(v);
|
|
||||||
const twoPI = Math.PI * 2;
|
|
||||||
const polyBlep = (t, dt) => {
|
const polyBlep = (t, dt) => {
|
||||||
// 0 <= t < 1
|
// 0 <= t < 1
|
||||||
if (t < dt) {
|
if (t < dt) {
|
||||||
@ -155,25 +132,6 @@ const polyBlep = (t, dt) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const inc = () => {
|
|
||||||
t += freqInSecondsPerSample;
|
|
||||||
t -= bitwiseOrZero(t);
|
|
||||||
};
|
|
||||||
|
|
||||||
const square_number = (x) => {
|
|
||||||
return x * x;
|
|
||||||
};
|
|
||||||
|
|
||||||
const blep = (t, dt) => {
|
|
||||||
if (t < dt) {
|
|
||||||
return -square_number(t / dt - 1);
|
|
||||||
} else if (t > 1 - dt) {
|
|
||||||
return square_number((t - 1) / dt + 1);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const polySaw = (t, dt) => {
|
const polySaw = (t, dt) => {
|
||||||
// Correct phase, so it would be in line with sin(2.*M_PI * t)
|
// Correct phase, so it would be in line with sin(2.*M_PI * t)
|
||||||
t += 0.5;
|
t += 0.5;
|
||||||
@ -184,8 +142,6 @@ const polySaw = (t, dt) => {
|
|||||||
// return naive_saw;
|
// return naive_saw;
|
||||||
};
|
};
|
||||||
|
|
||||||
const saw2 = (x, t) => (((x * t) % 1) - 0.5) * 2;
|
|
||||||
|
|
||||||
class BetterOscillatorProcessor extends AudioWorkletProcessor {
|
class BetterOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -252,9 +208,6 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
const output = outputs[0];
|
const output = outputs[0];
|
||||||
|
|
||||||
for (let i = 0; i < output[0].length; i++) {
|
for (let i = 0; i < output[0].length; i++) {
|
||||||
// const blep = polyBlep(this.phase, frequency / sampleRate);
|
|
||||||
// console.log(blep);
|
|
||||||
// const out = saw2(frequency, this.phase / sampleRate);
|
|
||||||
const out = polySaw(this.phase, frequency / sampleRate);
|
const out = polySaw(this.phase, frequency / sampleRate);
|
||||||
output[0][i] = out;
|
output[0][i] = out;
|
||||||
|
|
||||||
@ -264,16 +217,6 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor {
|
|||||||
this.phase = this.phase - 1;
|
this.phase = this.phase - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (let i = 0; i < outlen; x++) {
|
|
||||||
// const val = saw2(frequency, this.phase)
|
|
||||||
// // out[x] = 2 * saw(dt + this.phase) - 1;
|
|
||||||
// // out[x] = polySaw(this.phase, dt);
|
|
||||||
// }
|
|
||||||
// this.phase = this.phase + dt * outlen;
|
|
||||||
|
|
||||||
// this.phase %= sampleRate;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// for (let z = 0; z < outputs.length; z++) {
|
// for (let z = 0; z < outputs.length; z++) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user