2 Copyright (C) 2003 Paul Brossier
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * various math functions
23 * \todo multichannel (each function should return -or set- an array sized to
24 * the number of channel in the input vector)
26 * \todo appropriate switches depending on types.h content
33 #define TWO_PI (PI*2.)
35 /* aliases to math.h functions */
47 /* aliases to complex.h functions */
49 /* mingw32 does not know about c*f functions */
51 /** complex = CEXPC(complex) */
53 /** sample = ARGC(complex) */
55 /** sample = ABSC(complex) norm */
57 /** sample = REAL(complex) */
59 /** sample = IMAG(complex) */
62 /** sample = EXPC(complex) */
64 /** complex = CEXPC(complex) */
66 /** sample = ARGC(complex) */
68 /** sample = ABSC(complex) norm */
70 /** sample = REAL(complex) */
72 /** sample = IMAG(complex) */
77 #define DB2LIN(g) (POW(10.0f,(g)*0.05f))
78 #define LIN2DB(v) (20.0f*LOG10(v))
79 #define SQR(_a) (_a*_a)
81 #define ELEM_SWAP(a,b) { register smpl_t t=(a);(a)=(b);(b)=t; }
87 * - dafx : http://profs.sci.univr.it/%7Edafx/Final-Papers/ps/Bernardini.ps.gz
88 * - freqtweak : http://freqtweak.sf.net/
89 * - extace : http://extace.sf.net/
102 aubio_win_blackman_harris,
109 void aubio_window(smpl_t *w, uint_t size, aubio_window_type wintype);
111 /** principal argument
113 * mod(phase+PI,-TWO_PI)+PI
115 smpl_t aubio_unwrap2pi (smpl_t phase);
117 /** calculates the mean of a vector
121 smpl_t vec_mean(fvec_t *s);
122 /** returns the max of a vector
126 smpl_t vec_max(fvec_t *s);
127 /** returns the min of a vector
131 smpl_t vec_min(fvec_t *s);
132 /** returns the index of the min of a vector
136 uint_t vec_min_elem(fvec_t *s);
137 /** returns the index of the max of a vector
141 uint_t vec_max_elem(fvec_t *s);
142 /** implement 'fftshift' like function
144 * a[0]...,a[n/2],a[n/2+1],...a[n]
148 * a[n/2+1],...a[n],a[0]...,a[n/2]
150 void vec_shift(fvec_t *s);
152 smpl_t vec_sum(fvec_t *s);
157 smpl_t vec_local_energy(fvec_t * f);
158 /** returns High Frequency Energy Content
161 smpl_t vec_local_hfc(fvec_t * f);
162 /** return alpha norm.
164 * alpha=2 means normalise variance.
165 * alpha=1 means normalise abs value.
166 * as alpha goes large, tends to normalisation
169 * \bug should not use POW :(
171 smpl_t vec_alpha_norm(fvec_t * DF, smpl_t alpha);
172 /* dc(min) removal */
173 void vec_dc_removal(fvec_t * mag);
174 /** alpha normalisation */
175 void vec_alpha_normalise(fvec_t * mag, uint_t alpha);
177 void vec_add(fvec_t * mag, smpl_t threshold);
179 void vec_adapt_thres(fvec_t * vec, fvec_t * tmp,
180 uint_t win_post, uint_t win_pre);
181 /** adaptative thresholding
183 * y=fn_thresh(fn,x,post,pre)
184 * compute adaptive threshold at each time
185 * fn : a function name or pointer, eg 'median'
187 * post: window length, causal part
188 * pre: window length, anti-causal part
190 * y: signal the same length as x
192 * Formerly median_thresh, used compute median over a
193 * window of post+pre+1 samples, but now works with any
194 * function that takes a vector or matrix and returns a
195 * 'representative' value for each column, eg
196 * medians=fn_thresh(median,x,8,8)
197 * minima=fn_thresh(min,x,8,8)
198 * see SPARMS for explanation of post and pre
200 smpl_t vec_moving_thres(fvec_t * vec, fvec_t * tmp,
201 uint_t win_post, uint_t win_pre, uint_t win_pos);
203 /** returns the median of the vector
205 * This Quickselect routine is based on the algorithm described in
206 * "Numerical recipes in C", Second Edition,
207 * Cambridge University Press, 1992, Section 8.5, ISBN 0-521-43108-5
209 * This code by Nicolas Devillard - 1998. Public domain,
210 * available at http://ndevilla.free.fr/median/median/
212 smpl_t vec_median(fvec_t * input);
214 /** finds exact peak position by quadratic interpolation*/
215 smpl_t vec_quadint(fvec_t * x,uint_t pos);
217 /** Quadratic interpolation using Lagrange polynomial.
219 * inspired from ``Comparison of interpolation algorithms in real-time sound
220 * processing'', Vladimir Arnost,
222 * estimate = s0 + (pf/2.)*((pf-3.)*s0-2.*(pf-2.)*s1+(pf-1.)*s2);
224 * \param s0,s1,s2 are 3 known points on the curve,
225 * \param pf is the floating point index [0;2]
227 smpl_t aubio_quadfrac(smpl_t s0, smpl_t s1, smpl_t s2, smpl_t pf);
229 /** returns 1 if X1 is a peak and positive */
230 uint_t vec_peakpick(fvec_t * input, uint_t pos);
232 smpl_t aubio_bintomidi(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
233 smpl_t aubio_bintofreq(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
234 smpl_t aubio_freqtomidi(smpl_t freq);
236 uint_t aubio_silence_detection(fvec_t * ibuf, smpl_t threshold);
237 smpl_t aubio_level_detection(fvec_t * ibuf, smpl_t threshold);
239 * calculate normalised autocorrelation function
241 void aubio_autocorr(fvec_t * input, fvec_t * output);