source: src/mathutils.h @ 407bba9

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 407bba9 was 407bba9, checked in by Paul Brossier <piem@piem.org>, 14 years ago

src/mathutils.c: use a string for window type, making enum private

  • Property mode set to 100644
File size: 9.4 KB
Line 
1/*
2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
6  aubio is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10
11  aubio is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21/** @file
22 *  various math functions
23 */
24
25#ifndef MATHUTILS_H
26#define MATHUTILS_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/** create window
33 
34  References:
35   
36    - <a href="http://en.wikipedia.org/wiki/Window_function">Window
37function</a> on Wikipedia
38    - Amalia de Götzen, Nicolas Bernardini, and Daniel Arfib. Traditional (?)
39implementations of a phase vocoder: the tricks of the trade. In Proceedings of
40the International Conference on Digital Audio Effects (DAFx-00), pages 37–44,
41Uni- versity of Verona, Italy, 2000.
42  (<a href="http://profs.sci.univr.it/%7Edafx/Final-Papers/ps/Bernardini.ps.gz">
43  ps.gz</a>)
44
45*/
46fvec_t *new_aubio_window (char_t * window_type, uint_t size);
47
48/** compute the principal argument
49
50  This function maps the input phase to its corresponding value wrapped in the
51range \f$ [-\pi, \pi] \f$.
52
53  \param phase unwrapped phase to map to the unit circle
54 
55  \return equivalent phase wrapped to the unit circle
56
57*/
58smpl_t aubio_unwrap2pi (smpl_t phase);
59
60/** compute the mean of a vector
61
62  \param s vector to compute norm from
63
64  \return the mean of v
65
66*/
67smpl_t fvec_mean (fvec_t * s);
68
69/** find the max of a vector
70
71  \param s vector to get the max from
72
73  \return the value of the minimum of v
74
75*/
76smpl_t fvec_max (fvec_t * s);
77
78/** find the min of a vector
79
80  \param s vector to get the min from
81
82  \return the value of the maximum of v
83
84*/
85smpl_t fvec_min (fvec_t * s);
86
87/** find the index of the min of a vector
88
89  \param s vector to get the index from
90
91  \return the index of the minimum element of v
92
93*/
94uint_t fvec_min_elem (fvec_t * s);
95
96/** find the index of the max of a vector
97
98  \param s vector to get the index from
99
100  \return the index of the maximum element of v
101
102*/
103uint_t fvec_max_elem (fvec_t * s);
104
105/** swap the left and right halves of a vector
106 
107  This function swaps the left part of the signal with the right part of the
108signal. Therefore
109
110  \f$ a[0], a[1], ..., a[\frac{N}{2}], a[\frac{N}{2}+1], ..., a[N-1], a[N] \f$
111 
112  becomes
113 
114  \f$ a[\frac{N}{2}+1], ..., a[N-1], a[N], a[0], a[1], ..., a[\frac{N}{2}] \f$
115
116  This operation, known as 'fftshift' in the Matlab Signal Processing Toolbox,
117can be used before computing the FFT to simplify the phase relationship of the
118resulting spectrum. See Amalia de Götzen's paper referred to above.
119 
120*/
121void fvec_shift (fvec_t * v);
122
123/** compute the sum of all elements of a vector
124
125  \param v vector to compute the sum of
126
127  \return the sum of v
128
129*/
130smpl_t fvec_sum (fvec_t * v);
131
132/** compute the energy of a vector
133
134  This function compute the sum of the squared elements of a vector.
135 
136  \param v vector to get the energy from
137
138  \return the energy of v
139 
140*/
141smpl_t fvec_local_energy (fvec_t * v);
142
143/** compute the High Frequency Content of a vector
144
145  The High Frequency Content is defined as \f$ \sum_0^{N-1} (k+1) v[k] \f$.
146 
147  \param v vector to get the energy from
148
149  \return the HFC of v
150 
151*/
152smpl_t fvec_local_hfc (fvec_t * v);
153
154/** computes the p-norm of a vector
155 
156  Computes the p-norm of a vector for \f$ p = \alpha \f$
157
158  \f$ L^p = ||x||_p = (|x_1|^p + |x_2|^p + ... + |x_n|^p ) ^ \frac{1}{p} \f$
159 
160  If p = 1, the result is the Manhattan distance.
161
162  If p = 2, the result is the Euclidean distance.
163
164  As p tends towards large values, \f$ L^p \f$ tends towards the maximum of the
165input vector.
166
167  References:
168 
169    - <a href="http://en.wikipedia.org/wiki/Lp_space">\f$L^p\f$ space</a> on
170  Wikipedia
171
172  \param v vector to compute norm from
173  \param p order of the computed norm
174
175  \return the p-norm of v
176 
177*/
178smpl_t fvec_alpha_norm (fvec_t * v, smpl_t p);
179
180/**  alpha normalisation
181
182  This function divides all elements of a vector by the p-norm as computed by
183fvec_alpha_norm().
184
185  \param v vector to compute norm from
186  \param p order of the computed norm
187
188*/
189void fvec_alpha_normalise (fvec_t * v, smpl_t p);
190
191/** add a constant to each elements of a vector
192
193  \param v vector to add constant to
194  \param c constant to add to v
195
196*/
197void fvec_add (fvec_t * v, smpl_t c);
198
199/** remove the minimum value of the vector to each elements
200 
201  \param v vector to remove minimum from
202
203*/
204void fvec_min_removal (fvec_t * v);
205
206/** compute moving median theshold of a vector
207
208  This function computes the moving median threshold value of at the given
209position of a vector, taking the median amongs post elements before and up to
210pre elements after pos.
211 
212  \param v input vector
213  \param tmp temporary vector of length post+1+pre
214  \param post length of causal part to take before pos
215  \param pre length of anti-causal part to take after pos
216  \param pos index to compute threshold for
217
218  \return moving median threshold value
219
220*/
221smpl_t fvec_moving_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre,
222    uint_t pos);
223
224/** apply adaptive threshold to a vector
225
226  For each points at position p of an input vector, this function remove the
227moving median threshold computed at p.
228
229  \param v input vector
230  \param tmp temporary vector of length post+1+pre
231  \param post length of causal part to take before pos
232  \param pre length of anti-causal part to take after pos
233
234*/
235void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre);
236
237/** returns the median of a vector
238
239  The QuickSelect routine is based on the algorithm described in "Numerical
240recipes in C", Second Edition, Cambridge University Press, 1992, Section 8.5,
241ISBN 0-521-43108-5
242
243  This implementation of the QuickSelect routine is based on Nicolas
244Devillard's implementation, available at http://ndevilla.free.fr/median/median/
245and in the Public Domain.
246
247  \param v vector to get median from
248
249  \return the median of v
250 
251*/
252smpl_t fvec_median (fvec_t * v);
253
254/** finds exact peak index by quadratic interpolation*/
255smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t span);
256
257/** Quadratic interpolation using Lagrange polynomial.
258 
259  Inspired from ``Comparison of interpolation algorithms in real-time sound
260processing'', Vladimir Arnost,
261 
262  \param s0,s1,s2 are 3 consecutive samples of a curve
263  \param pf is the floating point index [0;2]
264 
265  \return s0 + (pf/2.)*((pf-3.)*s0-2.*(pf-2.)*s1+(pf-1.)*s2);
266
267*/
268smpl_t aubio_quadfrac (smpl_t s0, smpl_t s1, smpl_t s2, smpl_t pf);
269
270/** return 1 if v[p] is a peak and positive, 0 otherwise
271
272  This function returns 1 if a peak is found at index p in the vector v. The
273peak is defined as follows:
274
275  - v[p] is positive
276  - v[p-1] < v[p]
277  - v[p] > v[p+1]
278
279  \param v input vector
280  \param p position of supposed for peak
281
282  \return 1 if a peak is found, 0 otherwise
283
284*/
285uint_t fvec_peakpick (fvec_t * v, uint_t p);
286
287/** convert frequency bin to midi value */
288smpl_t aubio_bintomidi (smpl_t bin, smpl_t samplerate, smpl_t fftsize);
289
290/** convert midi value to frequency bin */
291smpl_t aubio_miditobin (smpl_t midi, smpl_t samplerate, smpl_t fftsize);
292
293/** convert frequency bin to frequency (Hz) */
294smpl_t aubio_bintofreq (smpl_t bin, smpl_t samplerate, smpl_t fftsize);
295
296/** convert frequency (Hz) to frequency bin */
297smpl_t aubio_freqtobin (smpl_t freq, smpl_t samplerate, smpl_t fftsize);
298
299/** convert frequency (Hz) to midi value (0-128) */
300smpl_t aubio_freqtomidi (smpl_t freq);
301
302/** convert midi value (0-128) to frequency (Hz) */
303smpl_t aubio_miditofreq (smpl_t midi);
304
305/** return 1 if a is a power of 2, 0 otherwise */
306uint_t aubio_is_power_of_two(uint_t a);
307
308/** return the next power of power of 2 greater than a */
309uint_t aubio_next_power_of_two(uint_t a);
310
311/** compute sound pressure level (SPL) in dB
312
313  This quantity is often wrongly called 'loudness'.
314
315  \param v vector to compute dB SPL from
316
317  \return level of v in dB SPL
318
319*/
320smpl_t aubio_db_spl (fvec_t * v);
321
322/** check if buffer level in dB SPL is under a given threshold
323 
324  \param v vector to get level from
325  \param threshold threshold in dB SPL
326
327  \return 0 if level is under the given threshold, 1 otherwise
328
329*/
330uint_t aubio_silence_detection (fvec_t * v, smpl_t threshold);
331
332/** get buffer level if level >= threshold, 1. otherwise
333
334  \param v vector to get level from
335  \param threshold threshold in dB SPL
336
337  \return level in dB SPL if level >= threshold, 1. otherwise
338
339*/
340smpl_t aubio_level_detection (fvec_t * v, smpl_t threshold);
341
342/** compute normalised autocorrelation function
343
344  \param input vector to compute autocorrelation from
345  \param output vector to store autocorrelation function to
346
347*/
348void aubio_autocorr (fvec_t * input, fvec_t * output);
349
350/** zero-crossing rate (ZCR)
351
352  The zero-crossing rate is the number of times a signal changes sign,
353  divided by the length of this signal.
354
355  \param v vector to compute ZCR from
356
357  \return zero-crossing rate of v
358
359*/
360smpl_t aubio_zero_crossing_rate (fvec_t * v);
361
362/** clean up cached memory at the end of program
363 
364  This function should be used at the end of programs to purge all cached
365  memory. So far it is only useful to clean FFTW's cache.
366
367*/
368void aubio_cleanup (void);
369
370#ifdef __cplusplus
371}
372#endif
373
374#endif
375
Note: See TracBrowser for help on using the repository browser.