quiver-dsp 0.1.0

A modular audio synthesis library using Arrow-style combinators and graph-based patching
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# Effects

Signal processing effects for shaping sound character.

## Saturator

Soft clipping distortion based on analog saturation curves.

```rust,ignore
use quiver::analog::{Saturator, saturation};

let sat = patch.add("saturator", Saturator::new(saturation::tanh_sat));
```

### Inputs

| Port | Signal | Description |
|------|--------|-------------|
| `in` | Audio | Input signal |
| `drive` | Unipolar CV | Saturation amount |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Saturated output |

### Saturation Types

| Function | Character |
|----------|-----------|
| `tanh_sat` | Smooth, tube-like |
| `soft_clip` | Adjustable knee |
| `asym_sat` | Even harmonics |
| `diode_clip` | Hard, aggressive |

---

## Wavefolder

Creates complex harmonics by reflecting the signal about a threshold. Supports opt-in
oversampling via `set_oversample`. `type_id`: `wavefolder`.

```rust,ignore
let folder = patch.add("folder", Wavefolder::new(1.0)); // threshold
```

### Inputs

| Port | Signal | Description |
|------|--------|-------------|
| `in` | Audio | Input signal |
| `threshold` | Unipolar CV | Fold threshold (default = constructor value) |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Folded output |

### The Folding Process

```
Input:   ╱╲
        ╱  ╲
       ╱    ╲

1 Fold: ╱╲╱╲
       ╱    ╲

2 Folds: ╱╲╱╲╱╲╱╲
        ╱      ╲
```

$$y = \sin(f \cdot \pi \cdot x)$$

Where $f$ is the fold amount.

---

## Crosstalk

Simulates channel bleed between left and right.

```rust,ignore
let crosstalk = patch.add("xtalk", Crosstalk::new());
```

### Inputs

| Port | Signal | Description |
|------|--------|-------------|
| `left` | Audio | Left channel |
| `right` | Audio | Right channel |
| `amount` | Unipolar CV | Bleed amount (0-10%) |

### Outputs

| Port | Signal | Description |
|------|--------|-------------|
| `left` | Audio | Left with right bleed |
| `right` | Audio | Right with left bleed |

### The Effect

$$L_{out} = L_{in} + \text{amount} \cdot R_{in}$$
$$R_{out} = R_{in} + \text{amount} \cdot L_{in}$$

Adds subtle width and analog character.

---

## Ground Loop

Simulates 50/60Hz power supply hum.

```rust,ignore
let hum = patch.add("hum", GroundLoop::new(44100.0));
```

### Inputs

| Port | Signal | Description |
|------|--------|-------------|
| `amount` | Unipolar CV | Hum level |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Hum signal |

### Configuration

```rust,ignore
let hum = GroundLoop::new(44100.0)
    .with_frequency(60.0)   // 60Hz (US) or 50Hz (EU)
    .with_harmonics(3);     // Include 2nd and 3rd harmonics
```

Mix very subtly for vintage authenticity.

---

## Scope

Real-time waveform visualization.

```rust,ignore
let scope = patch.add("scope", Scope::new(44100.0));
```

### Inputs

| Port | Signal | Description |
|------|--------|-------------|
| `in` | Audio | Signal to display |
| `trigger` | Gate | Trigger sync |

### Trigger Modes

| Mode | Description |
|------|-------------|
| `Free` | Continuous display |
| `RisingEdge` | Sync on positive zero-cross |
| `FallingEdge` | Sync on negative zero-cross |
| `Single` | One-shot capture |

### Reading the Buffer

```rust,ignore
let waveform = scope.buffer();
// Vec<f64> of recent samples
```

---

## Spectrum Analyzer

FFT-based frequency analysis.

```rust,ignore
let analyzer = patch.add("spectrum", SpectrumAnalyzer::new(44100.0));
```

### Input

| Port | Signal | Description |
|------|--------|-------------|
| `in` | Audio | Signal to analyze |

### Reading Data

```rust,ignore
let bins = analyzer.bins();           // Frequency bins
let mags = analyzer.magnitudes();     // dB values
let peak = analyzer.peak_frequency(); // Dominant frequency
```

---

## Level Meter

RMS and peak level monitoring.

```rust,ignore
let meter = patch.add("meter", LevelMeter::new(44100.0));
```

### Input

| Port | Signal | Description |
|------|--------|-------------|
| `in` | Audio | Signal to meter |

### Reading Levels

