From b5ea095a3b52beb324705ea688fc3299dcfabc44 Mon Sep 17 00:00:00 2001 From: Mark Kremer Date: Thu, 1 Aug 2024 19:45:21 +0200 Subject: [PATCH] Use Go 1.21 clear() function --- compositors.go | 4 +--- ctrl.go | 4 +--- generators/silence.go | 8 ++------ mixer.go | 4 +--- streamers.go | 4 +--- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/compositors.go b/compositors.go index cf8a1bd..8dabdb8 100644 --- a/compositors.go +++ b/compositors.go @@ -102,9 +102,7 @@ func Mix(s ...Streamer) Streamer { toStream := min(len(tmp), len(samples)) // clear the samples - for i := range samples[:toStream] { - samples[i] = [2]float64{} - } + clear(samples[:toStream]) snMax := 0 // max number of streamed samples in this iteration for _, st := range s { diff --git a/ctrl.go b/ctrl.go index 6dc7e30..8ca1601 100644 --- a/ctrl.go +++ b/ctrl.go @@ -35,9 +35,7 @@ func (c *Ctrl) Stream(samples [][2]float64) (n int, ok bool) { return 0, false } if c.Paused { - for i := range samples { - samples[i] = [2]float64{} - } + clear(samples) return len(samples), true } return c.Streamer.Stream(samples) diff --git a/generators/silence.go b/generators/silence.go index 9c093d3..d36cea3 100644 --- a/generators/silence.go +++ b/generators/silence.go @@ -7,9 +7,7 @@ import "github.com/gopxl/beep" func Silence(num int) beep.Streamer { if num < 0 { return beep.StreamerFunc(func(samples [][2]float64) (m int, ok bool) { - for i := range samples { - samples[i] = [2]float64{} - } + clear(samples) return len(samples), true }) } @@ -21,9 +19,7 @@ func Silence(num int) beep.Streamer { if num < len(samples) { samples = samples[:num] } - for i := range samples { - samples[i] = [2]float64{} - } + clear(samples) num -= len(samples) return len(samples), true diff --git a/mixer.go b/mixer.go index 77df90e..341c205 100644 --- a/mixer.go +++ b/mixer.go @@ -30,9 +30,7 @@ func (m *Mixer) Stream(samples [][2]float64) (n int, ok bool) { toStream := min(len(tmp), len(samples)) // clear the samples - for i := range samples[:toStream] { - samples[i] = [2]float64{} - } + clear(samples[:toStream]) for si := 0; si < len(m.streamers); si++ { // mix the stream diff --git a/streamers.go b/streamers.go index 34b8e6b..888fdf4 100644 --- a/streamers.go +++ b/streamers.go @@ -12,9 +12,7 @@ func Silence(num int) Streamer { if 0 < num && num < len(samples) { samples = samples[:num] } - for i := range samples { - samples[i] = [2]float64{} - } + clear(samples) if num > 0 { num -= len(samples) }