- Add 21 new ClassFreqConfigs entries covering mDNS/SSDP/SNMP/QUIC/IMAP/POP3/SMTPSub/RDP/Telnet/VNC/FTP/SMB/TFTP/MySQL/PostgreSQL/Redis/MongoDB/SIP/LDAP/Kerberos/Syslog - Update AllClasses() to return 35 entries (add LDAP/Kerberos/Syslog in Infrastructure section) - Remove outdated Phase 11 exclusion comment from AllClasses() doc comment
371 lines
13 KiB
Go
371 lines
13 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",
|
|
},
|
|
// --- Infrastructure additions (Triangle, 93-118 Hz) ---
|
|
classify.ClassMDNS: {
|
|
BaseHz: 93.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 93.0, SampleRate),
|
|
Pan: 0.3,
|
|
Group: "Infrastructure",
|
|
},
|
|
classify.ClassSSDP: {
|
|
BaseHz: 105.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 105.0, SampleRate),
|
|
Pan: -0.2,
|
|
Group: "Infrastructure",
|
|
},
|
|
classify.ClassSNMP: {
|
|
BaseHz: 118.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 118.0, SampleRate),
|
|
Pan: 0.2,
|
|
Group: "Infrastructure",
|
|
},
|
|
// --- Web addition (Sawtooth, 190 Hz) ---
|
|
classify.ClassQUIC: {
|
|
BaseHz: 190.0,
|
|
WaveformType: WaveformSawtooth,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSawtooth, 190.0, SampleRate),
|
|
Pan: -0.2,
|
|
Group: "Web",
|
|
},
|
|
// --- Mail additions (Triangle, 241-305 Hz) ---
|
|
classify.ClassIMAP: {
|
|
BaseHz: 241.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 241.0, SampleRate),
|
|
Pan: 0.3,
|
|
Group: "Mail",
|
|
},
|
|
classify.ClassPOP3: {
|
|
BaseHz: 271.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 271.0, SampleRate),
|
|
Pan: 0.4,
|
|
Group: "Mail",
|
|
},
|
|
classify.ClassSMTPSub: {
|
|
BaseHz: 305.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 305.0, SampleRate),
|
|
Pan: 0.5,
|
|
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",
|
|
},
|
|
// --- Remote Access additions (Square, 385-485 Hz) ---
|
|
classify.ClassRDP: {
|
|
BaseHz: 385.0,
|
|
WaveformType: WaveformSquare,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSquare, 385.0, SampleRate),
|
|
Pan: -0.6,
|
|
Group: "Remote Access",
|
|
},
|
|
classify.ClassTelnet: {
|
|
BaseHz: 432.0,
|
|
WaveformType: WaveformSquare,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSquare, 432.0, SampleRate),
|
|
Pan: -0.5,
|
|
Group: "Remote Access",
|
|
},
|
|
classify.ClassVNC: {
|
|
BaseHz: 485.0,
|
|
WaveformType: WaveformSquare,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSquare, 485.0, SampleRate),
|
|
Pan: -0.4,
|
|
Group: "Remote Access",
|
|
},
|
|
// --- File Transfer additions (Square, 545-687 Hz) ---
|
|
classify.ClassFTP: {
|
|
BaseHz: 545.0,
|
|
WaveformType: WaveformSquare,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSquare, 545.0, SampleRate),
|
|
Pan: 0.5,
|
|
Group: "File Transfer",
|
|
},
|
|
classify.ClassSMB: {
|
|
BaseHz: 612.0,
|
|
WaveformType: WaveformSquare,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSquare, 612.0, SampleRate),
|
|
Pan: 0.6,
|
|
Group: "File Transfer",
|
|
},
|
|
classify.ClassTFTP: {
|
|
BaseHz: 687.0,
|
|
WaveformType: WaveformSquare,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSquare, 687.0, SampleRate),
|
|
Pan: 0.7,
|
|
Group: "File Transfer",
|
|
},
|
|
// --- 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",
|
|
},
|
|
// --- Database additions (Sawtooth, 1543-2182 Hz) ---
|
|
classify.ClassMySQL: {
|
|
BaseHz: 1543.0,
|
|
WaveformType: WaveformSawtooth,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSawtooth, 1543.0, SampleRate),
|
|
Pan: -0.4,
|
|
Group: "Database",
|
|
},
|
|
classify.ClassPostgreSQL: {
|
|
BaseHz: 1732.0,
|
|
WaveformType: WaveformSawtooth,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSawtooth, 1732.0, SampleRate),
|
|
Pan: -0.2,
|
|
Group: "Database",
|
|
},
|
|
classify.ClassRedis: {
|
|
BaseHz: 1944.0,
|
|
WaveformType: WaveformSawtooth,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSawtooth, 1944.0, SampleRate),
|
|
Pan: 0.2,
|
|
Group: "Database",
|
|
},
|
|
classify.ClassMongoDB: {
|
|
BaseHz: 2182.0,
|
|
WaveformType: WaveformSawtooth,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSawtooth, 2182.0, SampleRate),
|
|
Pan: 0.4,
|
|
Group: "Database",
|
|
},
|
|
// --- VoIP (Sine, 2449 Hz) ---
|
|
classify.ClassSIP: {
|
|
BaseHz: 2449.0,
|
|
WaveformType: WaveformSine,
|
|
Harmonics: WaveformPresetHarmonics(WaveformSine, 2449.0, SampleRate),
|
|
Pan: 0.0,
|
|
Group: "VoIP",
|
|
},
|
|
// --- Infrastructure auto-assigned (Triangle, 2950-3250 Hz) per D-02 ---
|
|
classify.ClassLDAP: {
|
|
BaseHz: 2950.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 2950.0, SampleRate),
|
|
Pan: -0.2,
|
|
Group: "Infrastructure",
|
|
},
|
|
classify.ClassKerberos: {
|
|
BaseHz: 3250.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 3250.0, SampleRate),
|
|
Pan: 0.0,
|
|
Group: "Infrastructure",
|
|
},
|
|
classify.ClassSyslog: {
|
|
BaseHz: 3050.0,
|
|
WaveformType: WaveformTriangle,
|
|
Harmonics: WaveformPresetHarmonics(WaveformTriangle, 3050.0, SampleRate),
|
|
Pan: 0.2,
|
|
Group: "Infrastructure",
|
|
},
|
|
}
|