```rust,ignore
let rms = meter.rms();       // RMS level in volts
let peak = meter.peak();     // Peak level
let rms_db = meter.rms_db(); // RMS in dB
```

### Peak Hold

```rust,ignore
let meter = LevelMeter::new(44100.0)
    .with_peak_hold(500.0);  // 500ms hold time
```

---

## Distortion

Waveshaping distortion with four selectable algorithms (soft clip, hard clip, foldback,
asymmetric), a one-pole tone control, dry/wet mix, and opt-in oversampling
(`set_oversample`). `type_id`: `distortion`.

```rust,ignore
let dist = patch.add("dist", Distortion::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `drive` | Unipolar CV | 0-10V | Drive into the shaper, default 0.5 |
| `tone` | Unipolar CV | 0-10V | Tone (one-pole lowpass), default 0.5 |
| `mode` | Unipolar CV | 0-10V | Algorithm select (4 modes) |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default fully wet |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Distorted output |

---

## Bitcrusher

Lo-fi bit-depth and sample-rate reduction. `type_id`: `bitcrusher`.

```rust,ignore
let crush = patch.add("crush", Bitcrusher::new());
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `bits` | Unipolar CV | 0-10V | Bit-depth reduction (~1–16 bits), default 0.5 |
| `downsample` | Unipolar CV | 0-10V | Sample-rate reduction |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Crushed output |

---

## Delay Line

Delay of up to 2 seconds with feedback and wet/dry mix; slew-smoothed delay time for
CV-modulated effects. Breaks feedback cycles. `type_id`: `delay_line`.

