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
|
%module xtract
%include carrays.i
%include typemaps.i
%{
#include "xtract/xtract_scalar.h"
#include "xtract/xtract_vector.h"
#include "xtract/xtract_helper.h"
#include "xtract/xtract_macros.h"
#include "xtract/xtract_delta.h"
#include "xtract/libxtract.h"
%}
/* Ensure filterbank gets freed */
/** FIX: This doesn't work, or I'm not using properly. For now just add an explicit call to destroy_filterbank() in the target code */
%newobject create_filterbank;
%delobject destroy_filterbank;
/* Helper functions */
%inline %{
xtract_function_descriptor_t
*get_descriptor(xtract_function_descriptor_t *fd, int i){
return &fd[i];
}
/* Return a pointer to memory allocated for a mel filterbank */
xtract_mel_filter *create_filterbank(int n_filters, int blocksize){
float **filters;
xtract_mel_filter *mf;
int n, N;
N = blocksize;
mf = malloc(sizeof(xtract_mel_filter));
mf->n_filters = n_filters;
filters = (float **)malloc(n_filters * sizeof(float *));
for(n = 0; n < n_filters; n++)
filters[n] = (float *)malloc(N * sizeof(float));
mf->filters = filters;
return mf;
}
/* Free a mel filterbank */
void destroy_filterbank(xtract_mel_filter *filterbank){
int i = filterbank->n_filters;
float **filters;
filters = filterbank->filters;
while(i--)
free(filters[i]);
free(filters);
free(filterbank);
}
/* Eventually this should be deprecated */
/* void destroy_filterbank_explicit(float **filterbank, int n_filters){
int i = n_filters;
while(i--)
free(filterbank[i]);
free(filterbank);
}
*/
%}
%array_class(float, floatArray);
%array_class(int, intArray);
%apply float *OUTPUT { float *result };
/* %apply float *INPUT { float *data }; */
%ignore xtract;
%include "xtract/xtract_scalar.h"
/* We have to put xtract_delta declarations inline because it contains a mixture of vector and scalar functions */
%inline %{
int xtract_flux(const float *data, const int N, const void *argv , float *result);
int xtract_lnorm(const float *data, const int N, const void *argv , float *result);
%}
%clear float *result;
%inline %{
int xtract_difference_vector(const float *data, const int N, const void *argv, float *result);
%}
%include "xtract/xtract_vector.h"
%include "xtract/xtract_helper.h"
%include "xtract/xtract_macros.h"
%include "xtract/libxtract.h"
|