Skip to content

Commit

Permalink
Add explanatory comment for initial value of Resampler.off
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKremer committed Jul 31, 2024
1 parent 6fbcee9 commit df94d52
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions resample.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ func ResampleRatio(quality int, ratio float64, s Streamer) *Resampler {
buf1: make([][2]float64, resamplerSingleBufferSize),
buf2: make([][2]float64, resamplerSingleBufferSize),
pts: make([]point, quality*2),
off: -resamplerSingleBufferSize,
pos: 0.0,
end: math.MaxInt,
// The initial value of `off` is set so that the current position is just behind the end
// of buf2:
// current position (0) - len(buf2) = -resamplerSingleBufferSize
// When the Stream() method is called for the first time, it will determine that neither
// buf1 nor buf2 contain the required samples because they are both in the past relative to
// the chosen `off` value. As a result, buf2 will be filled with samples, and `off` will be
// incremented by resamplerSingleBufferSize, making `off` equal to 0. This will align the
// start of buf2 with the current position.
off: -resamplerSingleBufferSize,
pos: 0.0,
end: math.MaxInt,
}
}

Expand Down

0 comments on commit df94d52

Please sign in to comment.