mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
more zzfx wiring
This commit is contained in:
parent
c3f27d1ad9
commit
afb8ab44cf
@ -802,8 +802,29 @@ const generic_params = [
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
['clip'],
|
['clip'],
|
||||||
];
|
|
||||||
|
|
||||||
|
// ZZFX
|
||||||
|
//['volume'],
|
||||||
|
['randomness'],
|
||||||
|
// ['frequency'], => freq
|
||||||
|
/* ['attack'],
|
||||||
|
['decay'],
|
||||||
|
['sustain'],
|
||||||
|
['release'], */
|
||||||
|
// ['shape'], // duplicate
|
||||||
|
['shapeCurve'],
|
||||||
|
// ['slide'], // superdirt duplicate
|
||||||
|
['deltaSlide'],
|
||||||
|
['pitchJump'],
|
||||||
|
['pitchJumpTime'],
|
||||||
|
['repeatTime'],
|
||||||
|
['noise'],
|
||||||
|
['modulation'],
|
||||||
|
['bitCrush'], // like crush..
|
||||||
|
//['delay'], // duplicate
|
||||||
|
// ['sustainVolume'], // not needed?
|
||||||
|
['tremolo'],
|
||||||
|
];
|
||||||
// TODO: slice / splice https://www.youtube.com/watch?v=hKhPdO0RKDQ&list=PL2lW1zNIIwj3bDkh-Y3LUGDuRcoUigoDs&index=13
|
// TODO: slice / splice https://www.youtube.com/watch?v=hKhPdO0RKDQ&list=PL2lW1zNIIwj3bDkh-Y3LUGDuRcoUigoDs&index=13
|
||||||
|
|
||||||
controls.createParam = function (names) {
|
controls.createParam = function (names) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { getAudioContext } from './superdough.mjs';
|
import { getAudioContext } from './superdough.mjs';
|
||||||
import * as zzfx from 'zzfx';
|
import { ZZFX } from 'zzfx';
|
||||||
|
|
||||||
export function gainNode(value) {
|
export function gainNode(value) {
|
||||||
const node = getAudioContext().createGain();
|
const node = getAudioContext().createGain();
|
||||||
@ -7,27 +7,97 @@ export function gainNode(value) {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getZZFX = ({ wave, freq, t, params}) => {
|
export const getZZFX = (value, t, duration) => {
|
||||||
params.frequency = freq;
|
let {
|
||||||
params.shape = {
|
s,
|
||||||
'zsine': 0,
|
note = 36,
|
||||||
'ztri': 1,
|
freq,
|
||||||
'zsaw': 2,
|
//
|
||||||
'ztan': 3,
|
randomness = 0,
|
||||||
'znoise': 4,
|
attack = 0,
|
||||||
}[wave];
|
decay = 0,
|
||||||
const samples = zzfx.buildSamples(...params);
|
sustain = 0.8,
|
||||||
|
release = 0.1,
|
||||||
|
shapeCurve = 1,
|
||||||
|
slide = 0,
|
||||||
|
deltaSlide = 0,
|
||||||
|
pitchJump = 0,
|
||||||
|
pitchJumpTime = 0,
|
||||||
|
repeatTime = 0,
|
||||||
|
noise = 0,
|
||||||
|
modulation = 0,
|
||||||
|
bitCrush = 0,
|
||||||
|
delay = 0,
|
||||||
|
tremolo = 0,
|
||||||
|
} = value;
|
||||||
|
if (typeof note === 'string') {
|
||||||
|
note = noteToMidi(note); // e.g. c3 => 48
|
||||||
|
}
|
||||||
|
// get frequency
|
||||||
|
if (!freq && typeof n === 'number') {
|
||||||
|
freq = midiToFreq(n);
|
||||||
|
}
|
||||||
|
const shape = ['zsine', 'ztri', 'zsaw', 'ztan', 'znoise'].indexOf(s) || 0;
|
||||||
|
|
||||||
|
const params = [
|
||||||
|
1, // volume
|
||||||
|
randomness, // randomness
|
||||||
|
freq,
|
||||||
|
attack,
|
||||||
|
duration, // sustain time
|
||||||
|
release,
|
||||||
|
shape,
|
||||||
|
shapeCurve,
|
||||||
|
slide,
|
||||||
|
deltaSlide,
|
||||||
|
pitchJump,
|
||||||
|
pitchJumpTime,
|
||||||
|
repeatTime,
|
||||||
|
noise,
|
||||||
|
modulation,
|
||||||
|
bitCrush,
|
||||||
|
delay,
|
||||||
|
sustain, // sustain volume!
|
||||||
|
decay,
|
||||||
|
tremolo,
|
||||||
|
];
|
||||||
|
const paramOrder = [
|
||||||
|
'volume',
|
||||||
|
'randomness',
|
||||||
|
'frequency',
|
||||||
|
'attack',
|
||||||
|
'sustain',
|
||||||
|
'release',
|
||||||
|
'shape',
|
||||||
|
'shapeCurve',
|
||||||
|
'slide',
|
||||||
|
'deltaSlide',
|
||||||
|
'pitchJump',
|
||||||
|
'pitchJumpTime',
|
||||||
|
'repeatTime',
|
||||||
|
'noise',
|
||||||
|
'modulation',
|
||||||
|
'bitCrush',
|
||||||
|
'delay',
|
||||||
|
'sustainVolume',
|
||||||
|
'decay',
|
||||||
|
'tremolo',
|
||||||
|
];
|
||||||
|
|
||||||
|
const readableParams = Object.fromEntries(paramOrder.map((param, i) => [param, params[i]]));
|
||||||
|
console.log(readableParams);
|
||||||
|
|
||||||
|
const samples = ZZFX.buildSamples(...params);
|
||||||
const context = getAudioContext();
|
const context = getAudioContext();
|
||||||
const buffer = context.createBuffer(
|
const buffer = context.createBuffer(1, samples.length, context.sampleRate);
|
||||||
samples.length,
|
buffer.getChannelData(0).set(samples);
|
||||||
samples[0].length,
|
const source = getAudioContext().createBufferSource();
|
||||||
context.sampleRate
|
source.buffer = buffer;
|
||||||
);
|
source.start(t);
|
||||||
const source = context.createBufferSource();
|
|
||||||
return {
|
return {
|
||||||
node: source,
|
node: source,
|
||||||
stop: (time) => source.stop(time), buffer}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getOscillator = ({ s, freq, t }) => {
|
export const getOscillator = ({ s, freq, t }) => {
|
||||||
// make oscillator
|
// make oscillator
|
||||||
|
|||||||
@ -22,45 +22,18 @@ const fm = (osc, harmonicityRatio, modulationIndex, wave = 'sine') => {
|
|||||||
|
|
||||||
export function registerSynthSounds() {
|
export function registerSynthSounds() {
|
||||||
['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => {
|
['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => {
|
||||||
registerSound(
|
registerSound(wave, (t, value, onended) => {
|
||||||
wave,
|
const duration = 0.2;
|
||||||
(t, value, onended) => {
|
const { node: o } = getZZFX({ s: wave, ...value }, t, duration);
|
||||||
const {
|
o.onended = () => {
|
||||||
attack = 0.001,
|
o.disconnect();
|
||||||
decay = 0.05,
|
onended();
|
||||||
sustain = 0.6,
|
};
|
||||||
release = 0.01,
|
return {
|
||||||
} = value;
|
node: o,
|
||||||
let { n, note, freq } = value;
|
stop: () => {},
|
||||||
n = note || n || 36;
|
};
|
||||||
if (typeof n === 'string') {
|
});
|
||||||
n = noteToMidi(n); // e.g. c3 => 48
|
|
||||||
}
|
|
||||||
// get frequency
|
|
||||||
if (!freq && typeof n === 'number') {
|
|
||||||
freq = midiToFreq(n); // + 48);
|
|
||||||
}
|
|
||||||
const params = {};
|
|
||||||
const { node: o, stop } = getZZFX({ wave, freq, t, params });
|
|
||||||
const g = gainNode(0.3);
|
|
||||||
// envelope
|
|
||||||
const { node: envelope, stop: releaseEnvelope } = getEnvelope(attack, decay, sustain, release, 1, t);
|
|
||||||
o.onended = () => {
|
|
||||||
o.disconnect();
|
|
||||||
g.disconnect();
|
|
||||||
onended();
|
|
||||||
};
|
|
||||||
console.log(o)
|
|
||||||
return {
|
|
||||||
node: o.connect(g).connect(envelope),
|
|
||||||
stop: (releaseTime) => {
|
|
||||||
releaseEnvelope(releaseTime);
|
|
||||||
let end = releaseTime + release;
|
|
||||||
stop(end);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => {
|
['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user