goborator/goborator_test.go
DataHoarder 6476c8414b
All checks were successful
continuous-integration/drone/push Build is passing
Use slices.Clone instead of copy()
2022-12-12 18:36:59 +01:00

55 lines
917 B
Go

package goborator
import (
"fmt"
"golang.org/x/exp/slices"
"os"
"testing"
"time"
"unsafe"
)
func TestGoborator(t *testing.T) {
ob := NewGaborator(1<<17, 16000, 85, 110, 7040, 440, 128)
defer ob.ProcessingFinished()
file, err := os.Open("sample/test.raw")
if err != nil {
t.Error(err)
return
}
channel := make(chan []float32)
go func() {
defer close(channel)
defer file.Close()
buf := make([]byte, ob.GetBlockSize()*4)
for {
n, err := file.Read(buf)
if n > 4 {
channel <- slices.Clone(unsafe.Slice((*float32)(unsafe.Pointer(&buf[0])), n/4))
}
if err != nil {
return
}
}
}()
start := time.Now()
var data [][]float32
for c := range ob.GaborBlockTransform(channel) {
data = append(data, c)
}
end := time.Now().Sub(start).Milliseconds()
/*for i, c := range data {
fmt.Printf("%d: %+F\n", i, c)
}*/
fmt.Printf("total: %d, %dms\n", len(data), end)
}