From 667b7365ce8033802d34d894693cca175da1a696 Mon Sep 17 00:00:00 2001 From: Jan Svabenik Date: Thu, 2 Apr 2026 23:06:11 +0200 Subject: [PATCH] feat: add output-rate override and stronger offline wav tests --- cmd/offline/main.go | 4 ++++ internal/audio/wav_test.go | 14 ++++++++++++++ internal/offline/generator_test.go | 11 +++++++++++ 3 files changed, 29 insertions(+) diff --git a/cmd/offline/main.go b/cmd/offline/main.go index ef3d5c4..bc43c18 100644 --- a/cmd/offline/main.go +++ b/cmd/offline/main.go @@ -14,12 +14,16 @@ func main() { configPath := flag.String("config", "", "path to JSON config") out := flag.String("output", "", "output IQ file path") duration := flag.Duration("duration", 2*time.Second, "generation duration") + outputRate := flag.Int("output-rate", 0, "override composite output sample rate") flag.Parse() cfg, err := cfgpkg.Load(*configPath) if err != nil { log.Fatalf("load config: %v", err) } + if *outputRate > 0 { + cfg.FM.CompositeRateHz = *outputRate + } gen := offpkg.NewGenerator(cfg) if err := gen.WriteFile(*out, *duration); err != nil { diff --git a/internal/audio/wav_test.go b/internal/audio/wav_test.go index 88ee755..63e45fb 100644 --- a/internal/audio/wav_test.go +++ b/internal/audio/wav_test.go @@ -10,6 +10,9 @@ func TestPCM16ToSample(t *testing.T) { if pcm16ToSample(32767) <= 0 { t.Fatal("expected positive sample") } + if pcm16ToSample(-32768) < -1.0 { + t.Fatal("expected clamped lower bound") + } } func TestLoadWAVSource(t *testing.T) { @@ -36,3 +39,14 @@ func TestLoadWAVSource(t *testing.T) { } _ = src.NextFrame() } + +func TestRejectInvalidWAV(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "bad.wav") + if err := os.WriteFile(path, []byte("nope"), 0o644); err != nil { + t.Fatalf("write wav: %v", err) + } + if _, err := LoadWAVSource(path); err == nil { + t.Fatal("expected wav load error") + } +} diff --git a/internal/offline/generator_test.go b/internal/offline/generator_test.go index c273b86..5d37b7a 100644 --- a/internal/offline/generator_test.go +++ b/internal/offline/generator_test.go @@ -3,6 +3,7 @@ package offline import ( "os" "path/filepath" + "strings" "testing" "time" @@ -36,3 +37,13 @@ func TestWriteFile(t *testing.T) { t.Fatal("expected non-empty file") } } + +func TestSummaryUsesToneFallback(t *testing.T) { + cfg := cfgpkg.Default() + cfg.Audio.InputPath = "" + g := NewGenerator(cfg) + summary := g.Summary(10 * time.Millisecond) + if !strings.Contains(summary, "source=tones") { + t.Fatalf("unexpected summary: %s", summary) + } +}