mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
add envelope to soundfonts
This commit is contained in:
parent
a33ce67dd4
commit
f788d347ec
@ -1,5 +1,5 @@
|
|||||||
import { toMidi } from '@strudel.cycles/core';
|
import { toMidi } from '@strudel.cycles/core';
|
||||||
import { getAudioContext, registerSound } from '@strudel.cycles/webaudio';
|
import { getAudioContext, registerSound, getEnvelope } from '@strudel.cycles/webaudio';
|
||||||
import { instruments } from './list.mjs';
|
import { instruments } from './list.mjs';
|
||||||
|
|
||||||
let loadCache = {};
|
let loadCache = {};
|
||||||
@ -122,18 +122,22 @@ export function registerSoundfonts() {
|
|||||||
instrument,
|
instrument,
|
||||||
async (time, value, onended) => {
|
async (time, value, onended) => {
|
||||||
const { note, n } = value;
|
const { note, n } = value;
|
||||||
|
const { attack = 0.001, decay = 0.001, sustain = 1, release = 0.001 } = value;
|
||||||
const ctx = getAudioContext();
|
const ctx = getAudioContext();
|
||||||
const bufferSource = await getFontBufferSource(instrument, note || n, ctx);
|
const bufferSource = await getFontBufferSource(instrument, note || n, ctx);
|
||||||
bufferSource.start(time);
|
bufferSource.start(time);
|
||||||
const stop = (time) => bufferSource.stop(time);
|
const { node: envelope, stop: releaseEnvelope } = getEnvelope(attack, decay, sustain, release, 0.3, time);
|
||||||
const g = new GainNode(ctx, { gain: 0.3 });
|
bufferSource.connect(envelope);
|
||||||
bufferSource.connect(g);
|
const stop = (releaseTime) => {
|
||||||
|
bufferSource.stop(releaseTime + release);
|
||||||
|
releaseEnvelope(releaseTime);
|
||||||
|
};
|
||||||
bufferSource.onended = () => {
|
bufferSource.onended = () => {
|
||||||
bufferSource.disconnect();
|
bufferSource.disconnect();
|
||||||
g.disconnect();
|
envelope.disconnect();
|
||||||
onended();
|
onended();
|
||||||
};
|
};
|
||||||
return { node: g, stop };
|
return { node: envelope, stop };
|
||||||
},
|
},
|
||||||
{ type: 'soundfont', prebake: true },
|
{ type: 'soundfont', prebake: true },
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user