feat(synth): add LFO modulation, ADSR envelopes, pentatonic tuning, and soft limiter

Replace static EMA-smoothed drones with an evolving ambient soundscape:
- ADSR envelope system with sustained (2s attack, 4s release) and bursty
  (30ms attack, no sustain) modes per protocol group
- LFO pitch wobble and amplitude tremolo with incommensurable rates per
  group (Eno technique) so modulation patterns never repeat
- C major pentatonic frequency tuning (just intonation) — any combination
  of active protocols sounds consonant
- tanh soft limiter on master output prevents clipping
- Sync all documentation: README, PROJECT.md, ARCHITECTURE.md, v1.2
  requirements traceability

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-27 19:38:58 +01:00
co-authored by Claude Opus 4.6
parent 494385b528
commit 6b2db48339
14 changed files with 824 additions and 255 deletions
+70 -5
View File
@@ -471,20 +471,85 @@ Frequency assignments must be validated by ear, not just by looking at Hz values
| Frequency collisions | None | Possible if not planned |
| AllClasses() iteration | 14 items, trivial | 32 items, still trivial |
| PrintConfig output lines | ~60 lines | ~130 lines |
| EMA smoothing convergence | No change | No change (per-layer, independent) |
| ADSR envelope convergence | No change | No change (per-layer, independent) |
| NewBank construction time | Negligible | Negligible |
The main practical change is perceptual loudness: with 32 layers each at 3.1% gain, the ambient mix becomes quieter when many protocols are active simultaneously. This is acceptable and matches the ambient/drone aesthetic. The `WhisperFloor` mechanism ensures inactive layers contribute minimally, so sessions with only 5-6 active protocols still sound full.
The main practical change is perceptual loudness: with 32 layers each at ~2.6% gain (accounting for tremolo headroom), the ambient mix becomes quieter when many protocols are active simultaneously. This is acceptable and matches the ambient aesthetic. The ADSR envelope system ensures inactive layers fade to silence, while the soft limiter prevents distortion when many protocols spike simultaneously.
---
## Synthesis Layer: Envelope + LFO + Soft Limiter (post-v1.2)
The original synthesis pipeline used pure EMA (exponential moving average) smoothing and static oscillators, producing continuous drones. This was replaced with a richer signal chain to create an evolving ambient soundscape:
### Signal Chain per Layer
```
Oscillator → ADSR Envelope → LFO Modulation → Per-layer Gain → Stereo Pan → Soft Limiter → Mix
```
### ADSR Envelope System (`synth/envelope.go`)
Replaces the single-coefficient EMA with a four-stage envelope state machine:
| Parameter | Sustained Protocols | Bursty Protocols |
|-----------|--------------------|--------------------|
| Attack | 2.0s (slow fade-in) | 0.03s (fast onset) |
| Decay | 1.0s (slight dip) | 0.3s (rapid drop) |
| Sustain | 85% of peak | 0% (no sustain) |
| Release | 4.0s (long tail) | 1.5s (medium tail) |
Protocol categorization via `FreqConfig.Bursty` flag:
- **Sustained** (Bursty=false): HTTPS, HTTP, QUIC, SSH, SMTP, IMAP, databases — produce ambient pads
- **Bursty** (Bursty=true): ICMP, DNS, NTP, DHCP, mDNS, SSDP, SNMP, LDAP, Kerberos, Syslog — produce percussive accents
The envelope wraps traffic-rate EMA: during Sustain phase, the EMA-smoothed traffic rate modulates amplitude within the sustain level, preserving the original volume-follows-traffic behavior.
### LFO Modulation (`synth/lfo.go`)
Each Layer has two LFOs:
1. **Pitch LFO** — Modulates oscillator frequency by +/- 0.05-0.15 semitones. Creates subtle detuning that makes drones "breathe".
2. **Tremolo LFO** — Modulates amplitude by +/- 8-20%. Creates gentle pulsing.
Group-specific LFO rates use **incommensurable periods** (Eno technique) so combined modulation never repeats:
| Group | Pitch Rate (Hz) | Tremolo Rate (Hz) |
|-------|----------------|-------------------|
| Infrastructure | 0.031 | 0.053 |
| Web | 0.043 | 0.071 |
| Mail | 0.037 | 0.059 |
| Remote Access | 0.029 | 0.047 |
| File Transfer | 0.041 | 0.067 |
| Database | 0.023 | 0.083 |
| VoIP | 0.019 | 0.091 |
| Unknown | 0.053 | 0.037 |
### Pentatonic Frequency Tuning
The original major-second ladder was replaced with **C major pentatonic (just intonation)**: C D E G A across octaves 2-8 (ratios 1/1, 9/8, 5/4, 3/2, 5/3). This guarantees that any subset of simultaneously active protocols produces consonant intervals — no dissonant beating.
### Soft Limiter (`synth/bank.go`)
A `tanh`-based soft limiter on the master stereo output replaces hard clipping. Combined with tremolo-headroom-aware gain (`1 / (N × 1.2)`), this preserves dynamics while preventing distortion during traffic spikes.
### Integration Points
- `FreqConfig.Bursty` (config.go) → selects `SustainedEnvParams` vs `BurstyEnvParams` in `NewLayer()`
- `FreqConfig.Group` (config.go) selects `LFOConfig` via `LFOConfigForGroup()` in `NewLayer()`
- `Layer.AdvanceSample()` (layer.go) → applies pitch LFO to oscillator freq, generates sample, applies envelope, applies tremolo
- `OscillatorBank.RenderWindow()` (bank.go) → applies per-layer gain + pan, then `softLimit()` on each stereo frame
---
## Sources
- Direct code inspection: `synth/config.go`, `synth/bank.go`, `synth/layer.go`, `synth/oscillator.go`, `classify/types.go`, `classify/rules.go`, `classify/classifier.go`, `config/config.go`, `encode/mp3.go`, `cmd/netsynth/main.go` — HIGH confidence
- Musical interval theory (detuning, harmonic relationships): HIGH confidence — standard acoustic physics
- Direct code inspection: `synth/config.go`, `synth/bank.go`, `synth/layer.go`, `synth/oscillator.go`, `synth/lfo.go`, `synth/envelope.go`, `classify/types.go`, `classify/rules.go`, `classify/classifier.go`, `config/config.go`, `encode/mp3.go`, `cmd/netsynth/main.go` — HIGH confidence
- Musical interval theory (detuning, harmonic relationships, pentatonic scales): HIGH confidence — standard acoustic physics
- Brian Eno incommensurable-period technique: HIGH confidence — well-documented generative music principle
- v1.2 protocol list: determined from feature research (see FEATURES.md for rationale on which protocols to include)
---
*Architecture research for: NetSynth v1.2 — extended protocol coverage with grouped families*
*Researched: 2026-03-27*
*Updated: 2026-03-27 — added synthesis layer documentation (ADSR, LFO, pentatonic, soft limiter)*