jamie@141
|
1 /*
|
jamie@141
|
2 * Copyright (C) 2012 Jamie Bullock
|
jamie@140
|
3 *
|
jamie@141
|
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
|
jamie@141
|
5 * of this software and associated documentation files (the "Software"), to
|
jamie@141
|
6 * deal in the Software without restriction, including without limitation the
|
jamie@141
|
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
jamie@141
|
8 * sell copies of the Software, and to permit persons to whom the Software is
|
jamie@141
|
9 * furnished to do so, subject to the following conditions:
|
jamie@1
|
10 *
|
jamie@141
|
11 * The above copyright notice and this permission notice shall be included in
|
jamie@141
|
12 * all copies or substantial portions of the Software.
|
jamie@1
|
13 *
|
jamie@141
|
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
jamie@141
|
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
jamie@141
|
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
jamie@141
|
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
jamie@141
|
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
jamie@141
|
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
jamie@141
|
20 * IN THE SOFTWARE.
|
jamie@1
|
21 *
|
jamie@1
|
22 */
|
jamie@1
|
23
|
jamie@1
|
24 /* xtract_delta.c: defines functions that extract a feature as a single value from more than one input vector */
|
jamie@1
|
25
|
jamie@106
|
26 #include <math.h>
|
jamie@106
|
27
|
jamie@38
|
28 #include "xtract/libxtract.h"
|
jamie@1
|
29
|
jamie@140
|
30 int xtract_flux(const float *data, const int N, const void *argv , float *result)
|
jamie@140
|
31 {
|
jamie@1
|
32
|
jamie@117
|
33 /* FIX: don't be lazy -- take the lnorm of the difference vector! */
|
jamie@106
|
34 return xtract_lnorm(data, N, argv, result);
|
jamie@105
|
35
|
jamie@106
|
36 }
|
jamie@106
|
37
|
jamie@140
|
38 int xtract_lnorm(const float *data, const int N, const void *argv , float *result)
|
jamie@140
|
39 {
|
jamie@106
|
40
|
jamie@107
|
41 int n,
|
jamie@106
|
42 type;
|
jamie@106
|
43
|
jamie@111
|
44 float order;
|
jamie@106
|
45
|
jamie@106
|
46 order = *(float *)argv;
|
jamie@111
|
47 type = *((float *)argv+1);
|
jamie@106
|
48
|
jamie@108
|
49 order = order > 0 ? order : 2.f;
|
jamie@106
|
50
|
jamie@111
|
51 *result = 0.f;
|
jamie@111
|
52
|
jamie@140
|
53 switch(type)
|
jamie@140
|
54 {
|
jamie@106
|
55
|
jamie@140
|
56 case XTRACT_POSITIVE_SLOPE:
|
jamie@140
|
57 for(n = 0; n < N; n++)
|
jamie@140
|
58 {
|
jamie@140
|
59 if(data[n] > 0)
|
jamie@106
|
60 *result += powf(data[n], order);
|
jamie@140
|
61 }
|
jamie@140
|
62 break;
|
jamie@140
|
63 default:
|
jamie@140
|
64 for(n = 0; n < N; n++)
|
jamie@140
|
65 *result += powf(data[n], order);
|
jamie@140
|
66 break;
|
jamie@106
|
67
|
jamie@106
|
68 }
|
jamie@106
|
69
|
jamie@106
|
70 *result = powf(*result, 1.f / order);
|
jamie@106
|
71
|
jamie@106
|
72 return XTRACT_SUCCESS;
|
jamie@1
|
73
|
jamie@1
|
74 }
|
jamie@1
|
75
|
jamie@140
|
76 int xtract_attack_time(const float *data, const int N, const void *argv , float *result)
|
jamie@140
|
77 {
|
jamie@1
|
78
|
jamie@56
|
79 return XTRACT_FEATURE_NOT_IMPLEMENTED;
|
jamie@1
|
80
|
jamie@1
|
81 }
|
jamie@1
|
82
|
jamie@140
|
83 int xtract_decay_time(const float *data, const int N, const void *argv, float *result)
|
jamie@140
|
84 {
|
jamie@1
|
85
|
jamie@56
|
86 return XTRACT_FEATURE_NOT_IMPLEMENTED;
|
jamie@1
|
87
|
jamie@1
|
88 }
|
jamie@1
|
89
|
jamie@140
|
90 int xtract_difference_vector(const float *data, const int N, const void *argv, float *result)
|
jamie@140
|
91 {
|
jamie@1
|
92
|
jamie@107
|
93 const float *frame1,
|
jamie@106
|
94 *frame2;
|
jamie@106
|
95
|
jamie@106
|
96 int n;
|
jamie@106
|
97
|
jamie@106
|
98 n = N >> 1;
|
jamie@106
|
99
|
jamie@106
|
100 frame1 = data;
|
jamie@106
|
101 frame2 = data + n;
|
jamie@106
|
102
|
jamie@106
|
103 while(n--)
|
jamie@106
|
104 result[n] = frame1[n] - frame2[n];
|
jamie@106
|
105
|
jamie@106
|
106 return XTRACT_SUCCESS;
|
jamie@1
|
107
|
jamie@1
|
108 }
|