jamie@107
|
1 /* libxtract feature extraction library
|
jamie@107
|
2 *
|
jamie@107
|
3 * Copyright (C) 2006 Jamie Bullock
|
jamie@107
|
4 *
|
jamie@107
|
5 * This program is free software; you can redistribute it and/or modify
|
jamie@107
|
6 * it under the terms of the GNU General Public License as published by
|
jamie@107
|
7 * the Free Software Foundation; either version 2 of the License, or
|
jamie@107
|
8 * (at your option) any later version.
|
jamie@107
|
9 *
|
jamie@107
|
10 * This program is distributed in the hope that it will be useful,
|
jamie@107
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jamie@107
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jamie@107
|
13 * GNU General Public License for more details.
|
jamie@107
|
14 *
|
jamie@107
|
15 * You should have received a copy of the GNU General Public License
|
jamie@107
|
16 * along with this program; if not, write to the Free Software
|
jamie@107
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
jamie@107
|
18 * USA.
|
jamie@107
|
19 */
|
jamie@107
|
20
|
jamie@107
|
21
|
jamie@107
|
22 /* helper.c: helper functions. */
|
jamie@107
|
23
|
jamie@113
|
24 #include <config.h>
|
jamie@113
|
25
|
jamie@113
|
26 #include <stdio.h>
|
jamie@113
|
27
|
jamie@107
|
28 #include "xtract/libxtract.h"
|
jamie@107
|
29
|
jamie@113
|
30 #ifdef WORDS_BIGENDIAN
|
jamie@113
|
31 #define INDEX 0
|
jamie@113
|
32 #else
|
jamie@113
|
33 #define INDEX 1
|
jamie@113
|
34 #endif
|
jamie@113
|
35
|
jamie@107
|
36 int xtract_windowed(const float *data, const int N, const void *argv, float *result){
|
jamie@107
|
37
|
jamie@107
|
38 int n;
|
jamie@107
|
39 const float *window;
|
jamie@107
|
40
|
jamie@107
|
41 n = N;
|
jamie@107
|
42 window = (const float *)argv;
|
jamie@107
|
43
|
jamie@107
|
44 while(n--)
|
jamie@107
|
45 result[n] = data[n] * window[n];
|
jamie@107
|
46
|
jamie@107
|
47 return XTRACT_SUCCESS;
|
jamie@107
|
48
|
jamie@107
|
49 }
|
jamie@107
|
50
|
jamie@107
|
51 int xtract_features_from_subframes(const float *data, const int N, const int feature, const void *argv, float *result){
|
jamie@107
|
52
|
jamie@107
|
53 const float *frame1,
|
jamie@107
|
54 *frame2;
|
jamie@107
|
55 float *result1,
|
jamie@107
|
56 *result2;
|
jamie@107
|
57
|
jamie@113
|
58 int n, rv;
|
jamie@107
|
59
|
jamie@107
|
60 n = N >> 1;
|
jamie@107
|
61
|
jamie@107
|
62 frame1 = data;
|
jamie@107
|
63 frame2 = data + n;
|
jamie@107
|
64 result1 = result;
|
jamie@107
|
65 result2 = result + n;
|
jamie@107
|
66
|
jamie@107
|
67 rv = xtract[feature](frame1, n, argv, result1);
|
jamie@107
|
68
|
jamie@107
|
69 if(rv == XTRACT_SUCCESS)
|
jamie@107
|
70 rv = xtract[feature](frame2, n, argv, result2);
|
jamie@107
|
71
|
jamie@107
|
72 return rv;
|
jamie@107
|
73
|
jamie@107
|
74 }
|
jamie@113
|
75
|
jamie@113
|
76 inline int xtract_is_denormal(double const d){
|
jamie@113
|
77 if(sizeof(d) != 2 * sizeof(int))
|
jamie@113
|
78 fprintf(stderr, "libxtract: Error: xtract_is_denormal() detects inconsistent wordlength for type 'double'\n");
|
jamie@113
|
79
|
jamie@113
|
80 int l = ((int *)&d)[INDEX];
|
jamie@113
|
81 return (l&0x7ff00000) == 0 && d!=0; //Check for 0 may not be necessary
|
jamie@113
|
82 }
|
jamie@113
|
83
|