From 3dfcbbeaf567bd3fa93784f2b4d063b2ec6c7bc3 Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Thu, 26 Mar 2026 21:02:35 +0100 Subject: [PATCH] feat(06-02): add freqCfgs parameter to RunSynthesis - Change RunSynthesis signature to accept injected config map (D-10) - Replace hardcoded synth.ClassFreqConfigs with passed-in freqCfgs - Update all three RunSynthesis calls in encode tests to pass synth.ClassFreqConfigs --- encode/mp3.go | 5 +++-- encode/mp3_test.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/encode/mp3.go b/encode/mp3.go index 3279dca..8820003 100644 --- a/encode/mp3.go +++ b/encode/mp3.go @@ -41,9 +41,10 @@ func EncodeMP3(outputPath string, frames [][2]float64, sampleRate int) error { // RunSynthesis consumes a slice of WindowSnapshots, renders audio via OscillatorBank, // and encodes to MP3 at outputPath. +// freqCfgs is the merged config map from config.Load (D-10: injected, not hardcoded). // Returns an error if zero packets were captured (D-16 / OUT-03). // The zero-packet guard runs BEFORE file creation to avoid leaving an empty file on disk. -func RunSynthesis(snapshots []classify.WindowSnapshot, outputPath string) error { +func RunSynthesis(snapshots []classify.WindowSnapshot, outputPath string, freqCfgs map[classify.TrafficClass]synth.FreqConfig) error { // D-16 / OUT-03: Zero-packet guard — check BEFORE creating output file var totalPackets int64 for _, snap := range snapshots { @@ -54,7 +55,7 @@ func RunSynthesis(snapshots []classify.WindowSnapshot, outputPath string) error } // Render all windows to stereo frames - bank := synth.NewBank(1.0, synth.ClassFreqConfigs) // tau=1.0s per D-07 + bank := synth.NewBank(1.0, freqCfgs) // tau=1.0s per D-07 var allFrames [][2]float64 for _, snap := range snapshots { frames := bank.RenderWindow(snap) diff --git a/encode/mp3_test.go b/encode/mp3_test.go index 2c18454..53f4d5c 100644 --- a/encode/mp3_test.go +++ b/encode/mp3_test.go @@ -53,7 +53,7 @@ func TestMP3Valid(t *testing.T) { tmpFile.Close() defer os.Remove(tmpPath) - if err := RunSynthesis(snaps, tmpPath); err != nil { + if err := RunSynthesis(snaps, tmpPath, synth.ClassFreqConfigs); err != nil { t.Fatalf("RunSynthesis: %v", err) } @@ -98,7 +98,7 @@ func TestZeroPacketError(t *testing.T) { tmpPath := "/tmp/netsynth-should-not-exist-" + t.Name() + ".mp3" defer os.Remove(tmpPath) - err := RunSynthesis([]classify.WindowSnapshot{}, tmpPath) + err := RunSynthesis([]classify.WindowSnapshot{}, tmpPath, synth.ClassFreqConfigs) if err == nil { t.Fatal("expected error for empty snapshot slice, got nil") } @@ -118,7 +118,7 @@ func TestZeroPacketError(t *testing.T) { {Counts: map[classify.TrafficClass]int64{}, TotalPackets: 0, WindowIndex: 0}, {Counts: map[classify.TrafficClass]int64{}, TotalPackets: 0, WindowIndex: 1}, } - err2 := RunSynthesis(zeroSnaps, tmpPath2) + err2 := RunSynthesis(zeroSnaps, tmpPath2, synth.ClassFreqConfigs) if err2 == nil { t.Fatal("expected error for zero-packet snapshots, got nil") }