@hraness/dawg 0.5.0 → 0.6.1
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/CHANGELOG.md +63 -0
- package/DAWG.md +592 -49
- package/README.md +4 -4
- package/core/chords.ts +492 -4
- package/core/diff.ts +9 -0
- package/core/expression.ts +143 -6
- package/core/fx.ts +689 -2
- package/core/granular.ts +619 -0
- package/core/instruments.ts +442 -0
- package/core/keys.ts +955 -0
- package/core/resonators.ts +862 -0
- package/core/score.ts +529 -8
- package/core/sdk/eval-child.ts +2 -0
- package/core/sdk/print.ts +247 -16
- package/core/sdk/sync-instruments.ts +58 -0
- package/core/sdk/v1.ts +2417 -40
- package/core/sections.ts +44 -10
- package/core/strings.ts +1080 -0
- package/core/winds.ts +652 -0
- package/guides/automation.md +1 -0
- package/guides/chords.md +3 -1
- package/guides/effects.md +5 -2
- package/guides/media.md +1 -1
- package/guides/performance.md +3 -0
- package/guides/resample.md +26 -0
- package/guides/sounds.md +7 -2
- package/guides/tempo.md +1 -0
- package/package.json +1 -1
- package/src/agent/agent.ts +13 -0
- package/src/agent/chord-tools.ts +153 -1
- package/src/agent/expression-tools.ts +91 -0
- package/src/agent/granular-tools.ts +138 -0
- package/src/agent/models.ts +4 -4
- package/src/agent/ops.ts +42 -2
- package/src/agent/preview-tool.ts +7 -1
- package/src/agent/resample-tool.ts +131 -0
- package/src/agent/tools.ts +726 -17
- package/src/agent/xcb-agent.ts +13 -0
- package/src/audio/arrange.ts +42 -3
- package/src/audio/dsp/bank.ts +233 -0
- package/src/audio/dsp/envelope.ts +161 -0
- package/src/audio/dsp/fft.ts +6 -0
- package/src/audio/dsp/filters.ts +57 -0
- package/src/audio/dsp/interp.ts +112 -0
- package/src/audio/dsp/modal.ts +684 -0
- package/src/audio/dsp/onset.ts +197 -0
- package/src/audio/dsp/oversample.ts +202 -0
- package/src/audio/dsp/rng.ts +37 -0
- package/src/audio/dsp/shape.ts +81 -0
- package/src/audio/dsp/shift.ts +256 -0
- package/src/audio/dsp/stft.ts +73 -0
- package/src/audio/dsp/window.ts +77 -0
- package/src/audio/effects/chain.ts +23 -3
- package/src/audio/effects/common.ts +14 -0
- package/src/audio/effects/convolution.ts +106 -1
- package/src/audio/effects/gaze.ts +354 -0
- package/src/audio/effects/rig/cab.ts +99 -0
- package/src/audio/effects/rig/filters.ts +152 -0
- package/src/audio/effects/rig/gate.ts +39 -0
- package/src/audio/effects/rig/head.ts +487 -0
- package/src/audio/effects/rig/index.ts +170 -0
- package/src/audio/effects/rig/section.ts +78 -0
- package/src/audio/effects/rig/stomp.ts +238 -0
- package/src/audio/engine.ts +56 -6
- package/src/audio/fit.ts +447 -0
- package/src/audio/granular.ts +995 -0
- package/src/audio/instrument-check.ts +137 -0
- package/src/audio/instruments.ts +140 -0
- package/src/audio/keys/dsp.ts +323 -0
- package/src/audio/keys/electric.ts +420 -0
- package/src/audio/keys/engine.ts +485 -0
- package/src/audio/keys/organ.ts +1335 -0
- package/src/audio/keys/piano.ts +476 -0
- package/src/audio/keys/sympathetic.ts +127 -0
- package/src/audio/live-worker.ts +56 -0
- package/src/audio/live.ts +361 -15
- package/src/audio/loudness.ts +65 -20
- package/src/audio/preview.ts +17 -1
- package/src/audio/resample.ts +285 -0
- package/src/audio/resonators.ts +295 -0
- package/src/audio/sampler.ts +328 -35
- package/src/audio/samples.ts +56 -8
- package/src/audio/strings/body.ts +263 -0
- package/src/audio/strings/bow.ts +656 -0
- package/src/audio/strings/engine.ts +615 -0
- package/src/audio/strings/loop.ts +119 -0
- package/src/audio/strings/measure.test-helpers.ts +200 -0
- package/src/audio/strings/pluck.ts +354 -0
- package/src/audio/warp.ts +61 -0
- package/src/audio/wav.ts +191 -19
- package/src/audio/winds/engine.ts +302 -0
- package/src/audio/winds/filters.ts +153 -0
- package/src/audio/winds/pitch.ts +104 -0
- package/src/audio/winds/trim.ts +80 -0
- package/src/audio/winds/trims.ts +917 -0
- package/src/audio/winds/voice.ts +479 -0
- package/src/commands/expression.ts +111 -23
- package/src/commands/fit.ts +135 -0
- package/src/commands/fx.ts +35 -1
- package/src/commands/granular.ts +432 -0
- package/src/commands/help.ts +159 -5
- package/src/commands/keys.ts +629 -0
- package/src/commands/modal.ts +310 -0
- package/src/commands/resample.ts +281 -0
- package/src/commands/rig.ts +264 -0
- package/src/commands/sample.ts +52 -2
- package/src/commands/shift.ts +119 -0
- package/src/commands/string.ts +201 -0
- package/src/commands/strum.ts +473 -0
- package/src/commands/time.ts +4 -1
- package/src/commands/wind.ts +244 -0
- package/src/main.ts +339 -15
- package/src/project/check.ts +17 -0
- package/src/render.ts +49 -4
- package/src/session/presence.ts +16 -3
- package/src/tui/audition.ts +2 -2
- package/src/tui/granular-menu.ts +278 -0
- package/src/tui/menu.ts +934 -9
- package/src/tui/modal-menu.ts +145 -0
- package/src/tui/performance-menu.ts +42 -0
- package/src/tui/play-chords.ts +104 -3
- package/src/tui/play-mode.ts +1 -0
- package/src/tui/play-session.ts +70 -2
- package/src/tui/wind-menu.ts +144 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpolation and fractional delay for 0.6 instruments: 4-point Hermite
|
|
3
|
+
* reads (grains, modulated delays) and a first-order Thiran allpass
|
|
4
|
+
* fractional delay (string loops: flat magnitude, exact phase delay).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** 4-point, 3rd-order Hermite (Catmull-Rom) through xm1 x0 x1 x2 at t in [0, 1). */
|
|
8
|
+
export function hermite4(
|
|
9
|
+
xm1: number,
|
|
10
|
+
x0: number,
|
|
11
|
+
x1: number,
|
|
12
|
+
x2: number,
|
|
13
|
+
t: number,
|
|
14
|
+
): number {
|
|
15
|
+
const c1 = 0.5 * (x1 - xm1);
|
|
16
|
+
const c2 = xm1 - 2.5 * x0 + 2 * x1 - 0.5 * x2;
|
|
17
|
+
const c3 = 0.5 * (x2 - xm1) + 1.5 * (x0 - x1);
|
|
18
|
+
return ((c3 * t + c2) * t + c1) * t + x0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Hermite read of `x` at fractional position `pos`; zero outside the buffer. */
|
|
22
|
+
export function hermiteAt(x: Float64Array, pos: number): number {
|
|
23
|
+
const i = Math.floor(pos);
|
|
24
|
+
const n = x.length;
|
|
25
|
+
const at = (k: number): number => (k >= 0 && k < n ? x[k]! : 0);
|
|
26
|
+
return hermite4(at(i - 1), at(i), at(i + 1), at(i + 2), pos - i);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function clamp(x: number, lo: number, hi: number): number {
|
|
30
|
+
return x < lo ? lo : x > hi ? hi : x;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Phase delay (samples) at `w` rad/sample of the allpass (a + z^-1)/(1 + a z^-1). */
|
|
34
|
+
export function allpassDelay(a: number, w: number): number {
|
|
35
|
+
if (w < 1e-9) return (1 - a) / (1 + a);
|
|
36
|
+
const s = Math.sin(w);
|
|
37
|
+
const c = Math.cos(w);
|
|
38
|
+
const num = Math.atan2(-s, a + c);
|
|
39
|
+
const den = Math.atan2(-a * s, 1 + a * c);
|
|
40
|
+
let phase = num - den;
|
|
41
|
+
while (phase > 0) phase -= 2 * Math.PI;
|
|
42
|
+
while (phase <= -2 * Math.PI) phase += 2 * Math.PI;
|
|
43
|
+
return -phase / w;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* First-order Thiran allpass coefficient whose phase delay at `w` is exactly
|
|
48
|
+
* `d` samples (d in [0.5, 1.5)): Thiran's closed form, then Newton steps.
|
|
49
|
+
* With w = 0 this is (1 - d) / (1 + d), exact at DC.
|
|
50
|
+
*/
|
|
51
|
+
export function thiranFor(d: number, w = 0): number {
|
|
52
|
+
let a = (1 - d) / (1 + d);
|
|
53
|
+
if (w < 1e-9) return a;
|
|
54
|
+
for (let i = 0; i < 4; i += 1) {
|
|
55
|
+
const f = allpassDelay(a, w) - d;
|
|
56
|
+
if (Math.abs(f) < 1e-10) break;
|
|
57
|
+
const h = 1e-6;
|
|
58
|
+
const df = (allpassDelay(a + h, w) - allpassDelay(a - h, w)) / (2 * h);
|
|
59
|
+
if (df === 0) break;
|
|
60
|
+
a = clamp(a - f / df, -0.9, 0.9);
|
|
61
|
+
}
|
|
62
|
+
return a;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A delay of `delay` samples (>= 0.5): an integer delay line plus a Thiran
|
|
67
|
+
* allpass for the fraction in [0.5, 1.5), so the pole stays well inside the
|
|
68
|
+
* unit circle. `set` may be called between samples (string pitch moves);
|
|
69
|
+
* the allpass state carries over, which is the usual small transient.
|
|
70
|
+
*/
|
|
71
|
+
export class FracDelay {
|
|
72
|
+
private readonly buffer: Float64Array;
|
|
73
|
+
private readonly mask: number;
|
|
74
|
+
private write = 0;
|
|
75
|
+
private whole = 0;
|
|
76
|
+
private a = 0;
|
|
77
|
+
private u1 = 0;
|
|
78
|
+
private y1 = 0;
|
|
79
|
+
|
|
80
|
+
constructor(maxDelay: number, delay = 1, w = 0) {
|
|
81
|
+
let size = 4;
|
|
82
|
+
while (size < Math.ceil(maxDelay) + 4) size *= 2;
|
|
83
|
+
this.buffer = new Float64Array(size);
|
|
84
|
+
this.mask = size - 1;
|
|
85
|
+
this.set(delay, w);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Total delay in samples; `w` is where the phase delay is exact (rad/sample). */
|
|
89
|
+
set(delay: number, w = 0): void {
|
|
90
|
+
const total = clamp(delay, 0.5, this.mask - 2);
|
|
91
|
+
const whole = Math.max(0, Math.floor(total - 0.5));
|
|
92
|
+
this.whole = whole;
|
|
93
|
+
this.a = thiranFor(total - whole, w);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
process(x: number): number {
|
|
97
|
+
const b = this.buffer;
|
|
98
|
+
b[this.write] = x;
|
|
99
|
+
const u = b[(this.write - this.whole) & this.mask]!;
|
|
100
|
+
this.write = (this.write + 1) & this.mask;
|
|
101
|
+
const y = this.a * u + this.u1 - this.a * this.y1;
|
|
102
|
+
this.u1 = u;
|
|
103
|
+
this.y1 = y;
|
|
104
|
+
return y;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
reset(): void {
|
|
108
|
+
this.buffer.fill(0);
|
|
109
|
+
this.u1 = 0;
|
|
110
|
+
this.y1 = 0;
|
|
111
|
+
}
|
|
112
|
+
}
|