Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

47 líneas
993B

  1. package audio
  2. // Sample represents a normalized audio sample in the range [-1, +1].
  3. type Sample float64
  4. const (
  5. SampleMin Sample = -1.0
  6. SampleMax Sample = 1.0
  7. )
  8. // Frame is a stereo pair of audio samples.
  9. type Frame struct {
  10. L Sample
  11. R Sample
  12. }
  13. // NewFrame creates a Frame from the provided left/right samples.
  14. func NewFrame(l, r Sample) Frame {
  15. return Frame{L: l, R: r}
  16. }
  17. // Mono returns the (L+R)/2 signal used in MPX generation.
  18. func (f Frame) Mono() Sample {
  19. return (f.L + f.R) / 2
  20. }
  21. // Difference returns the (L-R)/2 signal used for the stereo subcarrier.
  22. func (f Frame) Difference() Sample {
  23. return (f.L - f.R) / 2
  24. }
  25. // Clamp ensures the sample stays within the legal range.
  26. func (s Sample) Clamp() Sample {
  27. if s > SampleMax {
  28. return SampleMax
  29. }
  30. if s < SampleMin {
  31. return SampleMin
  32. }
  33. return s
  34. }
  35. // Scale adjusts the sample by a gain factor while keeping the result clamped.
  36. func (s Sample) Scale(gain float64) Sample {
  37. return Sample(float64(s) * gain).Clamp()
  38. }