Optimized batch callback with results from C
This commit is contained in:
parent
837c1db011
commit
b0d46ec375
17
goborator.go
17
goborator.go
|
@ -4,9 +4,9 @@ package goborator
|
|||
#cgo pkg-config: cgaborator
|
||||
#include <cgaborator.h>
|
||||
|
||||
void cgoCallback(uintptr_t callback_data, float* data, int size);
|
||||
void cgoCallback(uintptr_t callback_data, float* data, size_t size, size_t slice_size);
|
||||
|
||||
typedef void (*gaborator_transform_callback)(uintptr_t callback_data, float* data, int size);
|
||||
typedef void (*gaborator_transform_callback)(uintptr_t callback_data, float* data, size_t size, size_t slice_size);
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
|
@ -100,6 +100,12 @@ func (g *Gaborator) GaborTransform(source chan float32) (channel chan []float32)
|
|||
}
|
||||
}
|
||||
//finish
|
||||
if len(audioData) > 0 {
|
||||
err := g.Process(audioData)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
err := g.Process(nil)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
@ -151,8 +157,11 @@ func (g *Gaborator) analyze(block []float32) {
|
|||
}
|
||||
|
||||
//export cgoCallback
|
||||
func cgoCallback(ptr C.uintptr_t, data *C.float, size C.int) {
|
||||
func cgoCallback(ptr C.uintptr_t, data *C.float, size, sliceSize C.size_t) {
|
||||
buf := make([]float32, size)
|
||||
channel := cgo.Handle(ptr).Value().(chan []float32)
|
||||
copy(buf, unsafe.Slice((*float32)(data), int(size)))
|
||||
cgo.Handle(ptr).Value().(chan []float32) <- buf
|
||||
for i := 0; i < int(size); i += int(sliceSize) {
|
||||
channel <- buf[i : i+int(sliceSize)]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue