-
Notifications
You must be signed in to change notification settings - Fork 0
/
wt.go
65 lines (52 loc) · 1.34 KB
/
wt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package wavelib
/*
#cgo LDFLAGS: -lm -lwavelib
#include <wavelib.h>
*/
import "C"
import (
"reflect"
"runtime"
"unsafe"
)
type WTObject struct {
C_WTObject C.wt_object
}
func WTInit(wave WaveObject, method string, sigLength int, j int) WTObject {
return WTObject{C_WTObject: C.wt_init(wave.C_WaveObject, C.CString(method), C.int(sigLength), C.int(j))}
}
func (wt WTObject) Free() {
WTFree(wt)
}
func (wt WTObject) OutLength() int {
return int(wt.C_WTObject.outlength)
}
func (wt WTObject) Output() []float64 {
length := wt.OutLength()
sliceHdr := &reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(wt.C_WTObject.output)),
Cap: length,
Len: length,
}
return *(*[]float64)(unsafe.Pointer(sliceHdr))
}
func (wt WTObject) SigLength() int {
return int(wt.C_WTObject.siglength)
}
func WTFree(wt WTObject) {
C.wt_free(wt.C_WTObject)
}
func SetWTConv(wt WTObject, cmethod string) {
C.setWTConv(wt.C_WTObject, C.CString(cmethod))
}
func SWT(wt WTObject, inp []float64) {
C.swt(wt.C_WTObject, (*C.double)((unsafe.Pointer)((*reflect.SliceHeader)((unsafe.Pointer)(&inp)).Data)))
runtime.KeepAlive(inp)
}
func ISWT(wt WTObject, swtop []float64) {
C.iswt(wt.C_WTObject, (*C.double)((unsafe.Pointer)((*reflect.SliceHeader)((unsafe.Pointer)(&swtop)).Data)))
runtime.KeepAlive(swtop)
}
func WTSummary(wt WTObject) {
C.wt_summary(wt.C_WTObject)
}