Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

71 рядки
1.6KB

  1. package main
  2. import (
  3. "context"
  4. "encoding/binary"
  5. "fmt"
  6. "os"
  7. "time"
  8. "github.com/jan/fm-rds-tx/internal/output"
  9. "github.com/jan/fm-rds-tx/internal/platform"
  10. )
  11. func main() {
  12. ctx := context.Background()
  13. fb, err := output.NewFileBackend("examples/simulated_mpx.iq", binary.LittleEndian, output.BackendInfo{
  14. Name: "example-file",
  15. Description: "Captures simulated Soapy output for later playback.",
  16. })
  17. if err != nil {
  18. fmt.Fprintf(os.Stderr, "failed to open file backend: %v\n", err)
  19. os.Exit(1)
  20. }
  21. defer fb.Close(ctx)
  22. cfg := platform.SoapyConfig{
  23. Driver: "simulated",
  24. Device: "dummy",
  25. CenterFreqHz: 100e6,
  26. Simulated: true,
  27. BackendConfig: output.BackendConfig{
  28. SampleRateHz: 238_000,
  29. Channels: 2,
  30. IQLevel: 1.0,
  31. Metadata: map[string]string{"example": "soapy-sim"},
  32. },
  33. }
  34. driver := platform.NewSimulatedDriver(fb)
  35. backend := platform.NewSoapyBackend(cfg, driver)
  36. if err := backend.Configure(ctx, cfg.BackendConfig); err != nil {
  37. fmt.Fprintf(os.Stderr, "backend configure: %v\n", err)
  38. os.Exit(1)
  39. }
  40. frame := &output.CompositeFrame{
  41. SampleRateHz: cfg.BackendConfig.SampleRateHz,
  42. Timestamp: time.Now(),
  43. Samples: make([]output.IQSample, 512),
  44. }
  45. for idx := range frame.Samples {
  46. val := float32((idx%64))/32 - 1
  47. frame.Samples[idx].I = val
  48. frame.Samples[idx].Q = -val
  49. }
  50. written, err := backend.Write(ctx, frame)
  51. if err != nil {
  52. fmt.Fprintf(os.Stderr, "write frame: %v\n", err)
  53. os.Exit(1)
  54. }
  55. fmt.Printf("wrote %d samples to simulated Soapy backend\n", written)
  56. if err := backend.Flush(ctx); err != nil {
  57. fmt.Fprintf(os.Stderr, "flush: %v\n", err)
  58. }
  59. }