jamie@1
|
1 /* libxtract feature extraction library
|
jamie@1
|
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@1
|
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@43
|
27 int xtract_flux(const float *data, const int N, const void *argv , float *result){
|
jamie@1
|
28
|
jamie@117
|
29 /* FIX: don't be lazy -- take the lnorm of the difference vector! */
|
jamie@106
|
30 return xtract_lnorm(data, N, argv, result);
|
jamie@105
|
31
|
jamie@106
|
32 }
|
jamie@106
|
33
|
jamie@106
|
34 int xtract_lnorm(const float *data, const int N, const void *argv , float *result){
|
jamie@106
|
35
|
jamie@107
|
36 int n,
|
jamie@106
|
37 type;
|
jamie@106
|
38
|
jamie@111
|
39 float order;
|
jamie@106
|
40
|
jamie@106
|
41 order = *(float *)argv;
|
jamie@111
|
42 type = *((float *)argv+1);
|
jamie@106
|
43
|
jamie@108
|
44 order = order > 0 ? order : 2.f;
|
jamie@106
|
45
|
jamie@111
|
46 *result = 0.f;
|
jamie@111
|
47
|
jamie@106
|
48 switch(type){
|
jamie@106
|
49
|
jamie@106
|
50 case XTRACT_POSITIVE_SLOPE:
|
jamie@106
|
51 for(n = 0; n < N; n++){
|
jamie@106
|
52 if(data[n] > 0)
|
jamie@111
|
53 *result += powf(data[n], order);
|
jamie@106
|
54 }
|
jamie@106
|
55 break;
|
jamie@106
|
56 default:
|
jamie@106
|
57 for(n = 0; n < N; n++)
|
jamie@106
|
58 *result += powf(data[n], order);
|
jamie@106
|
59 break;
|
jamie@106
|
60
|
jamie@106
|
61 }
|
jamie@106
|
62
|
jamie@106
|
63 *result = powf(*result, 1.f / order);
|
jamie@106
|
64
|
jamie@106
|
65 return XTRACT_SUCCESS;
|
jamie@1
|
66
|
jamie@1
|
67 }
|
jamie@1
|
68
|
jamie@43
|
69 int xtract_attack_time(const float *data, const int N, const void *argv , float *result){
|
jamie@1
|
70
|
jamie@56
|
71 return XTRACT_FEATURE_NOT_IMPLEMENTED;
|
jamie@1
|
72
|
jamie@1
|
73 }
|
jamie@1
|
74
|
jamie@43
|
75 int xtract_decay_time(const float *data, const int N, const void *argv, float *result){
|
jamie@1
|
76
|
jamie@56
|
77 return XTRACT_FEATURE_NOT_IMPLEMENTED;
|
jamie@1
|
78
|
jamie@1
|
79 }
|
jamie@1
|
80
|
jamie@106
|
81 int xtract_difference_vector(const float *data, const int N, const void *argv, float *result){
|
jamie@1
|
82
|
jamie@107
|
83 const float *frame1,
|
jamie@106
|
84 *frame2;
|
jamie@106
|
85
|
jamie@106
|
86 int n;
|
jamie@106
|
87
|
jamie@106
|
88 n = N >> 1;
|
jamie@106
|
89
|
jamie@106
|
90 frame1 = data;
|
jamie@106
|
91 frame2 = data + n;
|
jamie@106
|
92
|
jamie@106
|
93 while(n--)
|
jamie@106
|
94 result[n] = frame1[n] - frame2[n];
|
jamie@106
|
95
|
jamie@106
|
96 return XTRACT_SUCCESS;
|
jamie@1
|
97
|
jamie@1
|
98 }
|