From 5a3c859a5184ecbc49e8847edd19b332896fca00 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sun, 27 Apr 2025 19:28:57 +0300 Subject: [PATCH] fix(tracker): also peak detector windows were in wrong order --- tracker/detector.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tracker/detector.go b/tracker/detector.go index 4e1c556..9ecfaad 100644 --- a/tracker/detector.go +++ b/tracker/detector.go @@ -166,8 +166,8 @@ func makePeakDetector(oversampling bool) peakDetector { return peakDetector{ oversampling: oversampling, windows: [2][2]RingBuffer[float32]{ - {{Buffer: make([]float32, 4)}, {Buffer: make([]float32, 30)}}, // momentary and short-term peaks for left channel - {{Buffer: make([]float32, 4)}, {Buffer: make([]float32, 30)}}, // momentary and short-term peaks for right channel + {{Buffer: make([]float32, 4)}, {Buffer: make([]float32, 4)}}, // momentary peaks + {{Buffer: make([]float32, 30)}, {Buffer: make([]float32, 30)}}, // short-term peaks }, } } @@ -361,9 +361,9 @@ func (d *peakDetector) update(buf sointu.AudioBuffer) (ret PeakResult) { if len(d.tmp2) < len4 { d.tmp2 = append(d.tmp2, make([]float32, len4-len(d.tmp2))...) } - for chn := 0; chn < 2; chn++ { + for chn := range 2 { // deinterleave the channels - for i := 0; i < len(buf); i++ { + for i := range buf { d.tmp[i] = buf[i][chn] } // 4x oversample the signal @@ -386,13 +386,13 @@ func (d *peakDetector) update(buf sointu.AudioBuffer) (ret PeakResult) { } func (d *peakDetector) reset() { - for chn := 0; chn < 2; chn++ { + for chn := range 2 { d.states[chn].history = [11]float32{} for i := range d.windows[chn] { - d.windows[chn][i].Cursor = 0 - l := len(d.windows[chn][i].Buffer) - d.windows[chn][i].Buffer = d.windows[chn][i].Buffer[:0] - d.windows[chn][i].Buffer = append(d.windows[chn][i].Buffer, make([]float32, l)...) + d.windows[i][chn].Cursor = 0 + l := len(d.windows[i][chn].Buffer) + d.windows[i][chn].Buffer = d.windows[i][chn].Buffer[:0] + d.windows[i][chn].Buffer = append(d.windows[i][chn].Buffer, make([]float32, l)...) } d.maxPower[chn] = 0 }