@audio/synth-voice 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/audio.d.ts +3 -1
- package/audio.js +3 -2
- package/package.json +1 -1
- package/voice.d.ts +2 -0
- package/voice.js +5 -4
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ import voice from '@audio/synth-voice'
|
|
|
13
13
|
Composed voice — [`synth-osc`](https://github.com/audiojs/synth/tree/main/packages/synth-osc) through a one-pole lowpass whose cutoff is scaled by an [`synth-envelope`](https://github.com/audiojs/synth/tree/main/packages/synth-envelope) ADSR, the Tone.js Synth/MonoSynth class. Pitched — `(freq, opts)`.
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
|
-
voice(440, { type: 'sawtooth',
|
|
16
|
+
voice(440, { type: 'sawtooth', fc: 3000, envAmount: 0.6 }) // → Float32Array
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
| Param | Default | |
|
|
@@ -23,7 +23,7 @@ voice(440, { type: 'sawtooth', cutoff: 3000, envAmount: 0.6 }) // → Float32A
|
|
|
23
23
|
| `type` | `'sawtooth'` | Oscillator waveform — see `synth-osc` |
|
|
24
24
|
| `duration` | `0.6` | Note-on length, seconds |
|
|
25
25
|
| `attack` / `decay` / `sustain` / `release` | `0.01` / `0.15` / `0.6` / `0.25` | ADSR, seconds/level |
|
|
26
|
-
| `
|
|
26
|
+
| `fc` | `3000` | Lowpass cutoff at full envelope, Hz (`cutoff` still accepted) |
|
|
27
27
|
| `envAmount` | `0.6` | 0..1 — how much the envelope scales the cutoff |
|
|
28
28
|
| `amp` | `0.7` | Peak amplitude |
|
|
29
29
|
|
package/audio.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface VoiceOptions {
|
|
|
21
21
|
/** 0.001..4 s (default 0.25) */
|
|
22
22
|
"release"?: Auto
|
|
23
23
|
/** 100..16000 Hz (default 3000) */
|
|
24
|
+
"fc"?: Auto
|
|
25
|
+
/** @deprecated former name of "fc" */
|
|
24
26
|
"cutoff"?: Auto
|
|
25
27
|
/** 0..1 (default 0.6) */
|
|
26
28
|
"envAmount"?: Auto
|
|
@@ -46,7 +48,7 @@ export declare const voice: {
|
|
|
46
48
|
/** 0.001..4 s (default 0.25) */
|
|
47
49
|
"release": { type: "number", default: 0.25 }
|
|
48
50
|
/** 100..16000 Hz (default 3000) */
|
|
49
|
-
"
|
|
51
|
+
"fc": { type: "number", default: 3000, alias: "cutoff" }
|
|
50
52
|
/** 0..1 (default 0.6) */
|
|
51
53
|
"envAmount": { type: "number", default: 0.6 }
|
|
52
54
|
/** 0..1 (default 0.7) */
|
package/audio.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// @audio/synth-poly for allocation).
|
|
7
7
|
|
|
8
8
|
import voiceFn from './voice.js'
|
|
9
|
+
import { midiToHz } from '@audio/note'
|
|
9
10
|
|
|
10
11
|
export const voice = (ctx) => {
|
|
11
12
|
return (inputs, outputs, params) => {
|
|
@@ -25,7 +26,7 @@ export const voice = (ctx) => {
|
|
|
25
26
|
type: params.type,
|
|
26
27
|
attack: params.attack[0], decay: params.decay[0],
|
|
27
28
|
sustain: params.sustain[0], release: params.release[0],
|
|
28
|
-
|
|
29
|
+
fc: params.fc[0], envAmount: params.envAmount[0],
|
|
29
30
|
amp: params.amp[0] * (slot.velocity ?? 1),
|
|
30
31
|
})
|
|
31
32
|
for (let i = 0; i < d.length && slot.time + i < n; i++) o0[slot.time + i] += d[i]
|
|
@@ -48,7 +49,7 @@ voice.params = {
|
|
|
48
49
|
decay: { type: 'number', min: 0.001, max: 2, default: 0.15, unit: 's', curve: 'log' },
|
|
49
50
|
sustain: { type: 'number', min: 0, max: 1, default: 0.6 },
|
|
50
51
|
release: { type: 'number', min: 0.001, max: 4, default: 0.25, unit: 's', curve: 'log' },
|
|
51
|
-
|
|
52
|
+
fc: { type: 'number', min: 100, max: 16000, default: 3000, unit: 'Hz', curve: 'log', alias: 'cutoff' },
|
|
52
53
|
envAmount: { type: 'number', min: 0, max: 1, default: 0.6 },
|
|
53
54
|
amp: { type: 'number', min: 0, max: 1, default: 0.7 },
|
|
54
55
|
}
|
package/package.json
CHANGED
package/voice.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface VoiceOptions {
|
|
|
15
15
|
/** seconds, default 0.25 */
|
|
16
16
|
release?: number
|
|
17
17
|
/** lowpass cutoff at full envelope, Hz, default 3000 */
|
|
18
|
+
fc?: number
|
|
19
|
+
/** @deprecated former name of `fc` */
|
|
18
20
|
cutoff?: number
|
|
19
21
|
/** 0..1, how much the envelope scales the cutoff, default 0.6 */
|
|
20
22
|
envAmount?: number
|
package/voice.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
// Synth voice — oscillator × ADSR envelope through a one-pole lowpass with envelope-scaled
|
|
2
|
-
// cutoff (Tone.js Synth/MonoSynth class), composed from @audio/synth-osc + synth-envelope.
|
|
2
|
+
// cutoff `fc` (Tone.js Synth/MonoSynth class), composed from @audio/synth-osc + synth-envelope.
|
|
3
3
|
|
|
4
4
|
import osc from '@audio/synth-osc'
|
|
5
5
|
import adsr from '@audio/synth-envelope'
|
|
6
6
|
|
|
7
7
|
export default function voice (freq, { fs = 44100, type = 'sawtooth', duration = 0.6,
|
|
8
8
|
attack = 0.01, decay = 0.15, sustain = 0.6, release = 0.25,
|
|
9
|
-
cutoff
|
|
9
|
+
fc, cutoff, envAmount = 0.6, amp = 0.7 } = {}) {
|
|
10
|
+
fc ??= cutoff ?? 3000 // `cutoff`: former name
|
|
10
11
|
let env = adsr({ attack, decay, sustain, release, duration, fs })
|
|
11
12
|
let src = osc(freq, { duration: env.length / fs, fs, type, amp: 1 })
|
|
12
13
|
let out = new Float32Array(env.length)
|
|
13
14
|
let lp = 0
|
|
14
15
|
for (let i = 0; i < env.length; i++) {
|
|
15
|
-
let
|
|
16
|
-
let a = Math.exp(-2 * Math.PI *
|
|
16
|
+
let f = fc * (1 - envAmount + envAmount * env[i])
|
|
17
|
+
let a = Math.exp(-2 * Math.PI * f / fs)
|
|
17
18
|
lp = src[i] * env[i] * (1 - a) + lp * a
|
|
18
19
|
out[i] = amp * lp
|
|
19
20
|
}
|