diff --git a/resample.go b/resample.go index 99e6c8a..e79e2a7 100644 --- a/resample.go +++ b/resample.go @@ -57,7 +57,7 @@ func ResampleRatio(quality int, ratio float64, s Streamer) *Resampler { ratio: ratio, buf1: make([][2]float64, resamplerSingleBufferSize), buf2: make([][2]float64, resamplerSingleBufferSize), - pts: make([]point, quality*2+1), + pts: make([]point, quality*2), off: -resamplerSingleBufferSize, pos: 0, end: math.MaxInt, @@ -85,8 +85,8 @@ func (r *Resampler) Stream(samples [][2]float64) (n int, ok bool) { // Determine the quality*2 closest sample positions for the interpolation. // The window has length len(r.pts) and is centered around wantPos. - windowStart := int(wantPos) - len(r.pts)/2 // (inclusive) - windowEnd := int(wantPos) + len(r.pts)/2 + 1 // (exclusive) + windowStart := int(wantPos) - (len(r.pts)-1)/2 // (inclusive) + windowEnd := int(wantPos) + len(r.pts)/2 + 1 // (exclusive) // Prepare the buffers. if windowEnd >= r.off+resamplerSingleBufferSize { diff --git a/resample_test.go b/resample_test.go index 0539cb6..d3009e9 100644 --- a/resample_test.go +++ b/resample_test.go @@ -32,7 +32,7 @@ func TestResample(t *testing.T) { func resampleCorrect(quality int, old, new beep.SampleRate, p [][2]float64) [][2]float64 { ratio := float64(old) / float64(new) - pts := make([]point, quality*2+1) + pts := make([]point, quality*2) var resampled [][2]float64 for i := 0; ; i++ { j := float64(i) * ratio