jamie@1
|
1 /* libxtract feature extraction library
|
jamie@140
|
2 *
|
jamie@1
|
3 * Copyright (C) 2006 Jamie Bullock
|
jamie@1
|
4 *
|
jamie@1
|
5 * This program is free software; you can redistribute it and/or modify
|
jamie@1
|
6 * it under the terms of the GNU General Public License as published by
|
jamie@1
|
7 * the Free Software Foundation; either version 2 of the License, or
|
jamie@1
|
8 * (at your option) any later version.
|
jamie@1
|
9 *
|
jamie@1
|
10 * This program is distributed in the hope that it will be useful,
|
jamie@1
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jamie@1
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jamie@1
|
13 * GNU General Public License for more details.
|
jamie@1
|
14 *
|
jamie@1
|
15 * You should have received a copy of the GNU General Public License
|
jamie@1
|
16 * along with this program; if not, write to the Free Software
|
jamie@140
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
jamie@1
|
18 * USA.
|
jamie@1
|
19 */
|
jamie@1
|
20
|
jamie@1
|
21 /* xtract_delta.c: defines functions that extract a feature as a single value from more than one input vector */
|
jamie@1
|
22
|
jamie@106
|
23 #include <math.h>
|
jamie@106
|
24
|
jamie@38
|
25 #include "xtract/libxtract.h"
|
jamie@1
|
26
|
jamie@140
|
27 int xtract_flux(const float *data, const int N, const void *argv , float *result)
|
jamie@140
|
28 {
|
jamie@1
|
29
|
jamie@117
|
30 /* FIX: don't be lazy -- take the lnorm of the difference vector! */
|
jamie@106
|
31 return xtract_lnorm(data, N, argv, result);
|
jamie@105
|
32
|
jamie@106
|
33 }
|
jamie@106
|
34
|
jamie@140
|
35 int xtract_lnorm(const float *data, const int N, const void *argv , float *result)
|
jamie@140
|
36 {
|
jamie@106
|
37
|
jamie@107
|
38 int n,
|
jamie@106
|
39 type;
|
jamie@106
|
40
|
jamie@111
|
41 float order;
|
jamie@106
|
42
|
jamie@106
|
43 order = *(float *)argv;
|
jamie@111
|
44 type = *((float *)argv+1);
|
jamie@106
|
45
|
jamie@108
|
46 order = order > 0 ? order : 2.f;
|
jamie@106
|
47
|
jamie@111
|
48 *result = 0.f;
|
jamie@111
|
49
|
jamie@140
|
50 switch(type)
|
jamie@140
|
51 {
|
jamie@106
|
52
|
jamie@140
|
53 case XTRACT_POSITIVE_SLOPE:
|
jamie@140
|
54 for(n = 0; n < N; n++)
|
jamie@140
|
55 {
|
jamie@140
|
56 if(data[n] > 0)
|
jamie@106
|
57 *result += powf(data[n], order);
|
jamie@140
|
58 }
|
jamie@140
|
59 break;
|
jamie@140
|
60 default:
|
jamie@140
|
61 for(n = 0; n < N; n++)
|
jamie@140
|
62 *result += powf(data[n], order);
|
jamie@140
|
63 break;
|
jamie@106
|
64
|
jamie@106
|
65 }
|
jamie@106
|
66
|
jamie@106
|
67 *result = powf(*result, 1.f / order);
|
jamie@106
|
68
|
jamie@106
|
69 return XTRACT_SUCCESS;
|
jamie@1
|
70
|
jamie@1
|
71 }
|
jamie@1
|
72
|
jamie@140
|
73 int xtract_attack_time(const float *data, const int N, const void *argv , float *result)
|
jamie@140
|
74 {
|
jamie@1
|
75
|
jamie@56
|
76 return XTRACT_FEATURE_NOT_IMPLEMENTED;
|
jamie@1
|
77
|
jamie@1
|
78 }
|
jamie@1
|
79
|
jamie@140
|
80 int xtract_decay_time(const float *data, const int N, const void *argv, float *result)
|
jamie@140
|
81 {
|
jamie@1
|
82
|
jamie@56
|
83 return XTRACT_FEATURE_NOT_IMPLEMENTED;
|
jamie@1
|
84
|
jamie@1
|
85 }
|
jamie@1
|
86
|
jamie@140
|
87 int xtract_difference_vector(const float *data, const int N, const void *argv, float *result)
|
jamie@140
|
88 {
|
jamie@1
|
89
|
jamie@107
|
90 const float *frame1,
|
jamie@106
|
91 *frame2;
|
jamie@106
|
92
|
jamie@106
|
93 int n;
|
jamie@106
|
94
|
jamie@106
|
95 n = N >> 1;
|
jamie@106
|
96
|
jamie@106
|
97 frame1 = data;
|
jamie@106
|
98 frame2 = data + n;
|
jamie@106
|
99
|
jamie@106
|
100 while(n--)
|
jamie@106
|
101 result[n] = frame1[n] - frame2[n];
|
jamie@106
|
102
|
jamie@106
|
103 return XTRACT_SUCCESS;
|
jamie@1
|
104
|
jamie@1
|
105 }
|