Skip to content

Commit

Permalink
Use Go 1.21 clear() function
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKremer committed Aug 1, 2024
1 parent 80c6ece commit b5ea095
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 18 deletions.
4 changes: 1 addition & 3 deletions compositors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions generators/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions mixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions streamers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b5ea095

Please sign in to comment.