@audio/synth-voice 1.1.1 → 1.1.3
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 +36 -0
- package/audio.js +1 -1
- package/package.json +12 -3
- package/voice.d.ts +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @audio/synth-voice [](https://www.npmjs.com/package/@audio/synth-voice) [](https://github.com/krishnized/license)
|
|
2
|
+
|
|
3
|
+
Osc + envelope voice (Tone.js Synth class)
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @audio/synth-voice
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import voice from '@audio/synth-voice'
|
|
11
|
+
```
|
|
12
|
+
|
|
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
|
+
|
|
15
|
+
```js
|
|
16
|
+
voice(440, { type: 'sawtooth', cutoff: 3000, envAmount: 0.6 }) // → Float32Array
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
| Param | Default | |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `freq` | — | Hz (positional) |
|
|
22
|
+
| `fs` | `44100` | Sample rate |
|
|
23
|
+
| `type` | `'sawtooth'` | Oscillator waveform — see `synth-osc` |
|
|
24
|
+
| `duration` | `0.6` | Note-on length, seconds |
|
|
25
|
+
| `attack` / `decay` / `sustain` / `release` | `0.01` / `0.15` / `0.6` / `0.25` | ADSR, seconds/level |
|
|
26
|
+
| `cutoff` | `3000` | Lowpass cutoff at full envelope, Hz |
|
|
27
|
+
| `envAmount` | `0.6` | 0..1 — how much the envelope scales the cutoff |
|
|
28
|
+
| `amp` | `0.7` | Peak amplitude |
|
|
29
|
+
|
|
30
|
+
**Use when:** a ready-made subtractive voice for `synth-poly`, without composing osc+envelope+filter by hand.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
Part of [@audio/synth](https://github.com/audiojs/synth) — the synth family umbrella.
|
|
35
|
+
|
|
36
|
+
MIT © [audiojs](https://github.com/audiojs)
|
package/audio.js
CHANGED
|
@@ -18,7 +18,7 @@ export const voice = (ctx) => {
|
|
|
18
18
|
const evs = ctx.events || []
|
|
19
19
|
const on = new Map()
|
|
20
20
|
const render = (slot, endSample) => {
|
|
21
|
-
const freq =
|
|
21
|
+
const freq = midiToHz(slot.pitch)
|
|
22
22
|
const dur = Math.max(0.01, (endSample - slot.time) / sr)
|
|
23
23
|
const d = voiceFn(freq, {
|
|
24
24
|
fs: sr, duration: dur,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/synth-voice",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Synth voice — osc × ADSR through envelope-scaled lowpass (Tone.js Synth class)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,12 +15,15 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"voice.js",
|
|
18
|
+
"voice.d.ts",
|
|
18
19
|
"audio.js",
|
|
19
20
|
"audio.d.ts"
|
|
20
21
|
],
|
|
22
|
+
"types": "voice.d.ts",
|
|
21
23
|
"dependencies": {
|
|
22
24
|
"@audio/synth-osc": "^1.0.0",
|
|
23
|
-
"@audio/synth-envelope": "^1.0.0"
|
|
25
|
+
"@audio/synth-envelope": "^1.0.0",
|
|
26
|
+
"@audio/note": "^1.0.0"
|
|
24
27
|
},
|
|
25
28
|
"keywords": [
|
|
26
29
|
"audio",
|
|
@@ -36,5 +39,11 @@
|
|
|
36
39
|
"publishConfig": {
|
|
37
40
|
"access": "public"
|
|
38
41
|
},
|
|
39
|
-
"audio": "./audio.js"
|
|
42
|
+
"audio": "./audio.js",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/audiojs/synth.git",
|
|
46
|
+
"directory": "packages/synth-voice"
|
|
47
|
+
},
|
|
48
|
+
"funding": "https://github.com/sponsors/audiojs"
|
|
40
49
|
}
|
package/voice.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Osc + envelope voice — one-pole lowpass with envelope-scaled cutoff (Tone.js Synth/MonoSynth class). */
|
|
2
|
+
export interface VoiceOptions {
|
|
3
|
+
/** sample rate, default 44100 */
|
|
4
|
+
fs?: number
|
|
5
|
+
/** oscillator waveform, default 'sawtooth' */
|
|
6
|
+
type?: 'sine' | 'square' | 'sawtooth' | 'triangle'
|
|
7
|
+
/** note-on length, seconds, default 0.6 */
|
|
8
|
+
duration?: number
|
|
9
|
+
/** seconds, default 0.01 */
|
|
10
|
+
attack?: number
|
|
11
|
+
/** seconds, default 0.15 */
|
|
12
|
+
decay?: number
|
|
13
|
+
/** sustain level 0..1, default 0.6 */
|
|
14
|
+
sustain?: number
|
|
15
|
+
/** seconds, default 0.25 */
|
|
16
|
+
release?: number
|
|
17
|
+
/** lowpass cutoff at full envelope, Hz, default 3000 */
|
|
18
|
+
cutoff?: number
|
|
19
|
+
/** 0..1, how much the envelope scales the cutoff, default 0.6 */
|
|
20
|
+
envAmount?: number
|
|
21
|
+
/** peak amplitude, default 0.7 */
|
|
22
|
+
amp?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** freq: Hz (positional) */
|
|
26
|
+
export default function voice(freq: number, options?: VoiceOptions): Float32Array
|