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.

67 line
1.7KB

  1. package aoiprxkit
  2. import (
  3. "errors"
  4. "fmt"
  5. "net"
  6. "time"
  7. )
  8. // Config defines a pragmatic RX-only subset for statically configured AES67-style RTP audio.
  9. // It is intentionally narrower than full AES67.
  10. type Config struct {
  11. MulticastGroup string
  12. Port int
  13. InterfaceName string
  14. PayloadType uint8
  15. SampleRateHz int
  16. Channels int
  17. Encoding string
  18. PacketTime time.Duration
  19. JitterDepthPackets int
  20. ReadBufferBytes int
  21. }
  22. func DefaultConfig() Config {
  23. return Config{
  24. MulticastGroup: "239.69.0.1",
  25. Port: 5004,
  26. PayloadType: 97,
  27. SampleRateHz: 48000,
  28. Channels: 2,
  29. Encoding: "L24",
  30. PacketTime: time.Millisecond,
  31. JitterDepthPackets: 8,
  32. ReadBufferBytes: 1 << 20,
  33. }
  34. }
  35. func (c Config) Validate() error {
  36. if ip := net.ParseIP(c.MulticastGroup); ip == nil || ip.To4() == nil {
  37. return fmt.Errorf("invalid IPv4 multicast group: %q", c.MulticastGroup)
  38. }
  39. ip := net.ParseIP(c.MulticastGroup).To4()
  40. if ip[0] < 224 || ip[0] > 239 {
  41. return fmt.Errorf("multicast group must be IPv4 multicast: %q", c.MulticastGroup)
  42. }
  43. if c.Port < 1 || c.Port > 65535 {
  44. return errors.New("port must be 1..65535")
  45. }
  46. if c.SampleRateHz <= 0 {
  47. return errors.New("sample rate must be > 0")
  48. }
  49. if c.Channels < 1 || c.Channels > 2 {
  50. return errors.New("channels must be 1 or 2")
  51. }
  52. if c.Encoding != "L24" {
  53. return fmt.Errorf("unsupported encoding %q: only L24 is currently supported", c.Encoding)
  54. }
  55. if c.PacketTime <= 0 {
  56. return errors.New("packet time must be > 0")
  57. }
  58. if c.JitterDepthPackets < 1 {
  59. return errors.New("jitter depth must be >= 1")
  60. }
  61. return nil
  62. }