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);
};
const waveforms = ['sine', 'square', 'triangle', 'sawtooth'];
const waveforms = ['triangle', 'square', 'sawtooth', 'sine'];
const noises = ['pink', 'white', 'brown', 'crackle'];
export function registerSynthSounds() {
registerSound('bet', (begin, value, onended) => {
[...waveforms].forEach((s, i) => {
registerSound(s, (begin, value, onended) => {
const ac = getAudioContext();
let { note, freq, duration } = value;
note = note || 36;
@ -49,12 +50,12 @@ export function registerSynthSounds() {
const holdend = begin + duration;
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);
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 {
node,
@ -66,8 +67,9 @@ export function registerSynthSounds() {
},
};
});
});
[...waveforms, ...noises].forEach((s) => {
[...noises].forEach((s) => {
registerSound(
s,
(t, value, onended) => {
@ -78,12 +80,9 @@ export function registerSynthSounds() {
);
let sound;
if (waveforms.includes(s)) {
sound = getOscillator(s, t, value);
} else {
let { density } = value;
sound = getNoiseOscillator(s, t, density);
}
let { node: o, stop, triggerRelease } = sound;