Skip to content

Commit

Permalink
Revert resampler pts length increase
Browse files Browse the repository at this point in the history
The original length of pts made sense because when wantPos is a decimal position like 3.5, you want the window for quality 1 to contain positions 3 and 4. Having a window of 1 more doesn't make sense for that. My previous reasoning for increasing the window size was arguing from the point of wantPosition always being an integer value, which isn't the case.
  • Loading branch information
MarkKremer committed Jul 11, 2024
1 parent 3d1c089 commit 79137fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions resample.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion resample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 79137fc

Please sign in to comment.