diff --git a/go.mod b/go.mod index 9f40681..f26cac0 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module git.gammaspectra.live/S.O.N.G/goborator go 1.18 + +require golang.org/x/exp v0.0.0-20221212164502-fae10dda9338 diff --git a/go.sum b/go.sum index e69de29..dbd5d95 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/exp v0.0.0-20221212164502-fae10dda9338 h1:OvjRkcNHnf6/W5FZXSxODbxwD+X7fspczG7Jn/xQVD4= +golang.org/x/exp v0.0.0-20221212164502-fae10dda9338/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= diff --git a/goborator.go b/goborator.go index 8af7a7c..4bd08ff 100644 --- a/goborator.go +++ b/goborator.go @@ -7,6 +7,7 @@ package goborator import "C" import ( "fmt" + "golang.org/x/exp/slices" "log" "runtime" "unsafe" @@ -159,8 +160,7 @@ func (g *Gaborator) analyze(block []float32) { } func (g *Gaborator) outputResult(block []float32, sliceSize int) { - buf := make([]float32, len(block)) - copy(buf, block) + buf := slices.Clone(block) for i := 0; i < len(block); i += sliceSize { g.coefficientOutputChannel <- buf[i : i+sliceSize] diff --git a/goborator_test.go b/goborator_test.go index 94f0dcc..f9c843b 100644 --- a/goborator_test.go +++ b/goborator_test.go @@ -2,6 +2,7 @@ package goborator import ( "fmt" + "golang.org/x/exp/slices" "os" "testing" "time" @@ -29,9 +30,7 @@ func TestGoborator(t *testing.T) { n, err := file.Read(buf) if n > 4 { - values := make([]float32, n/4) - copy(values, unsafe.Slice((*float32)(unsafe.Pointer(&buf[0])), n/4)) - channel <- values + channel <- slices.Clone(unsafe.Slice((*float32)(unsafe.Pointer(&buf[0])), n/4)) } if err != nil { return