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@107
|
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@107
|
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@107
|
21 *
|
jamie@107
|
22 */
|
jamie@107
|
23
|
jamie@107
|
24 /* helper.c: helper functions. */
|
jamie@107
|
25
|
jamie@113
|
26 #include <config.h>
|
jamie@113
|
27
|
jamie@113
|
28 #include <stdio.h>
|
jamie@113
|
29
|
jamie@107
|
30 #include "xtract/libxtract.h"
|
jamie@107
|
31
|
jamie@113
|
32 #ifdef WORDS_BIGENDIAN
|
jamie@113
|
33 #define INDEX 0
|
jamie@113
|
34 #else
|
jamie@113
|
35 #define INDEX 1
|
jamie@113
|
36 #endif
|
jamie@113
|
37
|
jamie@140
|
38 int xtract_windowed(const float *data, const int N, const void *argv, float *result)
|
jamie@140
|
39 {
|
jamie@107
|
40
|
jamie@107
|
41 int n;
|
jamie@107
|
42 const float *window;
|
jamie@107
|
43
|
jamie@107
|
44 n = N;
|
jamie@107
|
45 window = (const float *)argv;
|
jamie@107
|
46
|
jamie@107
|
47 while(n--)
|
jamie@107
|
48 result[n] = data[n] * window[n];
|
jamie@107
|
49
|
jamie@107
|
50 return XTRACT_SUCCESS;
|
jamie@107
|
51
|
jamie@107
|
52 }
|
jamie@107
|
53
|
jamie@140
|
54 int xtract_features_from_subframes(const float *data, const int N, const int feature, const void *argv, float *result)
|
jamie@140
|
55 {
|
jamie@107
|
56
|
jamie@107
|
57 const float *frame1,
|
jamie@107
|
58 *frame2;
|
jamie@107
|
59 float *result1,
|
jamie@107
|
60 *result2;
|
jamie@107
|
61
|
jamie@113
|
62 int n, rv;
|
jamie@107
|
63
|
jamie@107
|
64 n = N >> 1;
|
jamie@107
|
65
|
jamie@107
|
66 frame1 = data;
|
jamie@107
|
67 frame2 = data + n;
|
jamie@107
|
68 result1 = result;
|
jamie@107
|
69 result2 = result + n;
|
jamie@107
|
70
|
jamie@107
|
71 rv = xtract[feature](frame1, n, argv, result1);
|
jamie@107
|
72
|
jamie@107
|
73 if(rv == XTRACT_SUCCESS)
|
jamie@107
|
74 rv = xtract[feature](frame2, n, argv, result2);
|
jamie@107
|
75
|
jamie@107
|
76 return rv;
|
jamie@107
|
77
|
jamie@107
|
78 }
|
jamie@113
|
79
|
jamie@140
|
80 inline int xtract_is_denormal(double const d)
|
jamie@140
|
81 {
|
jamie@113
|
82 if(sizeof(d) != 2 * sizeof(int))
|
jamie@113
|
83 fprintf(stderr, "libxtract: Error: xtract_is_denormal() detects inconsistent wordlength for type 'double'\n");
|
jamie@113
|
84
|
jamie@113
|
85 int l = ((int *)&d)[INDEX];
|
jamie@113
|
86 return (l&0x7ff00000) == 0 && d!=0; //Check for 0 may not be necessary
|
jamie@113
|
87 }
|
jamie@113
|
88
|
jamie@140
|
89 inline bool xtract_is_poweroftwo(unsigned int x)
|
jamie@140
|
90 {
|
jamie@140
|
91 return ((x != 0) && !(x & (x - 1)));
|
jamie@140
|
92 }
|
jamie@140
|
93
|