mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 13:38:40 +00:00
Add noise parameter for base oscillators
This commit is contained in:
parent
c2481e460b
commit
389c7be264
@ -45,6 +45,7 @@ export function registerSynthSounds() {
|
|||||||
fmwave: fmWaveform = 'sine',
|
fmwave: fmWaveform = 'sine',
|
||||||
vib = 0,
|
vib = 0,
|
||||||
vibmod = 0.5,
|
vibmod = 0.5,
|
||||||
|
noise = 0,
|
||||||
} = value;
|
} = value;
|
||||||
let { n, note, freq } = value;
|
let { n, note, freq } = value;
|
||||||
// with synths, n and note are the same thing
|
// with synths, n and note are the same thing
|
||||||
@ -65,6 +66,7 @@ export function registerSynthSounds() {
|
|||||||
vib,
|
vib,
|
||||||
vibmod,
|
vibmod,
|
||||||
partials: n,
|
partials: n,
|
||||||
|
noise: noise,
|
||||||
});
|
});
|
||||||
// FM + FM envelope
|
// FM + FM envelope
|
||||||
let stopFm, fmEnvelope;
|
let stopFm, fmEnvelope;
|
||||||
@ -188,8 +190,9 @@ export function getNoiseOscillator({ t, ac, type = 'white' }) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOscillator({ s, freq, t, vib, vibmod, partials }) {
|
export function getOscillator({ s, freq, t, vib, vibmod, partials, noise }) {
|
||||||
// Make oscillator with partial count
|
// Make oscillator with partial count
|
||||||
|
let ac = getAudioContext();
|
||||||
let o;
|
let o;
|
||||||
|
|
||||||
if (['pink', 'white', 'brown'].includes(s)) {
|
if (['pink', 'white', 'brown'].includes(s)) {
|
||||||
@ -221,6 +224,33 @@ export function getOscillator({ s, freq, t, vib, vibmod, partials }) {
|
|||||||
vibrato_oscillator.start(t);
|
vibrato_oscillator.start(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (noise > 0) {
|
||||||
|
// Two gain nodes to set the oscillators to their respective levels
|
||||||
|
let o_gain = ac.createGain();
|
||||||
|
let n_gain = ac.createGain();
|
||||||
|
o_gain.gain.setValueAtTime(1 - noise, ac.currentTime);
|
||||||
|
n_gain.gain.setValueAtTime(noise, ac.currentTime);
|
||||||
|
|
||||||
|
// Instanciating a mixer to blend sources together
|
||||||
|
let mix_gain = ac.createGain();
|
||||||
|
|
||||||
|
// Connecting the main oscillator to the gain node
|
||||||
|
o.connect(o_gain).connect(mix_gain);
|
||||||
|
|
||||||
|
// Instanciating a noise oscillator and connecting
|
||||||
|
const noiseOscillator = getNoiseOscillator({ t: t, ac: ac, type: 'pink' });
|
||||||
|
noiseOscillator.node.connect(n_gain).connect(mix_gain);
|
||||||
|
|
||||||
|
return {
|
||||||
|
node: mix_gain,
|
||||||
|
stop: (time) => {
|
||||||
|
vibrato_oscillator?.stop(time);
|
||||||
|
o.stop(time);
|
||||||
|
noiseOscillator.stop(time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
node: o,
|
node: o,
|
||||||
stop: (time) => {
|
stop: (time) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user