mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-19 17:48:33 +00:00
adding fm wave choice
This commit is contained in:
parent
02979926fd
commit
ebeaac3c5f
@ -2,7 +2,8 @@ import { midiToFreq, noteToMidi } from './util.mjs';
|
|||||||
import { registerSound, getAudioContext } from './superdough.mjs';
|
import { registerSound, getAudioContext } from './superdough.mjs';
|
||||||
import { getOscillator, gainNode, getEnvelope } from './helpers.mjs';
|
import { getOscillator, gainNode, getEnvelope } from './helpers.mjs';
|
||||||
|
|
||||||
const mod = (freq, range = 1, type = 'sine') => {
|
const mod = (freq, range = 1, type) => {
|
||||||
|
console.log(type)
|
||||||
const ctx = getAudioContext();
|
const ctx = getAudioContext();
|
||||||
const osc = ctx.createOscillator();
|
const osc = ctx.createOscillator();
|
||||||
osc.type = type;
|
osc.type = type;
|
||||||
@ -13,7 +14,7 @@ const mod = (freq, range = 1, type = 'sine') => {
|
|||||||
return { node: g, stop: (t) => osc.stop(t) };
|
return { node: g, stop: (t) => osc.stop(t) };
|
||||||
};
|
};
|
||||||
|
|
||||||
const fm = (osc, harmonicityRatio, modulationIndex, wave = 'sine') => {
|
const fm = (osc, harmonicityRatio, modulationIndex, wave) => {
|
||||||
const carrfreq = osc.frequency.value;
|
const carrfreq = osc.frequency.value;
|
||||||
const modfreq = carrfreq * harmonicityRatio;
|
const modfreq = carrfreq * harmonicityRatio;
|
||||||
const modgain = modfreq * modulationIndex;
|
const modgain = modfreq * modulationIndex;
|
||||||
@ -33,6 +34,7 @@ export function registerSynthSounds() {
|
|||||||
release = 0.01,
|
release = 0.01,
|
||||||
fmh: fmHarmonicity = 1,
|
fmh: fmHarmonicity = 1,
|
||||||
fmi: fmModulationIndex,
|
fmi: fmModulationIndex,
|
||||||
|
fmwave: fmWaveform = 'sine'
|
||||||
} = 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
|
||||||
@ -50,7 +52,11 @@ export function registerSynthSounds() {
|
|||||||
|
|
||||||
let stopFm;
|
let stopFm;
|
||||||
if (fmModulationIndex) {
|
if (fmModulationIndex) {
|
||||||
const { node: modulator, stop } = fm(o, fmHarmonicity, fmModulationIndex);
|
const { node: modulator, stop } = fm(
|
||||||
|
o, fmHarmonicity,
|
||||||
|
fmModulationIndex,
|
||||||
|
fmWaveform
|
||||||
|
);
|
||||||
modulator.connect(o.frequency);
|
modulator.connect(o.frequency);
|
||||||
stopFm = stop;
|
stopFm = stop;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user