mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 05:28:41 +00:00
working
This commit is contained in:
parent
8d02d4270a
commit
38908baccd
@ -458,6 +458,49 @@ export const { drive } = registerControl('drive');
|
|||||||
*/
|
*/
|
||||||
export const { channels, ch } = registerControl('channels', 'ch');
|
export const { channels, ch } = registerControl('channels', 'ch');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* controls the pulsewidth of the pulse oscillator
|
||||||
|
*
|
||||||
|
* @name pw
|
||||||
|
* @param {number | Pattern} pulsewidth
|
||||||
|
* @example
|
||||||
|
* note("{f a c e}%16").s("pulse").pw(".8:1:.2")
|
||||||
|
* @example
|
||||||
|
* n(run(8)).scale("D:pentatonic").s("pulse").pw("0 .75 .5 1")
|
||||||
|
*/
|
||||||
|
export const { pw } = registerControl(
|
||||||
|
['pw', 'pwrate', 'pwsweep'],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* controls the lfo rate for the pulsewidth of the pulse oscillator
|
||||||
|
*
|
||||||
|
* @name pwrate
|
||||||
|
* @param {number | Pattern} rate
|
||||||
|
* @example
|
||||||
|
* n(run(8)).scale("D:pentatonic").s("pulse").pw("0.5").pwrate("<5 .1 25>").pwsweep("<0.3 .8>")
|
||||||
|
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const { pwrate } = registerControl(
|
||||||
|
'pwrate'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* controls the lfo sweep for the pulsewidth of the pulse oscillator
|
||||||
|
*
|
||||||
|
* @name pwsweep
|
||||||
|
* @param {number | Pattern} sweep
|
||||||
|
* @example
|
||||||
|
* n(run(8)).scale("D:pentatonic").s("pulse").pw("0.5").pwrate("<5 .1 25>").pwsweep("<0.3 .8>")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const { pwsweep } = registerControl(
|
||||||
|
'pwsweep'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phaser audio effect that approximates popular guitar pedals.
|
* Phaser audio effect that approximates popular guitar pedals.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -307,16 +307,9 @@ function getDelay(orbit, delaytime, delayfeedback, t) {
|
|||||||
return delays[orbit];
|
return delays[orbit];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPhaser(time, end, frequency = 1, depth = 0.5, centerFrequency = 1000, sweep = 2000) {
|
export function getLfo(audioContext, time, end, properties = {}) {
|
||||||
//gain
|
return getWorklet(audioContext, 'lfo-processor', {
|
||||||
const ac = getAudioContext();
|
frequency: 1,
|
||||||
const lfoGain = ac.createGain();
|
|
||||||
lfoGain.gain.value = sweep * 2;
|
|
||||||
// centerFrequency = centerFrequency * 2;
|
|
||||||
// sweep = sweep * 1.5;
|
|
||||||
|
|
||||||
const lfo = getWorklet(ac, 'lfo-processor', {
|
|
||||||
frequency,
|
|
||||||
depth: 1,
|
depth: 1,
|
||||||
skew: 0,
|
skew: 0,
|
||||||
phaseoffset: 0,
|
phaseoffset: 0,
|
||||||
@ -324,8 +317,13 @@ function getPhaser(time, end, frequency = 1, depth = 0.5, centerFrequency = 1000
|
|||||||
end,
|
end,
|
||||||
shape: 1,
|
shape: 1,
|
||||||
dcoffset: -0.5,
|
dcoffset: -0.5,
|
||||||
|
...properties
|
||||||
});
|
});
|
||||||
lfo.connect(lfoGain);
|
}
|
||||||
|
|
||||||
|
function getPhaser(time, end, frequency = 1, depth = 0.5, centerFrequency = 1000, sweep = 2000) {
|
||||||
|
const ac = getAudioContext();
|
||||||
|
const lfoGain = getLfo(ac, time, end, { frequency, depth: sweep * 2 })
|
||||||
|
|
||||||
//filters
|
//filters
|
||||||
const numStages = 2; //num of filters in series
|
const numStages = 2; //num of filters in series
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { clamp, midiToFreq, noteToMidi } from './util.mjs';
|
import { clamp, midiToFreq, noteToMidi } from './util.mjs';
|
||||||
import { registerSound, getAudioContext } from './superdough.mjs';
|
import { registerSound, getAudioContext, getLfo } from './superdough.mjs';
|
||||||
import {
|
import {
|
||||||
applyFM,
|
applyFM,
|
||||||
gainNode,
|
gainNode,
|
||||||
@ -145,7 +145,20 @@ export function registerSynthSounds() {
|
|||||||
'pulse',
|
'pulse',
|
||||||
(begin, value, onended) => {
|
(begin, value, onended) => {
|
||||||
const ac = getAudioContext();
|
const ac = getAudioContext();
|
||||||
let { duration, n: pulsewidth = 0.5 } = value;
|
let { pwrate, pwsweep } = value;
|
||||||
|
if (pwsweep == null) {
|
||||||
|
if (pwrate != null) {
|
||||||
|
pwsweep = 0.3
|
||||||
|
} else {
|
||||||
|
pwsweep = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pwrate == null && pwsweep != null) {
|
||||||
|
pwrate = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
let { duration, pw: pulsewidth = value.n ?? 0.5, } = value;
|
||||||
const frequency = getFrequencyFromValue(value);
|
const frequency = getFrequencyFromValue(value);
|
||||||
|
|
||||||
const [attack, decay, sustain, release] = getADSRValues(
|
const [attack, decay, sustain, release] = getADSRValues(
|
||||||
@ -153,10 +166,8 @@ export function registerSynthSounds() {
|
|||||||
'linear',
|
'linear',
|
||||||
[0.001, 0.05, 0.6, 0.01],
|
[0.001, 0.05, 0.6, 0.01],
|
||||||
);
|
);
|
||||||
|
|
||||||
const holdend = begin + duration;
|
const holdend = begin + duration;
|
||||||
const end = holdend + release + 0.01;
|
const end = holdend + release + 0.01;
|
||||||
|
|
||||||
let o = getWorklet(
|
let o = getWorklet(
|
||||||
ac,
|
ac,
|
||||||
'pulse-oscillator',
|
'pulse-oscillator',
|
||||||
@ -179,10 +190,16 @@ export function registerSynthSounds() {
|
|||||||
|
|
||||||
getParamADSR(envGain.gain, attack, decay, sustain, release, 0, 1, begin, holdend, 'linear');
|
getParamADSR(envGain.gain, attack, decay, sustain, release, 0, 1, begin, holdend, 'linear');
|
||||||
|
|
||||||
|
|
||||||
|
if (pwsweep != 0) {
|
||||||
|
let lfo = getLfo(ac, begin, end, { frequency: pwrate, depth: pwsweep, })
|
||||||
|
lfo.connect(o.parameters.get('pulsewidth'))
|
||||||
|
}
|
||||||
let timeoutNode = webAudioTimeout(
|
let timeoutNode = webAudioTimeout(
|
||||||
ac,
|
ac,
|
||||||
() => {
|
() => {
|
||||||
destroyAudioWorkletNode(o);
|
destroyAudioWorkletNode(o);
|
||||||
|
destroyAudioWorkletNode(lfo);
|
||||||
envGain.disconnect();
|
envGain.disconnect();
|
||||||
onended();
|
onended();
|
||||||
fm?.stop();
|
fm?.stop();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user