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ů.

47 řádky
1.0KB

  1. package dsp
  2. import (
  3. "math"
  4. "testing"
  5. )
  6. func TestMPXLimiterPassesQuiet(t *testing.T) {
  7. lim := NewMPXLimiter(1.0, 0.1, 50, 228000)
  8. for i := 0; i < 100; i++ {
  9. in := 0.3 * math.Sin(float64(i))
  10. out := lim.Process(in)
  11. if math.Abs(out-in) > 1e-9 {
  12. t.Fatalf("limiter altered quiet signal at sample %d: in=%.6f out=%.6f", i, in, out)
  13. }
  14. }
  15. }
  16. func TestMPXLimiterClamps(t *testing.T) {
  17. lim := NewMPXLimiter(1.0, 0.01, 50, 228000)
  18. // Feed a signal well above ceiling
  19. var maxOut float64
  20. for i := 0; i < 10000; i++ {
  21. in := 3.0 * math.Sin(2*math.Pi*1000*float64(i)/228000)
  22. out := lim.Process(in)
  23. if math.Abs(out) > maxOut {
  24. maxOut = math.Abs(out)
  25. }
  26. }
  27. // After attack settles, output should approach ceiling
  28. if maxOut > 1.5 {
  29. t.Fatalf("limiter didn't reduce level enough: maxOut=%.4f", maxOut)
  30. }
  31. }
  32. func TestHardClip(t *testing.T) {
  33. if HardClip(1.5, 1.0) != 1.0 {
  34. t.Fatal("expected clip to 1.0")
  35. }
  36. if HardClip(-1.5, 1.0) != -1.0 {
  37. t.Fatal("expected clip to -1.0")
  38. }
  39. if HardClip(0.5, 1.0) != 0.5 {
  40. t.Fatal("expected passthrough")
  41. }
  42. }