Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

39 rindas
854B

  1. package rds
  2. import "strings"
  3. // normalizePS produces exactly 8 ASCII bytes for the RDS Program Service name.
  4. // Non-ASCII runes are replaced with space to avoid mid-rune truncation.
  5. func normalizePS(ps string) string {
  6. ps = strings.ToUpper(ps)
  7. clean := toASCII(ps)
  8. if len(clean) > 8 {
  9. clean = clean[:8]
  10. }
  11. if len(clean) < 8 {
  12. clean = clean + strings.Repeat(" ", 8-len(clean))
  13. }
  14. return clean
  15. }
  16. // normalizeRT produces up to 64 ASCII bytes for RDS RadioText.
  17. func normalizeRT(rt string) string {
  18. clean := toASCII(rt)
  19. if len(clean) > 64 {
  20. clean = clean[:64]
  21. }
  22. return clean
  23. }
  24. // toASCII replaces any non-ASCII byte with space.
  25. // RDS uses EBU Latin which is close to ASCII for the printable range.
  26. func toASCII(s string) string {
  27. b := []byte(s)
  28. for i, c := range b {
  29. if c < 0x20 || c > 0x7E {
  30. b[i] = ' '
  31. }
  32. }
  33. return string(b)
  34. }