goborator/goborator_test.go
DataHoarder 736a80d773
All checks were successful
continuous-integration/drone/push Build is passing
Faster test, add Drone CI
2022-07-13 20:33:40 +02:00

56 lines
936 B
Go

package goborator
import (
"fmt"
"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 {
values := make([]float32, n/4)
copy(values, unsafe.Slice((*float32)(unsafe.Pointer(&buf[0])), n/4))
channel <- values
}
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)
}