Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

51 řádky
1.5KB

  1. package stereo
  2. import (
  3. "math"
  4. "testing"
  5. "github.com/jan/fm-rds-tx/internal/audio"
  6. )
  7. func TestStereoEncoderEncode(t *testing.T) {
  8. enc := NewStereoEncoder(228000)
  9. frame := audio.NewFrame(1, -1)
  10. result := enc.Encode(frame)
  11. if math.Abs(result.Mono) > 1e-9 { t.Fatalf("expected mono 0, got %v", result.Mono) }
  12. var maxStereo float64
  13. for i := 0; i < 100; i++ {
  14. c := enc.Encode(frame)
  15. if math.Abs(c.Stereo) > maxStereo { maxStereo = math.Abs(c.Stereo) }
  16. }
  17. if maxStereo < 0.1 { t.Fatalf("expected non-trivial stereo, maxStereo=%.6f", maxStereo) }
  18. }
  19. func TestStereoEncoderMonoSignal(t *testing.T) {
  20. enc := NewStereoEncoder(228000)
  21. frame := audio.NewFrame(0.5, 0.5)
  22. for i := 0; i < 100; i++ {
  23. c := enc.Encode(frame)
  24. if math.Abs(c.Stereo) > 1e-12 { t.Fatalf("expected zero stereo, got %.9f", c.Stereo) }
  25. if math.Abs(c.Mono-0.5) > 1e-9 { t.Fatalf("expected mono=0.5, got %.9f", c.Mono) }
  26. }
  27. }
  28. func TestStereoEncoderPilotRange(t *testing.T) {
  29. enc := NewStereoEncoder(228000)
  30. frame := audio.NewFrame(0.1, -0.1)
  31. for i := 0; i < 1000; i++ {
  32. c := enc.Encode(frame)
  33. if c.Pilot < -1.001 || c.Pilot > 1.001 { t.Fatalf("pilot out of range: %.6f", c.Pilot) }
  34. }
  35. }
  36. func TestStereoEncoderReset(t *testing.T) {
  37. frame := audio.NewFrame(0.1, -0.1)
  38. enc := NewStereoEncoder(228000)
  39. initial := make([]float64, 4)
  40. for i := range initial { initial[i] = enc.Encode(frame).Pilot }
  41. enc.Reset()
  42. for i := range initial {
  43. if math.Abs(initial[i]-enc.Encode(frame).Pilot) > 1e-9 { t.Fatalf("reset failed at %d", i) }
  44. }
  45. }