```rust,ignore
let delay = patch.add("delay", DelayLine::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `time` | Unipolar CV | 0-10V | Delay time (1 ms–2 s, exponential), default 0.5 |
| `feedback` | Unipolar CV | 0-10V | Feedback (0–0.99) |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default 0.5 |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Mixed dry + delayed output |

---

## Chorus

Three-voice modulated-delay chorus with a mono and a stereo-spread output. `type_id`: `chorus`.

```rust,ignore
let chorus = patch.add("chorus", Chorus::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `rate` | Unipolar CV | 0-10V | LFO rate (0.1–5 Hz), default 0.3 |
| `depth` | Unipolar CV | 0-10V | Modulation depth (0–25 ms), default 0.5 |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default 0.5 |

### Outputs

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Mono mixed output |
| `left` | Audio | Left stereo-spread output |
| `right` | Audio | Right stereo-spread output |

---

## Flanger

Short-modulated-delay flanger with feedback; mono in, stereo out via a `spread` control.
`out` mirrors `left` for backward compatibility. `type_id`: `flanger`.

```rust,ignore
let flanger = patch.add("flanger", Flanger::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `rate` | Unipolar CV | 0-10V | LFO rate, default 0.3 |
| `depth` | Unipolar CV | 0-10V | Sweep depth, default 0.5 |
| `feedback` | Bipolar CV | ±5V | Feedback (−0.95–0.95) |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default 0.5 |
| `spread` | Unipolar CV | 0-10V | Stereo L/R decorrelation (0 = mono, 1 = 180°), default 0.5 |

### Outputs

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Legacy mono output (mirrors `left`) |
| `left` | Audio | Left channel |
| `right` | Audio | Right channel (phase-offset sweep) |

---

## Phaser

Cascaded-allpass phaser (2/4/6 selectable stages) with feedback; mono in, stereo out with
a `spread` control. `out` mirrors `left`. `type_id`: `phaser`.

```rust,ignore
let phaser = patch.add("phaser", Phaser::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `rate` | Unipolar CV | 0-10V | LFO rate, default 0.3 |
| `depth` | Unipolar CV | 0-10V | Notch sweep depth, default 0.7 |
| `feedback` | Bipolar CV | ±5V | Feedback (−0.95–0.95) |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default 0.5 |
| `stages` | Unipolar CV | 0-10V | Allpass stage count (<0.33 → 2, <0.66 → 4, else 6) |
| `spread` | Unipolar CV | 0-10V | Stereo L/R decorrelation, default 0.5 |

### Outputs

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Legacy mono output (mirrors `left`) |
| `left` | Audio | Left channel |
| `right` | Audio | Right channel (phase-offset notch sweep) |

---

## Tremolo

Amplitude-modulation tremolo with a sine-to-triangle shape blend. `type_id`: `tremolo`.

```rust,ignore
let trem = patch.add("trem", Tremolo::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `rate` | Unipolar CV | 0-10V | LFO rate (0.1–20 Hz), default 0.3 |
| `depth` | Unipolar CV | 0-10V | Modulation depth, default 0.5 |
| `shape` | Unipolar CV | 0-10V | LFO shape blend (sine ↔ triangle) |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Amplitude-modulated output |

---

## Vibrato

Pitch-modulation vibrato via a modulated delay line; defaults fully wet. `type_id`: `vibrato`.

```rust,ignore
let vib = patch.add("vib", Vibrato::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `rate` | Unipolar CV | 0-10V | LFO rate (0.1–15 Hz), default 0.3 |
| `depth` | Unipolar CV | 0-10V | Pitch-modulation depth, default 0.5 |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default fully wet |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Pitch-modulated output |

---

## Reverb

Freeverb-style algorithmic reverb (8 comb + 4 allpass) with size, damping, mix, and
pre-delay. Stereo output. `type_id`: `reverb`.

```rust,ignore
let reverb = patch.add("reverb", Reverb::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `size` | Unipolar CV | 0-10V | Room size / decay, default 0.5 |
| `damping` | Unipolar CV | 0-10V | High-frequency damping, default 0.5 |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default 0.5 |
| `predelay` | Unipolar CV | 0-10V | Pre-delay (0–100 ms) |

### Outputs

| Port | Signal | Description |
|------|--------|-------------|
| `left` | Audio | Left reverb channel |
| `right` | Audio | Right reverb channel |

---

## Pitch Shifter

Granular (two-grain, crossfaded) real-time pitch shifter. `type_id`: `pitch_shifter`.

```rust,ignore
let shift = patch.add("shift", PitchShifter::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio input |
| `shift` | Bipolar CV | ±5V | Pitch shift (±24 semitones) |
| `window` | Unipolar CV | 0-10V | Grain window (10–100 ms), default 0.5 |
| `mix` | Unipolar CV | 0-10V | Dry/wet, default fully wet |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Pitch-shifted output |

---

## Granular

Granular processor: records the input into a circular buffer and plays overlapping
Hann-windowed grains. `type_id`: `granular`.

```rust,ignore
let gran = patch.add("gran", Granular::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `in` | Audio | ±5V | Audio recorded into the buffer |
| `position` | Unipolar CV | 0-10V | Playback position, default 0.5 |
| `size` | Unipolar CV | 0-10V | Grain size (10–500 ms), default 0.3 |
| `density` | Unipolar CV | 0-10V | Grains per second (1–20), default 0.5 |
| `pitch` | Bipolar CV | ±5V | Pitch shift (±24 semitones) |
| `spray` | Unipolar CV | 0-10V | Position randomization, default 0.1 |
| `freeze` | Gate | 0/5V | Stops recording while high |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Granular output |

---

## Vocoder

Channel vocoder: per-band envelope followers on the modulator impose its spectral
envelope onto the carrier. `type_id`: `vocoder`.

```rust,ignore
let voc = patch.add("voc", Vocoder::new(44100.0));
```

### Inputs

| Port | Signal | Range | Description |
|------|--------|-------|-------------|
| `carrier` | Audio | ±5V | Carrier (typically an oscillator) |
| `modulator` | Audio | ±5V | Modulator (typically voice) |
| `bands` | Unipolar CV | 0-10V | Band count (4–16), default 1.0 |
| `attack` | Unipolar CV | 0-10V | Envelope-follower attack, default 0.3 |
| `release` | Unipolar CV | 0-10V | Envelope-follower release, default 0.3 |

### Output

| Port | Signal | Description |
|------|--------|-------------|
| `out` | Audio | Vocoded output |

---

## Building Effect Chains

### Serial Processing

```rust,ignore
// Input → Saturator → Filter → Output
patch.connect(input, sat.in_("in"))?;
patch.connect(sat.out("out"), vcf.in_("in"))?;
patch.connect(vcf.out("lp"), output)?;
```

### Parallel Processing

```rust,ignore
// Dry/wet mix
patch.connect(input, mult.in_("in"))?;
patch.connect(mult.out("out_1"), effect.in_("in"))?;  // Wet
patch.connect(mult.out("out_2"), xfade.in_("a"))?;    // Dry
patch.connect(effect.out("out"), xfade.in_("b"))?;    // Wet
```

### Feedback Loop

```rust,ignore
// With unit delay to prevent infinite loop
patch.connect(effect.out("out"), delay.in_("in"))?;
patch.connect(delay.out("out"), atten.in_("in"))?;  // Feedback amount
patch.connect(atten.out("out"), effect.in_("in"))?;
```