style(tracker): use for range loops everywhere in detector.go

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2025-04-30 16:24:48 +03:00
parent afc6b1f4a9
commit 0199658025

View File

@ -230,13 +230,13 @@ func (d *loudnessDetector) update(chunk sointu.AudioBuffer) LoudnessResult {
setSliceLength(&d.tmp2, l) setSliceLength(&d.tmp2, l)
setSliceLength(&d.tmpbool, l) setSliceLength(&d.tmpbool, l)
var total float32 var total float32
for chn := 0; chn < 2; chn++ { for chn := range 2 {
// deinterleave the channels // deinterleave the channels
for i := 0; i < len(chunk); i++ { for i := range chunk {
d.tmp[i] = chunk[i][chn] d.tmp[i] = chunk[i][chn]
} }
// filter the signal with the weighting filter // filter the signal with the weighting filter
for k := 0; k < len(d.weighting); k++ { for k := range d.weighting {
d.states[chn][k].Filter(d.tmp[:len(chunk)], d.weighting[k]) d.states[chn][k].Filter(d.tmp[:len(chunk)], d.weighting[k])
} }
// square the samples // square the samples
@ -302,7 +302,7 @@ func decibelToPower(loudness Decibel) float32 {
func (state *biquadState) Filter(buffer []float32, coeff biquadCoeff) { func (state *biquadState) Filter(buffer []float32, coeff biquadCoeff) {
s := *state s := *state
for i := 0; i < len(buffer); i++ { for i := range buffer {
x := buffer[i] x := buffer[i]
y := coeff.b0*x + coeff.b1*s.x1 + coeff.b2*s.x2 - coeff.a1*s.y1 - coeff.a2*s.y2 y := coeff.b0*x + coeff.b1*s.x1 + coeff.b2*s.x2 - coeff.a1*s.y1 - coeff.a2*s.y2
s.x2, s.x1 = s.x1, x s.x2, s.x1 = s.x1, x