This commit is contained in:
Jade (Rose) Rowland 2024-02-29 22:55:56 -05:00
parent 1690030b1d
commit a6f7c57d19

View file

@ -21,11 +21,12 @@ const fm = (osc, harmonicityRatio, modulationIndex, wave = 'sine') => {
return mod(modfreq, modgain, wave); return mod(modfreq, modgain, wave);
}; };
const waveforms = ['sine', 'square', 'triangle', 'sawtooth']; const waveforms = ['triangle', 'square', 'sawtooth', 'sine'];
const noises = ['pink', 'white', 'brown', 'crackle']; const noises = ['pink', 'white', 'brown', 'crackle'];
export function registerSynthSounds() { export function registerSynthSounds() {
registerSound('bet', (begin, value, onended) => { [...waveforms].forEach((s, i) => {
registerSound(s, (begin, value, onended) => {
const ac = getAudioContext(); const ac = getAudioContext();
let { note, freq, duration } = value; let { note, freq, duration } = value;
note = note || 36; note = note || 36;
@ -49,12 +50,12 @@ 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, 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, 1, begin, holdend, 'exponential'); getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.3, begin, holdend, 'linear');
return { return {
node, node,
@ -66,8 +67,9 @@ export function registerSynthSounds() {
}, },
}; };
}); });
});
[...waveforms, ...noises].forEach((s) => { [...noises].forEach((s) => {
registerSound( registerSound(
s, s,
(t, value, onended) => { (t, value, onended) => {
@ -78,12 +80,9 @@ export function registerSynthSounds() {
); );
let sound; let sound;
if (waveforms.includes(s)) {
sound = getOscillator(s, t, value);
} else {
let { density } = value; let { density } = value;
sound = getNoiseOscillator(s, t, density); sound = getNoiseOscillator(s, t, density);
}
let { node: o, stop, triggerRelease } = sound; let { node: o, stop, triggerRelease } = sound;