package goborator

import (
	"fmt"
	"os"
	"slices"
	"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
	err = ob.GaborBlockTransform(channel, func(output []float32) {
		data = append(data, output)
	})
	if err != nil {
		t.Fatal(err)
	}

	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)

}
