- Add Group string field to FreqConfig struct (GRP-04)
- Add frequency allocation table comment (32 slots, 65-2449 Hz, FREQ-03)
- Rebalance all 14 ClassFreqConfigs entries to major-second ladder (FREQ-01)
- Infrastructure band (Triangle, 65-133 Hz): ICMP/NTP/DHCP/DNS
- Web band (Sawtooth, 150-169 Hz): HTTPS/HTTP
- Mail band (Triangle, 214 Hz): SMTP
- Remote Access band (Square, 343 Hz): SSH
- Unknown band (Custom, 771-1375 Hz): Unknown1-4, OtherTCP, OtherUDP
- Remove stale NumLayers and GainPerLayer constants (Phase 8 cleanup)
- Non-Unknown entries use WaveformPresetHarmonics; Unknown retain hand-tuned {1,1.0},{2,0.8},{3,0.4}
216 lines
8.3 KiB
Go
216 lines
8.3 KiB
Go
package synth
|
|
|
|
import "github.com/netsynth/netsynth/classify"
|
|
|
|
const (
|
|
SampleRate = 44100 // D-13: CD quality
|
|
WindowMs = 500 // matches aggregate.DefaultWindowMs
|
|
SamplesPerWindow = SampleRate * WindowMs / 1000 // 22050
|
|
WhisperFloor = 0.03 // D-08/D-09: 3% of max amplitude
|
|
)
|
|
|
|
// WaveformType selects the harmonic preset for a synthesis layer.
|
|
// The zero value WaveformCustom preserves existing hand-tuned harmonics in FreqConfig.Harmonics.
|
|
type WaveformType int
|
|
|
|
const (
|
|
WaveformCustom WaveformType = iota // zero value: use FreqConfig.Harmonics as-is
|
|
WaveformSine // pure fundamental, single harmonic
|
|
WaveformSquare // odd harmonics with 1/k amplitude (bandlimited)
|
|
WaveformSawtooth // all harmonics with 1/k amplitude (bandlimited)
|
|
WaveformTriangle // odd harmonics with alternating 1/k^2 amplitude (bandlimited)
|
|
)
|
|
|
|
// WaveformPresetHarmonics returns the bandlimited harmonic series for the given waveform type
|
|
// at the given base frequency and sample rate. Returns nil for WaveformCustom.
|
|
// All returned harmonics are below Nyquist (sampleRate/2).
|
|
func WaveformPresetHarmonics(wt WaveformType, baseHz float64, sampleRate int) []HarmonicDef {
|
|
nyquist := float64(sampleRate) / 2.0
|
|
switch wt {
|
|
case WaveformCustom:
|
|
return nil
|
|
case WaveformSine:
|
|
return []HarmonicDef{{Ratio: 1, Amplitude: 1.0}}
|
|
case WaveformSquare:
|
|
var harmonics []HarmonicDef
|
|
for k := 1; float64(k)*baseHz < nyquist; k += 2 {
|
|
harmonics = append(harmonics, HarmonicDef{Ratio: k, Amplitude: 1.0 / float64(k)})
|
|
}
|
|
return harmonics
|
|
case WaveformSawtooth:
|
|
var harmonics []HarmonicDef
|
|
for k := 1; float64(k)*baseHz < nyquist; k++ {
|
|
harmonics = append(harmonics, HarmonicDef{Ratio: k, Amplitude: 1.0 / float64(k)})
|
|
}
|
|
return harmonics
|
|
case WaveformTriangle:
|
|
var harmonics []HarmonicDef
|
|
sign := 1.0
|
|
for k := 1; float64(k)*baseHz < nyquist; k += 2 {
|
|
harmonics = append(harmonics, HarmonicDef{Ratio: k, Amplitude: sign / float64(k*k)})
|
|
sign = -sign
|
|
}
|
|
return harmonics
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// HarmonicDef defines one partial in an additive synthesizer.
|
|
type HarmonicDef struct {
|
|
Ratio int // harmonic number: 1=fundamental, 2=octave, 3=fifth+octave, etc.
|
|
Amplitude float64 // relative weight
|
|
}
|
|
|
|
// FreqConfig holds synthesis parameters for one traffic class.
|
|
type FreqConfig struct {
|
|
BaseHz float64
|
|
Harmonics []HarmonicDef
|
|
Pan float64 // [-1, 1]: -1=full left, 0=center, +1=full right
|
|
WaveformType WaveformType // zero value WaveformCustom uses Harmonics as-is
|
|
Group string // sound family: "Infrastructure", "Web", "Mail", "Remote Access", "Unknown", etc.
|
|
}
|
|
|
|
// Frequency Allocation Table (Phase 9 design — major-second ladder, 65-2449 Hz)
|
|
//
|
|
// Slot Hz Class Group Waveform Pan
|
|
// 0 65 ICMP Infrastructure Triangle -0.3
|
|
// 1 73 NTP Infrastructure Triangle -0.1
|
|
// 2 82 DHCP Infrastructure Triangle 0.1
|
|
// 3 93 mDNS Infrastructure Triangle 0.3 (Phase 10)
|
|
// 4 105 SSDP Infrastructure Triangle -0.2 (Phase 10)
|
|
// 5 118 SNMP Infrastructure Triangle 0.2 (Phase 10)
|
|
// 6 133 DNS Infrastructure Triangle 0.0
|
|
// 7 150 HTTPS Web Sawtooth -0.4
|
|
// 8 169 HTTP Web Sawtooth -0.3
|
|
// 9 190 HTTP3 Web Sawtooth -0.2 (Phase 10)
|
|
// 10 214 SMTP Mail Triangle 0.2
|
|
// 11 241 IMAP Mail Triangle 0.3 (Phase 10)
|
|
// 12 271 POP3 Mail Triangle 0.4 (Phase 10)
|
|
// 13 305 SMTP-sub Mail Triangle 0.5 (Phase 10)
|
|
// 14 343 SSH Remote Access Square -0.7
|
|
// 15 385 RDP Remote Access Square -0.6 (Phase 10)
|
|
// 16 432 Telnet Remote Access Square -0.5 (Phase 10)
|
|
// 17 485 VNC Remote Access Square -0.4 (Phase 10)
|
|
// 18 545 FTP File Transfer Square 0.5 (Phase 10)
|
|
// 19 612 SMB File Transfer Square 0.6 (Phase 10)
|
|
// 20 687 TFTP File Transfer Square 0.7 (Phase 10)
|
|
// 21 771 unknown-1 Unknown Custom -0.9
|
|
// 22 866 unknown-2 Unknown Custom 0.9
|
|
// 23 972 unknown-3 Unknown Custom -0.7
|
|
// 24 1091 unknown-4 Unknown Custom 0.7
|
|
// 25 1225 other-TCP Unknown Custom -0.5
|
|
// 26 1375 other-UDP Unknown Custom 0.5
|
|
// 27 1543 MySQL Database Sawtooth -0.4 (Phase 10)
|
|
// 28 1732 PostgreSQL Database Sawtooth -0.2 (Phase 10)
|
|
// 29 1944 Redis Database Sawtooth 0.2 (Phase 10)
|
|
// 30 2182 MongoDB Database Sawtooth 0.4 (Phase 10)
|
|
// 31 2449 SIP VoIP Sine 0.0 (Phase 10)
|
|
//
|
|
// Auto-assign range: [2500, 4000] Hz (see config/config.go)
|
|
|
|
// ClassFreqConfigs maps each traffic class to its synthesis parameters.
|
|
// Frequencies per Phase 9 major-second ladder design. Harmonics per D-05/D-06.
|
|
// Pan positions per D-12. Group field drives family-aware config output (GRP-04).
|
|
var ClassFreqConfigs = map[classify.TrafficClass]FreqConfig{
|
|
// --- Infrastructure (Triangle, 65-133 Hz) ---
|
|
classify.ClassICMP: {
|
|
BaseHz: 65.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 65.0, SampleRate),
|
|
Pan: -0.3,
|
|
Group: "Infrastructure",
|
|
},
|
|
classify.ClassNTP: {
|
|
BaseHz: 73.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 73.0, SampleRate),
|
|
Pan: -0.1,
|
|
Group: "Infrastructure",
|
|
},
|
|
classify.ClassDHCP: {
|
|
BaseHz: 82.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 82.0, SampleRate),
|
|
Pan: 0.1,
|
|
Group: "Infrastructure",
|
|
},
|
|
classify.ClassDNS: {
|
|
BaseHz: 133.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 133.0, SampleRate),
|
|
Pan: 0.0,
|
|
Group: "Infrastructure",
|
|
},
|
|
// --- Web (Sawtooth, 150-169 Hz) ---
|
|
classify.ClassHTTPS: {
|
|
BaseHz: 150.0,
|
|
WaveformType: WaveformSawtooth,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSawtooth, 150.0, SampleRate),
|
|
Pan: -0.4,
|
|
Group: "Web",
|
|
},
|
|
classify.ClassHTTP: {
|
|
BaseHz: 169.0,
|
|
WaveformType: WaveformSawtooth,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSawtooth, 169.0, SampleRate),
|
|
Pan: -0.3,
|
|
Group: "Web",
|
|
},
|
|
// --- Mail (Triangle, 214 Hz) ---
|
|
classify.ClassSMTP: {
|
|
BaseHz: 214.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 214.0, SampleRate),
|
|
Pan: 0.2,
|
|
Group: "Mail",
|
|
},
|
|
// --- Remote Access (Square, 343 Hz) ---
|
|
classify.ClassSSH: {
|
|
BaseHz: 343.0,
|
|
WaveformType: WaveformSquare,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSquare, 343.0, SampleRate),
|
|
Pan: -0.7,
|
|
Group: "Remote Access",
|
|
},
|
|
// --- Unknown (Custom harmonics, 771-1375 Hz) ---
|
|
// D-05/D-06: dissonant harmonic character {1,1.0},{2,0.8},{3,0.4} retained for all Unknown entries.
|
|
// WaveformType is zero value (WaveformCustom) so bank.go uses the stored Harmonics directly.
|
|
classify.ClassUnknown1: {
|
|
BaseHz: 771.0,
|
|
Harmonics: []HarmonicDef{{1, 1.0}, {2, 0.8}, {3, 0.4}},
|
|
Pan: -0.9,
|
|
Group: "Unknown",
|
|
},
|
|
classify.ClassUnknown2: {
|
|
BaseHz: 866.0,
|
|
Harmonics: []HarmonicDef{{1, 1.0}, {2, 0.8}, {3, 0.4}},
|
|
Pan: 0.9,
|
|
Group: "Unknown",
|
|
},
|
|
classify.ClassUnknown3: {
|
|
BaseHz: 972.0,
|
|
Harmonics: []HarmonicDef{{1, 1.0}, {2, 0.8}, {3, 0.4}},
|
|
Pan: -0.7,
|
|
Group: "Unknown",
|
|
},
|
|
classify.ClassUnknown4: {
|
|
BaseHz: 1091.0,
|
|
Harmonics: []HarmonicDef{{1, 1.0}, {2, 0.8}, {3, 0.4}},
|
|
Pan: 0.7,
|
|
Group: "Unknown",
|
|
},
|
|
classify.ClassOtherTCP: {
|
|
BaseHz: 1225.0,
|
|
Harmonics: []HarmonicDef{{1, 1.0}, {2, 0.8}, {3, 0.4}},
|
|
Pan: -0.5,
|
|
Group: "Unknown",
|
|
},
|
|
classify.ClassOtherUDP: {
|
|
BaseHz: 1375.0,
|
|
Harmonics: []HarmonicDef{{1, 1.0}, {2, 0.8}, {3, 0.4}},
|
|
Pan: 0.5,
|
|
Group: "Unknown",
|
|
},
|
|
}
|