Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5KB

  1. package ingest
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/jan/fm-rds-tx/internal/audio"
  7. )
  8. type fakeSource struct {
  9. desc SourceDescriptor
  10. chunks chan PCMChunk
  11. errs chan error
  12. stats SourceStats
  13. }
  14. func newFakeSource() *fakeSource {
  15. return &fakeSource{
  16. desc: SourceDescriptor{ID: "fake", Kind: "stdin-pcm"},
  17. chunks: make(chan PCMChunk, 4),
  18. errs: make(chan error, 1),
  19. stats: SourceStats{State: "running", Connected: true},
  20. }
  21. }
  22. func (s *fakeSource) Descriptor() SourceDescriptor { return s.desc }
  23. func (s *fakeSource) Start(context.Context) error { return nil }
  24. func (s *fakeSource) Stop() error { close(s.chunks); return nil }
  25. func (s *fakeSource) Chunks() <-chan PCMChunk { return s.chunks }
  26. func (s *fakeSource) Errors() <-chan error { return s.errs }
  27. func (s *fakeSource) Stats() SourceStats { return s.stats }
  28. func TestRuntimeWritesFramesToStreamSink(t *testing.T) {
  29. sink := audio.NewStreamSource(128, 44100)
  30. src := newFakeSource()
  31. rt := NewRuntime(sink, src)
  32. if err := rt.Start(context.Background()); err != nil {
  33. t.Fatalf("start: %v", err)
  34. }
  35. defer rt.Stop()
  36. src.chunks <- PCMChunk{
  37. Channels: 2,
  38. SampleRateHz: 44100,
  39. Samples: []int32{1000 << 16, -1000 << 16},
  40. }
  41. deadline := time.Now().Add(1 * time.Second)
  42. for sink.Available() < 1 && time.Now().Before(deadline) {
  43. time.Sleep(10 * time.Millisecond)
  44. }
  45. if sink.Available() < 1 {
  46. t.Fatal("expected at least one frame in sink")
  47. }
  48. }