Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

47 lines
1.2KB

  1. package audio
  2. import (
  3. "math"
  4. "testing"
  5. )
  6. func TestResampledSource(t *testing.T) {
  7. src := &WAVSource{frames: []Frame{NewFrame(0.1, 0.1), NewFrame(0.2, 0.2)}, SampleRate: 48000}
  8. rs := NewResampledSource(src, 96000)
  9. a := rs.NextFrame()
  10. b := rs.NextFrame()
  11. if a == (Frame{}) || b == (Frame{}) {
  12. t.Fatal("expected non-zero frames")
  13. }
  14. }
  15. func TestResampledSourceInterpolation(t *testing.T) {
  16. // 2 samples at 48k, target at 96k -> ratio=0.5, so we should
  17. // get interpolated values between the two source frames.
  18. src := &WAVSource{
  19. frames: []Frame{NewFrame(0, 0), NewFrame(1, 1)},
  20. SampleRate: 48000,
  21. }
  22. rs := NewResampledSource(src, 96000)
  23. // First sample: position=0.0, exact frame[0] -> (0,0)
  24. f0 := rs.NextFrame()
  25. if math.Abs(float64(f0.L)) > 1e-9 {
  26. t.Fatalf("expected L=0 at pos 0, got %.6f", f0.L)
  27. }
  28. // Second sample: position=0.5, interpolated -> (0.5, 0.5)
  29. f1 := rs.NextFrame()
  30. if math.Abs(float64(f1.L)-0.5) > 1e-9 {
  31. t.Fatalf("expected L=0.5 at pos 0.5, got %.6f", f1.L)
  32. }
  33. }
  34. func TestResampledSourceNilSrc(t *testing.T) {
  35. rs := NewResampledSource(nil, 48000)
  36. f := rs.NextFrame()
  37. if f.L != 0 || f.R != 0 {
  38. t.Fatal("expected zero frame for nil source")
  39. }
  40. }