jamie@254
|
1 /*
|
jamie@254
|
2 * Copyright (C) 2012 Jamie Bullock
|
jamie@254
|
3 *
|
jamie@254
|
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
|
jamie@254
|
5 * of this software and associated documentation files (the "Software"), to
|
jamie@254
|
6 * deal in the Software without restriction, including without limitation the
|
jamie@254
|
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
jamie@254
|
8 * sell copies of the Software, and to permit persons to whom the Software is
|
jamie@254
|
9 * furnished to do so, subject to the following conditions:
|
jamie@254
|
10 *
|
jamie@254
|
11 * The above copyright notice and this permission notice shall be included in
|
jamie@254
|
12 * all copies or substantial portions of the Software.
|
jamie@254
|
13 *
|
jamie@254
|
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
jamie@254
|
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
jamie@254
|
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
jamie@254
|
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
jamie@254
|
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
jamie@254
|
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
jamie@254
|
20 * IN THE SOFTWARE.
|
jamie@254
|
21 *
|
jamie@254
|
22 */
|
jamie@254
|
23
|
jamie@254
|
24 /** \file xtract_helper.h: helper functions for making life with libxtract a bit more bearable */
|
jamie@254
|
25
|
jamie@254
|
26 #ifndef XTRACT_HELPER_H
|
jamie@254
|
27 #define XTRACT_HELPER_H
|
jamie@254
|
28
|
jamie@254
|
29 #ifdef __cplusplus
|
jamie@254
|
30 extern "C" {
|
jamie@254
|
31 #endif
|
jamie@254
|
32
|
jamie@254
|
33 #ifdef _MSC_VER
|
jamie@254
|
34 #ifndef __cplusplus
|
jamie@254
|
35 typedef int bool;
|
jamie@254
|
36 #define false 0
|
jamie@254
|
37 #define true 1
|
jamie@254
|
38 #endif
|
jamie@254
|
39 #else
|
jamie@254
|
40 #include <stdbool.h>
|
jamie@254
|
41 #endif
|
jamie@254
|
42
|
jamie@254
|
43
|
jamie@254
|
44 /**
|
jamie@254
|
45 * \defgroup helper helper functions
|
jamie@254
|
46 *
|
jamie@254
|
47 * Declares helper functions, and their parameters.
|
jamie@254
|
48 *
|
jamie@254
|
49 * \note These functions don't necessarily conform to the prototype used in xtract_scalar.h and xtract_vector.h etc, and as such are intended to be called 'directly' rather than via the xtract[] function pointer array (libxtract.h)
|
jamie@254
|
50 *
|
jamie@254
|
51 * @{
|
jamie@254
|
52 */
|
jamie@254
|
53
|
jamie@254
|
54 /** \brief Apply a window function to an array of length N
|
jamie@254
|
55 *
|
jamie@254
|
56 * \param *data a pointer to an array of doubles
|
jamie@254
|
57 * \param N the number of elements in the array pointed to by *data
|
jamie@254
|
58 * \param *argv a pointer to a window function as returned by xtract_make_window()
|
jamie@254
|
59 * \param *result a pointer to the first element an array containing the windowed data
|
jamie@254
|
60 *
|
jamie@254
|
61 * It is up to the caller to generate and free the array containing the window, and to allocate and free memory of size N to hold the data pointed to by *result
|
jamie@254
|
62 *
|
jamie@254
|
63 */
|
jamie@254
|
64 int xtract_windowed(const double *data, const int N, const void *argv, double *result);
|
jamie@254
|
65
|
jamie@254
|
66 /** \brief Divides the array pointed to by *data into two subframes, and applies a given feature to each subframe, returning them in a single array pointed to by result
|
jamie@254
|
67 *
|
jamie@254
|
68 * \param *data an array of doubles
|
jamie@254
|
69 * \param N the number of elements in the array pointed by *data
|
jamie@254
|
70 * \param feature an integer representing the feature to be applied to each subframe in data. This will be a value as given in the enumeration xtract_features_ (libxtract.h)
|
jamie@254
|
71 * \param *argv a pointer to the argument vector to be passed to the feature extraction function as determined by feature
|
jamie@254
|
72 * \param *result a pointer to the 'packed' results of the feature calculation. This may be passed in as *data to xtract_features_from_subframes() to calculate further features on the subframes, or xtract_difference_vector(), to get the difference between the subframes.
|
jamie@254
|
73 *
|
jamie@254
|
74 *
|
jamie@254
|
75 * It is important to ensure that any _init_*() functions that are called in preparation for functions that are called on subframes are given the subframe size as 'N', and not the frame size. i.e. if xtract_features_from_subframes() is called with N=64, and feature=XTRACT_SPECTRUM, then xtract_init_fft() should be called with N=32.
|
jamie@254
|
76 *
|
jamie@254
|
77 */
|
jamie@254
|
78 int xtract_features_from_subframes(const double *data, const int N, const int feature, const void *argv, double *result);
|
jamie@254
|
79
|
jamie@254
|
80 /** \brief Test whether a number is denormal */
|
jamie@254
|
81 int xtract_is_denormal(double const d);
|
jamie@254
|
82
|
jamie@254
|
83 /** \brief Test whether a number is a power of two */
|
jamie@254
|
84 bool xtract_is_poweroftwo(unsigned int x);
|
jamie@254
|
85
|
jamie@254
|
86
|
jamie@254
|
87 /** \brief Smooth a vector
|
jamie@254
|
88 *
|
jamie@254
|
89 * \param *data a pointer to an array of doubles
|
jamie@254
|
90 * \param N the number of elements in the array pointed to by *data to be smoothed
|
jamie@254
|
91 * \param *argv a pointer to a double giving the smoothing gain
|
jamie@254
|
92 * \param *result a pointer to the first element an array containing the smoothed data
|
jamie@254
|
93 *
|
jamie@254
|
94 * \note if passing in a spectrum e.g. *result from xtract_spectrum(), then N for xtract_smoothed() should be N / 2 with respect to the N for xtract_spectrum() so only amplitude components are smoothed, not frequencies!
|
jamie@254
|
95 *
|
jamie@254
|
96 */
|
jamie@254
|
97 int xtract_smoothed(const double *data, const int N, const void *argv, double *result);
|
jamie@254
|
98
|
jamie@254
|
99
|
jamie@254
|
100 /** @} */
|
jamie@254
|
101
|
jamie@254
|
102 #ifdef __cplusplus
|
jamie@254
|
103 }
|
jamie@254
|
104 #endif
|
jamie@254
|
105
|
jamie@254
|
106 #endif
|
jamie@254
|
107
|
jamie@254
|
108
|
jamie@254
|
109
|