-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemporal.go
132 lines (115 loc) · 3.26 KB
/
temporal.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Copyright 2013 Jeremy Wall ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
*/
package aubio
/*
#cgo LDFLAGS: -laubio
#include <aubio/aubio.h>
*/
import "C"
// Filter is a wrapper for the aubio_filter_t object.
type Filter struct {
o *C.aubio_filter_t
buf *SimpleBuffer
}
// Constructs a Filter. Filters maintain their own working buffer
// which will get freed when the Filters Free method is called.
// The caller is responsible for calling Free on the constructed
// Filter or risk leaking memory.
func NewFilter(order, bufSize uint) (*Filter, error) {
f, err := C.new_aubio_filter(C.uint_t(order))
if f == nil {
return nil, err
}
return &Filter{o: f, buf: NewSimpleBuffer(bufSize)}, nil
}
// Free frees up the memory allocatd by aubio for this Filter.
func (f *Filter) Free() {
if f.o != nil {
C.del_aubio_filter(f.o)
f.o = nil
}
if f.buf != nil {
f.buf.Free()
f.buf = nil
}
}
// Reset resets the memory for this Filter.
func (f *Filter) Reset() {
if f.o != nil {
C.aubio_filter_do_reset(f.o)
}
}
// Buffer returns the output buffer for this Filter.
// The buffer is populated by calls to DoOutplace and is owned
// by the Filter object.
// Subsequent calls to DoOutplace may change the data contained in
// this buffer.
func (f *Filter) Buffer() *SimpleBuffer {
return f.buf
}
// SetSamplerate sets the samplerate for this Filter.
func (f *Filter) SetSamplerate(rate uint) {
if f.o != nil {
C.aubio_filter_set_samplerate(f.o, C.uint_t(rate))
}
}
// Do does an in-place filter on the input vector.
// The output buffer is not used.
func (f *Filter) Do(in *SimpleBuffer) {
// Filter in-place
if f.o != nil {
C.aubio_filter_do(f.o, in.vec)
}
}
// TODO(jwall): maybe the outplace filter should be a seperate type?
// DoOutPlace does filters the input vector into the Filter's output
// Buffer. Each call to this method will change the data contained
// in the output buffer. This buffer can be retrieved though the
// Buffer method.
func (f *Filter) DoOutplace(in *SimpleBuffer) {
if f.o != nil {
C.aubio_filter_do_outplace(f.o, in.vec, f.buf.vec)
}
}
// DoFwdBack runs the aubio_filter_do_filtfilt function on this
// Filter.
func (f *Filter) DoFwdBack(in *SimpleBuffer, workBufSize uint) {
if f.o != nil {
tmp := NewSimpleBuffer(workBufSize)
defer tmp.Free()
C.aubio_filter_do_filtfilt(f.o, in.vec, tmp.vec)
}
}
// Feedback returns the buffer containing the feedback coefficients.
func (f *Filter) Feedback() *LongSampleBuffer {
if f.o != nil {
return newLBufferFromVec(C.aubio_filter_get_feedback(f.o))
}
return nil
}
// Feedback returns the buffer containing the feedforward coefficients.
func (f *Filter) Feedforward() *LongSampleBuffer {
if f.o != nil {
return newLBufferFromVec(C.aubio_filter_get_feedforward(f.o))
}
return nil
}
// Order returns this Filters order.
func (f *Filter) Order() uint {
if f.o != nil {
return uint(C.aubio_filter_get_order(f.o))
}
return 0
}
// Samplerate returns this Filters samplerate.
func (f *Filter) Samplerate() uint {
if f.o != nil {
return uint(C.aubio_filter_get_samplerate(f.o))
}
return 0
}