mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
pitch envelope for sampler and soundfonts
+ added getPitchEnvelope helper
This commit is contained in:
parent
bdc2af9733
commit
32456d6966
@ -1,5 +1,11 @@
|
|||||||
import { noteToMidi, freqToMidi, getSoundIndex } from '@strudel.cycles/core';
|
import { noteToMidi, freqToMidi, getSoundIndex } from '@strudel.cycles/core';
|
||||||
import { getAudioContext, registerSound, getParamADSR, getADSRValues } from '@strudel.cycles/webaudio';
|
import {
|
||||||
|
getAudioContext,
|
||||||
|
registerSound,
|
||||||
|
getParamADSR,
|
||||||
|
getADSRValues,
|
||||||
|
getPitchEnvelope,
|
||||||
|
} from '@strudel.cycles/webaudio';
|
||||||
import gm from './gm.mjs';
|
import gm from './gm.mjs';
|
||||||
|
|
||||||
let loadCache = {};
|
let loadCache = {};
|
||||||
@ -149,6 +155,11 @@ export function registerSoundfonts() {
|
|||||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.3, time, holdEnd, 'linear');
|
getParamADSR(node.gain, attack, decay, sustain, release, 0, 0.3, time, holdEnd, 'linear');
|
||||||
let envEnd = holdEnd + release + 0.01;
|
let envEnd = holdEnd + release + 0.01;
|
||||||
|
|
||||||
|
// pitch envelope
|
||||||
|
if (value.penv) {
|
||||||
|
getPitchEnvelope(bufferSource.detune, value, time, holdEnd);
|
||||||
|
}
|
||||||
|
|
||||||
bufferSource.stop(envEnd);
|
bufferSource.stop(envEnd);
|
||||||
const stop = (releaseTime) => {};
|
const stop = (releaseTime) => {};
|
||||||
bufferSource.onended = () => {
|
bufferSource.onended = () => {
|
||||||
|
|||||||
@ -144,3 +144,16 @@ export function drywet(dry, wet, wetAmount = 0) {
|
|||||||
wet_gain.connect(mix);
|
wet_gain.connect(mix);
|
||||||
return mix;
|
return mix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPitchEnvelope(param, value, t, holdEnd) {
|
||||||
|
if (value.penv) {
|
||||||
|
let [pattack, pdecay, psustain, prelease] = getADSRValues([
|
||||||
|
value.pattack,
|
||||||
|
value.pdecay,
|
||||||
|
value.psustain,
|
||||||
|
value.prelease,
|
||||||
|
]);
|
||||||
|
const cents = value.penv * 100;
|
||||||
|
getParamADSR(param, pattack, pdecay, psustain, prelease, 0, cents, t, holdEnd, 'linear');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { noteToMidi, valueToMidi, getSoundIndex } from './util.mjs';
|
import { noteToMidi, valueToMidi, getSoundIndex } from './util.mjs';
|
||||||
import { getAudioContext, registerSound } from './index.mjs';
|
import { getAudioContext, registerSound } from './index.mjs';
|
||||||
import { getADSRValues, getParamADSR } from './helpers.mjs';
|
import { getADSRValues, getParamADSR, getPitchEnvelope } from './helpers.mjs';
|
||||||
import { logger } from './logger.mjs';
|
import { logger } from './logger.mjs';
|
||||||
|
|
||||||
const bufferCache = {}; // string: Promise<ArrayBuffer>
|
const bufferCache = {}; // string: Promise<ArrayBuffer>
|
||||||
@ -310,6 +310,11 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
|
|||||||
|
|
||||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 1, t, holdEnd, 'linear');
|
getParamADSR(node.gain, attack, decay, sustain, release, 0, 1, t, holdEnd, 'linear');
|
||||||
|
|
||||||
|
// pitch envelope
|
||||||
|
if (value.penv) {
|
||||||
|
getPitchEnvelope(bufferSource.detune, value, t, holdEnd);
|
||||||
|
}
|
||||||
|
|
||||||
const out = ac.createGain(); // we need a separate gain for the cutgroups because firefox...
|
const out = ac.createGain(); // we need a separate gain for the cutgroups because firefox...
|
||||||
node.connect(out);
|
node.connect(out);
|
||||||
bufferSource.onended = function () {
|
bufferSource.onended = function () {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { midiToFreq, noteToMidi } from './util.mjs';
|
import { midiToFreq, noteToMidi } from './util.mjs';
|
||||||
import { registerSound, getAudioContext } from './superdough.mjs';
|
import { registerSound, getAudioContext } from './superdough.mjs';
|
||||||
import { gainNode, getADSRValues, getParamADSR } from './helpers.mjs';
|
import { gainNode, getADSRValues, getParamADSR, getPitchEnvelope } from './helpers.mjs';
|
||||||
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
||||||
|
|
||||||
const mod = (freq, range = 1, type = 'sine') => {
|
const mod = (freq, range = 1, type = 'sine') => {
|
||||||
@ -105,10 +105,8 @@ export function waveformN(partials, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// expects one of waveforms as s
|
// expects one of waveforms as s
|
||||||
export function getOscillator(
|
export function getOscillator(s, t, value) {
|
||||||
s,
|
let {
|
||||||
t,
|
|
||||||
{
|
|
||||||
n: partials,
|
n: partials,
|
||||||
note,
|
note,
|
||||||
freq,
|
freq,
|
||||||
@ -126,14 +124,7 @@ export function getOscillator(
|
|||||||
fmvelocity: fmVelocity,
|
fmvelocity: fmVelocity,
|
||||||
fmwave: fmWaveform = 'sine',
|
fmwave: fmWaveform = 'sine',
|
||||||
duration,
|
duration,
|
||||||
penv,
|
} = value;
|
||||||
// panchor = 0, // TODO
|
|
||||||
pattack,
|
|
||||||
pdecay,
|
|
||||||
psustain,
|
|
||||||
prelease,
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
let ac = getAudioContext();
|
let ac = getAudioContext();
|
||||||
let o;
|
let o;
|
||||||
// If no partials are given, use stock waveforms
|
// If no partials are given, use stock waveforms
|
||||||
@ -203,9 +194,9 @@ export function getOscillator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pitch envelope
|
// pitch envelope
|
||||||
if (penv) {
|
if (value.penv) {
|
||||||
const holdEnd = t + duration;
|
const holdEnd = t + duration;
|
||||||
getParamADSR(o.detune, pattack, pdecay, psustain, prelease, 0, penv * 100, t, holdEnd, 'linear');
|
getPitchEnvelope(o.detune, value, t, holdEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
let noiseMix;
|
let noiseMix;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user