rename some params + use correct duration

This commit is contained in:
Felix Roos 2023-08-31 06:57:08 +02:00
parent a786c642f1
commit 0f54bb1938
3 changed files with 40 additions and 40 deletions

View file

@ -804,25 +804,17 @@ const generic_params = [
['clip'], ['clip'],
// ZZFX // ZZFX
//['volume'], ['zrand'],
['randomness'],
// ['frequency'], => freq
/* ['attack'],
['decay'],
['sustain'],
['release'], */
// ['shape'], // duplicate
['shapeCurve'], ['shapeCurve'],
// ['slide'], // superdirt duplicate ['slide'], // superdirt duplicate
['deltaSlide'], ['deltaSlide'],
['pitchJump'], ['pitchJump'],
['pitchJumpTime'], ['pitchJumpTime'],
['repeatTime'], ['repeatTime'],
['noise'], ['noise'],
['modulation'], ['zmod'],
['bitCrush'], // like crush.. ['zcrush'], // like crush..
//['delay'], // duplicate ['zdelay'], // duplicate
// ['sustainVolume'], // not needed?
['tremolo'], ['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

View file

@ -167,6 +167,8 @@ export const superdough = async (value, deadline, hapDuration) => {
); );
} }
// duration is passed as value too..
value.duration = hapDuration;
// calculate absolute time // calculate absolute time
let t = ac.currentTime + deadline; let t = ac.currentTime + deadline;
// destructure // destructure

View file

@ -2,13 +2,13 @@
import { midiToFreq, noteToMidi } from './util.mjs'; import { midiToFreq, noteToMidi } from './util.mjs';
import { registerSound, getAudioContext } from './superdough.mjs'; import { registerSound, getAudioContext } from './superdough.mjs';
export const getZZFX = (value, t, duration) => { export const getZZFX = (value, t) => {
let { let {
s, s,
note = 36, note = 36,
freq, freq,
// //
randomness = 0, zrand = 0,
attack = 0, attack = 0,
decay = 0, decay = 0,
sustain = 0.8, sustain = 0.8,
@ -21,10 +21,12 @@ export const getZZFX = (value, t, duration) => {
repeatTime = 0, repeatTime = 0,
noise = 0, noise = 0,
modulation = 0, modulation = 0,
bitCrush = 0, zcrush = 0,
delay = 0, zdelay = 0,
tremolo = 0, tremolo = 0,
duration = 0.2,
} = value; } = value;
const sustainTime = Math.max(duration - attack - decay, 0);
if (typeof note === 'string') { if (typeof note === 'string') {
note = noteToMidi(note); // e.g. c3 => 48 note = noteToMidi(note); // e.g. c3 => 48
} }
@ -32,14 +34,16 @@ export const getZZFX = (value, t, duration) => {
if (!freq && typeof note === 'number') { if (!freq && typeof note === 'number') {
freq = midiToFreq(note); freq = midiToFreq(note);
} }
const shape = ['zsine', 'ztri', 'zsaw', 'ztan', 'znoise'].indexOf(s) || 0; s = s.replace('z_', '');
const shape = ['sine', 'triangle', 'sawtooth', 'tan', 'noise'].indexOf(s) || 0;
shapeCurve = s === 'square' ? 0 : shapeCurve;
const params = [ const params = [
1, // volume 0.25, // volume
randomness, // randomness zrand,
freq, freq,
attack, attack,
duration, // sustain time sustainTime,
release, release,
shape, shape,
shapeCurve, shapeCurve,
@ -50,8 +54,8 @@ export const getZZFX = (value, t, duration) => {
repeatTime, repeatTime,
noise, noise,
modulation, modulation,
bitCrush, zcrush,
delay, zdelay,
sustain, // sustain volume! sustain, // sustain volume!
decay, decay,
tremolo, tremolo,
@ -71,20 +75,22 @@ export const getZZFX = (value, t, duration) => {
}; };
export function registerZZFXSounds() { export function registerZZFXSounds() {
console.log('registerZZFXSounds'); ['z_sine', 'z_sawtooth', 'z_triangle', 'z_square', 'z_tan', 'z_noise'].forEach((wave) => {
['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => { registerSound(
registerSound(wave, (t, value, onended) => { wave,
const duration = 0.3; (t, value, onended) => {
const { node: o } = getZZFX({ s: wave, ...value }, t, duration); const { node: o } = getZZFX({ s: wave, ...value }, t);
o.onended = () => { o.onended = () => {
o.disconnect(); o.disconnect();
onended(); onended();
}; };
return { return {
node: o, node: o,
stop: () => {}, stop: () => {},
}; };
}); },
{ type: 'synth', prebake: true },
);
}); });
} }
@ -92,7 +98,7 @@ export function registerZZFXSounds() {
function redableZZFX(params) { function redableZZFX(params) {
const paramOrder = [ const paramOrder = [
'volume', 'volume',
'randomness', 'zrand',
'frequency', 'frequency',
'attack', 'attack',
'sustain', 'sustain',
@ -106,8 +112,8 @@ function redableZZFX(params) {
'repeatTime', 'repeatTime',
'noise', 'noise',
'modulation', 'modulation',
'bitCrush', 'zcrush',
'delay', 'zdelay',
'sustainVolume', 'sustainVolume',
'decay', 'decay',
'tremolo', 'tremolo',