Use new c-goborator

This commit is contained in:
DataHoarder 2022-01-25 13:59:35 +01:00
parent 08f2e306d8
commit 0dbf0c1a59
2 changed files with 11 additions and 7 deletions

View file

@ -28,7 +28,7 @@ type Gaborator struct {
func NewGaborator(blockSize int, sampleRate float64, bandsPerOctave int, minimumFrequency, maximumFrequency, referenceFrequency float64, stepSize int) *Gaborator {
g := &Gaborator{
pointer: unsafe.Pointer(C.gaborator_initialize(C.int(blockSize), C.double(sampleRate), C.int(bandsPerOctave), C.double(minimumFrequency), C.double(maximumFrequency), C.double(referenceFrequency))),
pointer: unsafe.Pointer(C.gaborator_initialize(C.double(sampleRate), C.int(bandsPerOctave), C.double(minimumFrequency), C.double(maximumFrequency), C.double(referenceFrequency))),
sampleRate: sampleRate,
audioBlockSize: blockSize,
audioDataToTransform: make([]float32, blockSize),
@ -142,11 +142,11 @@ func (g *Gaborator) GaborTransform(reader io.Reader) [][]float32 {
break
}
audioData = append(audioData, f)
}
//log.Printf("length file in float %d / blocks %d", len(audioData), len(audioData)/g.audioBlockSize)
//TODO: this seems to skip last block?
for floatIndex := 0; floatIndex < len(audioData); floatIndex += g.audioBlockSize {
g.gaborTransform(audioData[floatIndex : floatIndex+g.audioBlockSize])
for len(audioData) >= g.audioBlockSize {
g.gaborTransform(audioData[0:g.audioBlockSize])
audioData = audioData[g.audioBlockSize:]
}
}
g.ProcessingFinished()

View file

@ -1,12 +1,14 @@
package goborator
import (
"fmt"
"os"
"testing"
)
func TestGoborator(t *testing.T) {
ob := NewGaborator(8192, 16000, 85, 110, 7040, 440, 128)
defer ob.ProcessingFinished()
file, err := os.Open("sample/test.raw")
if err != nil {
@ -14,5 +16,7 @@ func TestGoborator(t *testing.T) {
return
}
ob.GaborTransform(file)
for i, c := range ob.GetCoefficients() {
fmt.Printf("%d: %+F\n", i, c)
}
}