1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/* libxtract feature extraction library
*
* Copyright (C) 2006 Jamie Bullock
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/* xtract_scalar.h: declares functions that extract a feature as a vector from an input vector */
#ifndef XTRACT_VECTOR_H
#define XTRACT_VECTOR_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* \defgroup vector vector extraction functions
*
* Defines vector extraction functions, and their parameters.
* @{
*/
/** \brief Extract frequency domain spectrum from time domain signal
*
* \param *data: a pointer to the first element in an array of floats representing an audio vector
* \param N: the number of array elements to be considered
* \param *argv: a pointer to an array of floats, the first representing (samplerate / N), the second will be cast to an integer and determines the spectrum type (e.g. XTRACT_MAGNITUDE_SPECTRUM, XTRACT_LOG_POWER_SPECTRUM). The third argument determines whether or not the DC component is included in the output. If argv[2] == 1, then the DC component is included in which case the size of the array pointed to by *result must be N+2. For any further use of the array pointed to by *result, the value of N must reflect the (larger) array size. The fourth argument determines whether the magnitude/power coefficients are to be normalised. If argv[3] == 1, then the coefficients are normalised.
* \param *result: a pointer to an array of size N containing N/2 magnitude/power/log magnitude/log power coefficients and N/2 bin frequencies.
*
* The magnitude/power coefficients are scaled to the range 0-1 so that for a given coefficient x, 0 <= x <= 1
*
*/
int xtract_spectrum(const float *data, const int N, const void *argv, float *result);
/** \brief Extract autocorrelation from time domain signal using FFT based method
*
* \param *data: a pointer to the first element in an array of floats representing an audio vector
* \param N: the number of array elements to be considered
* \param *argv: a pointer to NULL
* \param *result: the autocorrelation of N values from the array pointed to by *data
*/
int xtract_autocorrelation_fft(const float *data, const int N, const void *argv, float *result);
/** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner
*
* \param *data: a pointer to the first element in an array of spectral magnitudes, e.g. the first half of the array pointed to by *resul from xtract_spectrum()
* \param N: the number of array elements to be considered
* \param *argv: a pointer to a data structure of type xtract_mel_filter, containing n_filters coefficient tables to make up a mel-spaced filterbank
* \param *result: a pointer to an array containing the resultant MFCC
*
* The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc
*/
int xtract_mfcc(const float *data, const int N, const void *argv, float *result);
/** \brief Extract the Discrete Cosine transform of a time domain signal
* \param *data: a pointer to the first element in an array of floats representing an audio vector
* \param N: the number of array elements to be considered
* \param *argv: a pointer to NULL
* \param *result: a pointer to an array containing resultant dct coefficients
*/
int xtract_dct(const float *data, const int N, const void *argv, float *result);
/** \brief Extract autocorrelation from time domain signal using time-domain autocorrelation technique
*
* \param *data: a pointer to the first element in an array of floats representing an audio vector
* \param N: the number of array elements to be considered
* \param *argv: a pointer to NULL
* \param *result: the autocorrelation of N values from the array pointed to by *data
*/
int xtract_autocorrelation(const float *data, const int N, const void *argv, float *result);
/** \brief Extract Average Magnitude Difference Function from time domain signal
*
* \param *data: a pointer to the first element in an array of floats representing an audio vector
* \param N: the number of array elements to be considered
* \param *argv: a pointer to NULL
* \param *result: the AMDF of N values from the array pointed to by *data
*/
int xtract_amdf(const float *data, const int N, const void *argv, float *result);
/** \brief Extract Average Squared Difference Function from time domain signal
*
* \param *data: a pointer to the first element in an array of floats representing an audio vector
* \param N: the number of array elements to be considered
* \param *argv: a pointer to NULL
* \param *result: the ASDF of N values from the array pointed to by *data
*/
int xtract_asdf(const float *data, const int N, const void *argv, float *result);
/** \brief Extract Bark band coefficients based on a method
* \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
* \param N: the number of array elements to be considered
* \param *argv: a pointer to an array of ints representing the limits of each bark band. This can be obtained by calling xtract_init_bark.
* \param *result: a pointer to an array containing resultant bark coefficients
*
* The limits array pointed to by *argv must be obtained by first calling xtract_init_bark
*
*/
int xtract_bark_coefficients(const float *data, const int N, const void *argv, float *result);
/** \brief Extract the amplitude and frequency of spectral peaks from a magnitude spectrum
* \param *data: a pointer to an array of size N containing N magnitude/power/log magnitude/log power coefficients. (e.g. the first half of the array pointed to by *result from xtract_spectrum().
* \param N: the size of the input array (note: it is assumed that enough memory has been allocated for an output array twice the size)
* \param *argv: a pointer to an array of floats, the first representing (samplerate / N), the second representing the peak threshold as percentage of the magnitude of the maximum peak found
* \param *result: a pointer to an array of size N * 2 containing N magnitude/power/log magnitude/log power coefficients and N bin frequencies.
*
*/
int xtract_peak_spectrum(const float *data, const int N, const void *argv, float *result);
/** \brief Extract the harmonic spectrum of from a of a peak spectrum
* \param *data: a pointer to the first element in an array of floats representing the peak spectrum of an audio vector (e.g. *result from xtract_peaks). It is expected that the first half of the array pointed to by *data will contain amplitudes for each peak considered, and the the second half will contain the respective frequencies
* \param N: the size of the array pointed to by *data
* \param *argv: a pointer to an array containing the fundamental (f0) of the spectrum, and a threshold (t) where 0<=t<=1.0, and t determines the distance from the nearest harmonic number within which a partial can be considered harmonic.
* \param *result: a pointer to an array of size N containing N/2 magnitude coefficients and N/2 bin frequencies.
*/
int xtract_harmonic_spectrum(const float *data, const int N, const void *argv, float *result);
/** \brief Extract Linear Predictive Coding Coefficients
*
* Based on algorithm in Rabiner and Juang as implemented by Jutta Degener in Dr. Dobb's Journal December, 1994.
*
* Returns N-1 reflection (PARCOR) coefficients and N-1 LPC coefficients via *result
*
* \param *data: N autocorrelation values e.g the data pointed to by *result from xtract_autocorrelation()
* \param N: the number of autocorrelation values to be considered
* \param *argv: a pointer to NULL
* \param *result: a pointer to an array containing N-1 reflection coefficients and N-1 LPC coefficients.
*
* An array of size 2 * (N - 1) must be allocated, and *result must point to its first element.
*/
int xtract_lpc(const float *data, const int N, const void *argv, float *result);
/** \brief Extract Linear Predictive Coding Cepstral Coefficients
*
* \param *data: a pointer to the first element in an array of LPC coeffiecients e.g. a pointer to the second half of the array pointed to by *result from xtract_lpc()
* \param N: the number of LPC coefficients to be considered
* \param *argv: a pointer to a float representing the order of the result vector. This must be a whole number. According to Rabiner and Juang the ratio between the number (p) of LPC coefficients and the order (Q) of the LPC cepstrum is given by Q ~ (3/2)p where Q > p.
* \param *result: a pointer to an array containing the resultant LPCC.
*
* An array of size Q, where Q is given by argv[0] must be allocated, and *result must point to its first element.
*
*/
int xtract_lpcc(const float *data, const int N, const void *argv, float *result);
/** @} */
#ifdef __cplusplus
}
#endif
#endif
|