Skip to content

Commit

Permalink
Merge pull request #767 from ilesinge/document_adsr
Browse files Browse the repository at this point in the history
Document adsr function
  • Loading branch information
felixroos authored Nov 1, 2023
2 parents 158fa85 + 2633f4f commit 16bb920
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/controls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,17 @@ generic_params.forEach(([names, ...aliases]) => {
controls.createParams = (...names) =>
names.reduce((acc, name) => Object.assign(acc, { [name]: controls.createParam(name) }), {});

/**
* ADSR envelope: Combination of Attack, Decay, Sustain, and Release.
*
* @name adsr
* @param {number | Pattern} time attack time in seconds
* @param {number | Pattern} time decay time in seconds
* @param {number | Pattern} gain sustain level (0 to 1)
* @param {number | Pattern} time release time in seconds
* @example
* note("<c3 bb2 f3 eb3>").sound("sawtooth").lpf(600).adsr(".1:.1:.5:.2")
*/
controls.adsr = register('adsr', (adsr, pat) => {
adsr = !Array.isArray(adsr) ? [adsr] : adsr;
const [attack, decay, sustain, release] = adsr;
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/examples.test.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,15 @@ exports[`runs examples > example "addVoicings" example index 0 1`] = `
]
`;

exports[`runs examples > example "adsr" example index 0 1`] = `
[
"[ 0/1 → 1/1 | note:c3 s:sawtooth cutoff:600 ]",
"[ 1/1 → 2/1 | note:bb2 s:sawtooth cutoff:600 ]",
"[ 2/1 → 3/1 | note:f3 s:sawtooth cutoff:600 ]",
"[ 3/1 → 4/1 | note:eb3 s:sawtooth cutoff:600 ]",
]
`;

exports[`runs examples > example "almostAlways" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:hh speed:0.5 ]",
Expand Down
4 changes: 4 additions & 0 deletions website/src/pages/learn/effects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Strudel uses ADSR envelopes, which are probably the most common way to describe

<JsDoc client:idle name="release" h={0} />

## adsr

<JsDoc client:idle name="adsr" h={0} />

# Filter Envelope

Each filter can receive an additional filter envelope controlling the cutoff value dynamically. It uses an ADSR envelope similar to the one used for amplitude. There is an additional parameter to control the depth of the filter modulation: `lpenv`|`hpenv`|`bpenv`. This allows you to play subtle or huge filter modulations just the same by only increasing or decreasing the depth.
Expand Down

0 comments on commit 16bb920

Please sign in to comment.