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.

29 lines
761B

  1. package audio
  2. type ResampledSource struct {
  3. src *WAVSource
  4. ratio float64
  5. position float64
  6. }
  7. func NewResampledSource(src *WAVSource, targetSampleRate float64) *ResampledSource {
  8. ratio := 1.0
  9. if src != nil && src.SampleRate > 0 && targetSampleRate > 0 {
  10. ratio = float64(src.SampleRate) / targetSampleRate
  11. }
  12. return &ResampledSource{src: src, ratio: ratio}
  13. }
  14. func (s *ResampledSource) NextFrame() Frame {
  15. if s.src == nil || len(s.src.frames) == 0 {
  16. return NewFrame(0, 0)
  17. }
  18. idx := int(s.position) % len(s.src.frames)
  19. frame := s.src.frames[idx]
  20. s.position += s.ratio
  21. for s.position >= float64(len(s.src.frames)) {
  22. s.position -= float64(len(s.src.frames))
  23. }
  24. return frame
  25. }