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

42 рядки
1.1KB

  1. package stereo
  2. import (
  3. "github.com/jan/fm-rds-tx/internal/audio"
  4. "github.com/jan/fm-rds-tx/internal/dsp"
  5. )
  6. // Components holds the individual MPX components produced by the stereo encoder.
  7. type Components struct {
  8. Mono float64 // L+R baseband
  9. Stereo float64 // L-R baseband on suppressed carrier
  10. Pilot float64 // 19 kHz pilot tone
  11. }
  12. // StereoEncoder generates stereo MPX primitives from stereo audio frames.
  13. type StereoEncoder struct {
  14. pilot dsp.PilotGenerator
  15. LevelStereo float64
  16. }
  17. // NewStereoEncoder creates a StereoEncoder configured for the provided sample rate.
  18. func NewStereoEncoder(sampleRate float64) StereoEncoder {
  19. return StereoEncoder{
  20. pilot: dsp.NewPilotGenerator(sampleRate, 0.1),
  21. LevelStereo: 0.75,
  22. }
  23. }
  24. // Encode converts a stereo frame into MPX components.
  25. func (s *StereoEncoder) Encode(frame audio.Frame) Components {
  26. return Components{
  27. Mono: float64(frame.Mono()),
  28. Stereo: float64(frame.Difference()) * s.LevelStereo,
  29. Pilot: s.pilot.Sample(),
  30. }
  31. }
  32. // Reset restarts the pilot generator phase.
  33. func (s *StereoEncoder) Reset() {
  34. s.pilot.Reset()
  35. }