2 Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
22 * various math functions
36 - <a href="http://en.wikipedia.org/wiki/Window_function">Window
37 function</a> on Wikipedia
38 - Amalia de Götzen, Nicolas Bernardini, and Daniel Arfib. Traditional (?)
39 implementations of a phase vocoder: the tricks of the trade. In Proceedings of
40 the International Conference on Digital Audio Effects (DAFx-00), pages 37–44,
41 Uni- versity of Verona, Italy, 2000.
42 (<a href="http://profs.sci.univr.it/%7Edafx/Final-Papers/ps/Bernardini.ps.gz">
53 aubio_win_blackman_harris,
60 fvec_t *new_aubio_window (uint_t size, aubio_window_type wintype);
62 /** compute the principal argument
64 This function maps the input phase to its corresponding value wrapped in the
65 range \f$ [-\pi, \pi] \f$.
67 \param phase unwrapped phase to map to the unit circle
69 \return equivalent phase wrapped to the unit circle
72 smpl_t aubio_unwrap2pi (smpl_t phase);
74 /** compute the mean of a vector
76 \param s vector to compute norm from
81 smpl_t fvec_mean (fvec_t * s);
83 /** find the max of a vector
85 \param s vector to get the max from
87 \return the value of the minimum of v
90 smpl_t fvec_max (fvec_t * s);
92 /** find the min of a vector
94 \param s vector to get the min from
96 \return the value of the maximum of v
99 smpl_t fvec_min (fvec_t * s);
101 /** find the index of the min of a vector
103 \param s vector to get the index from
105 \return the index of the minimum element of v
108 uint_t fvec_min_elem (fvec_t * s);
110 /** find the index of the max of a vector
112 \param s vector to get the index from
114 \return the index of the maximum element of v
117 uint_t fvec_max_elem (fvec_t * s);
119 /** swap the left and right halves of a vector
121 This function swaps the left part of the signal with the right part of the
124 \f$ a[0], a[1], ..., a[\frac{N}{2}], a[\frac{N}{2}+1], ..., a[N-1], a[N] \f$
128 \f$ a[\frac{N}{2}+1], ..., a[N-1], a[N], a[0], a[1], ..., a[\frac{N}{2}] \f$
130 This operation, known as 'fftshift' in the Matlab Signal Processing Toolbox,
131 can be used before computing the FFT to simplify the phase relationship of the
132 resulting spectrum. See Amalia de Götzen's paper referred to above.
135 void fvec_shift (fvec_t * v);
137 /** compute the sum of all elements of a vector
139 \param v vector to compute the sum of
144 smpl_t fvec_sum (fvec_t * v);
146 /** compute the energy of a vector
148 This function compute the sum of the squared elements of a vector.
150 \param v vector to get the energy from
152 \return the energy of v
155 smpl_t fvec_local_energy (fvec_t * v);
157 /** compute the High Frequency Content of a vector
159 The High Frequency Content is defined as \f$ \sum_0^{N-1} (k+1) v[k] \f$.
161 \param v vector to get the energy from
166 smpl_t fvec_local_hfc (fvec_t * v);
168 /** computes the p-norm of a vector
170 Computes the p-norm of a vector for \f$ p = \alpha \f$
172 \f$ L^p = ||x||_p = (|x_1|^p + |x_2|^p + ... + |x_n|^p ) ^ \frac{1}{p} \f$
174 If p = 1, the result is the Manhattan distance.
176 If p = 2, the result is the Euclidean distance.
178 As p tends towards large values, \f$ L^p \f$ tends towards the maximum of the
183 - <a href="http://en.wikipedia.org/wiki/Lp_space">\f$L^p\f$ space</a> on
186 \param v vector to compute norm from
187 \param p order of the computed norm
189 \return the p-norm of v
192 smpl_t fvec_alpha_norm (fvec_t * v, smpl_t p);
194 /** alpha normalisation
196 This function divides all elements of a vector by the p-norm as computed by
199 \param v vector to compute norm from
200 \param p order of the computed norm
203 void fvec_alpha_normalise (fvec_t * v, smpl_t p);
205 /** add a constant to each elements of a vector
207 \param v vector to add constant to
208 \param c constant to add to v
211 void fvec_add (fvec_t * v, smpl_t c);
213 /** remove the minimum value of the vector to each elements
215 \param v vector to remove minimum from
218 void fvec_min_removal (fvec_t * v);
220 /** compute moving median theshold of a vector
222 This function computes the moving median threshold value of at the given
223 position of a vector, taking the median amongs post elements before and up to
224 pre elements after pos.
226 \param v input vector
227 \param tmp temporary vector of length post+1+pre
228 \param post length of causal part to take before pos
229 \param pre length of anti-causal part to take after pos
230 \param pos index to compute threshold for
232 \return moving median threshold value
235 smpl_t fvec_moving_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre,
238 /** apply adaptive threshold to a vector
240 For each points at position p of an input vector, this function remove the
241 moving median threshold computed at p.
243 \param v input vector
244 \param tmp temporary vector of length post+1+pre
245 \param post length of causal part to take before pos
246 \param pre length of anti-causal part to take after pos
249 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre);
251 /** returns the median of a vector
253 The QuickSelect routine is based on the algorithm described in "Numerical
254 recipes in C", Second Edition, Cambridge University Press, 1992, Section 8.5,
257 This implementation of the QuickSelect routine is based on Nicolas
258 Devillard's implementation, available at http://ndevilla.free.fr/median/median/
259 and in the Public Domain.
261 \param v vector to get median from
263 \return the median of v
266 smpl_t fvec_median (fvec_t * v);
268 /** finds exact peak index by quadratic interpolation*/
269 smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t span);
271 /** Quadratic interpolation using Lagrange polynomial.
273 Inspired from ``Comparison of interpolation algorithms in real-time sound
274 processing'', Vladimir Arnost,
276 \param s0,s1,s2 are 3 consecutive samples of a curve
277 \param pf is the floating point index [0;2]
279 \return s0 + (pf/2.)*((pf-3.)*s0-2.*(pf-2.)*s1+(pf-1.)*s2);
282 smpl_t aubio_quadfrac (smpl_t s0, smpl_t s1, smpl_t s2, smpl_t pf);
284 /** return 1 if v[p] is a peak and positive, 0 otherwise
286 This function returns 1 if a peak is found at index p in the vector v. The
287 peak is defined as follows:
293 \param v input vector
294 \param p position of supposed for peak
296 \return 1 if a peak is found, 0 otherwise
299 uint_t fvec_peakpick (fvec_t * v, uint_t p);
301 /** convert frequency bin to midi value */
302 smpl_t aubio_bintomidi (smpl_t bin, smpl_t samplerate, smpl_t fftsize);
304 /** convert midi value to frequency bin */
305 smpl_t aubio_miditobin (smpl_t midi, smpl_t samplerate, smpl_t fftsize);
307 /** convert frequency bin to frequency (Hz) */
308 smpl_t aubio_bintofreq (smpl_t bin, smpl_t samplerate, smpl_t fftsize);
310 /** convert frequency (Hz) to frequency bin */
311 smpl_t aubio_freqtobin (smpl_t freq, smpl_t samplerate, smpl_t fftsize);
313 /** convert frequency (Hz) to midi value (0-128) */
314 smpl_t aubio_freqtomidi (smpl_t freq);
316 /** convert midi value (0-128) to frequency (Hz) */
317 smpl_t aubio_miditofreq (smpl_t midi);
319 /** compute sound pressure level (SPL) in dB
321 This quantity is often wrongly called 'loudness'.
323 \param v vector to compute dB SPL from
325 \return level of v in dB SPL
328 smpl_t aubio_db_spl (fvec_t * v);
330 /** check if buffer level in dB SPL is under a given threshold
332 \param v vector to get level from
333 \param threshold threshold in dB SPL
335 \return 0 if level is under the given threshold, 1 otherwise
338 uint_t aubio_silence_detection (fvec_t * v, smpl_t threshold);
340 /** get buffer level if level >= threshold, 1. otherwise
342 \param v vector to get level from
343 \param threshold threshold in dB SPL
345 \return level in dB SPL if level >= threshold, 1. otherwise
348 smpl_t aubio_level_detection (fvec_t * v, smpl_t threshold);
350 /** compute normalised autocorrelation function
352 \param input vector to compute autocorrelation from
353 \param output vector to store autocorrelation function to
356 void aubio_autocorr (fvec_t * input, fvec_t * output);
358 /** zero-crossing rate (ZCR)
360 The zero-crossing rate is the number of times a signal changes sign,
361 divided by the length of this signal.
363 \param v vector to compute ZCR from
365 \return zero-crossing rate of v
368 smpl_t aubio_zero_crossing_rate (fvec_t * v);
370 /** clean up cached memory at the end of program
372 This function should be used at the end of programs to purge all cached
373 memory. So far it is only useful to clean FFTW's cache.
376 void aubio_cleanup (void);