annotate libs/aubioFullOSXUni/include/aubio/mathutils.h @ 2:fa2af670b5c5 tip

SoundFileLoader might have moved
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 06 Jan 2012 00:23:26 +0000
parents bcb0d40158f4
children
rev   line source
andrew@0 1 /*
andrew@0 2 Copyright (C) 2003 Paul Brossier
andrew@0 3
andrew@0 4 This program is free software; you can redistribute it and/or modify
andrew@0 5 it under the terms of the GNU General Public License as published by
andrew@0 6 the Free Software Foundation; either version 2 of the License, or
andrew@0 7 (at your option) any later version.
andrew@0 8
andrew@0 9 This program is distributed in the hope that it will be useful,
andrew@0 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrew@0 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrew@0 12 GNU General Public License for more details.
andrew@0 13
andrew@0 14 You should have received a copy of the GNU General Public License
andrew@0 15 along with this program; if not, write to the Free Software
andrew@0 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
andrew@0 17
andrew@0 18 */
andrew@0 19
andrew@0 20 /** @file
andrew@0 21 * various math functions
andrew@0 22 *
andrew@0 23 * \todo multichannel (each function should return -or set- an array sized to
andrew@0 24 * the number of channel in the input vector)
andrew@0 25 *
andrew@0 26 * \todo appropriate switches depending on types.h content
andrew@0 27 */
andrew@0 28
andrew@0 29 #ifndef MATHUTILS_H
andrew@0 30 #define MATHUTILS_H
andrew@0 31
andrew@0 32 /** Window types
andrew@0 33 *
andrew@0 34 * inspired from
andrew@0 35 *
andrew@0 36 * - dafx : http://profs.sci.univr.it/%7Edafx/Final-Papers/ps/Bernardini.ps.gz
andrew@0 37 * - freqtweak : http://freqtweak.sf.net/
andrew@0 38 * - extace : http://extace.sf.net/
andrew@0 39 */
andrew@0 40
andrew@0 41 #ifdef __cplusplus
andrew@0 42 extern "C" {
andrew@0 43 #endif
andrew@0 44
andrew@0 45 typedef enum {
andrew@0 46 aubio_win_rectangle,
andrew@0 47 aubio_win_hamming,
andrew@0 48 aubio_win_hanning,
andrew@0 49 aubio_win_hanningz,
andrew@0 50 aubio_win_blackman,
andrew@0 51 aubio_win_blackman_harris,
andrew@0 52 aubio_win_gaussian,
andrew@0 53 aubio_win_welch,
andrew@0 54 aubio_win_parzen
andrew@0 55 } aubio_window_type;
andrew@0 56
andrew@0 57 /** create window */
andrew@0 58 void aubio_window(smpl_t *w, ba_uint_t size, aubio_window_type wintype);
andrew@0 59
andrew@0 60 /** principal argument
andrew@0 61 *
andrew@0 62 * mod(phase+PI,-TWO_PI)+PI
andrew@0 63 */
andrew@0 64 smpl_t aubio_unwrap2pi (smpl_t phase);
andrew@0 65
andrew@0 66 /** calculates the mean of a vector
andrew@0 67 *
andrew@0 68 * \bug mono
andrew@0 69 */
andrew@0 70 smpl_t vec_mean(fvec_t *s);
andrew@0 71 /** returns the max of a vector
andrew@0 72 *
andrew@0 73 * \bug mono
andrew@0 74 */
andrew@0 75 smpl_t vec_max(fvec_t *s);
andrew@0 76 /** returns the min of a vector
andrew@0 77 *
andrew@0 78 * \bug mono
andrew@0 79 */
andrew@0 80 smpl_t vec_min(fvec_t *s);
andrew@0 81 /** returns the index of the min of a vector
andrew@0 82 *
andrew@0 83 * \bug mono
andrew@0 84 */
andrew@0 85 ba_uint_t vec_min_elem(fvec_t *s);
andrew@0 86 /** returns the index of the max of a vector
andrew@0 87 *
andrew@0 88 * \bug mono
andrew@0 89 */
andrew@0 90 ba_uint_t vec_max_elem(fvec_t *s);
andrew@0 91 /** implement 'fftshift' like function
andrew@0 92 *
andrew@0 93 * a[0]...,a[n/2],a[n/2+1],...a[n]
andrew@0 94 *
andrew@0 95 * becomes
andrew@0 96 *
andrew@0 97 * a[n/2+1],...a[n],a[0]...,a[n/2]
andrew@0 98 */
andrew@0 99 void vec_shift(fvec_t *s);
andrew@0 100 /** returns sum */
andrew@0 101 smpl_t vec_sum(fvec_t *s);
andrew@0 102 /** returns energy
andrew@0 103 *
andrew@0 104 * \bug mono
andrew@0 105 */
andrew@0 106 smpl_t vec_local_energy(fvec_t * f);
andrew@0 107 /** returns High Frequency Energy Content
andrew@0 108 *
andrew@0 109 * \bug mono */
andrew@0 110 smpl_t vec_local_hfc(fvec_t * f);
andrew@0 111 /** return alpha norm.
andrew@0 112 *
andrew@0 113 * alpha=2 means normalise variance.
andrew@0 114 * alpha=1 means normalise abs value.
andrew@0 115 * as alpha goes large, tends to normalisation
andrew@0 116 * by max value.
andrew@0 117 *
andrew@0 118 * \bug should not use POW :(
andrew@0 119 */
andrew@0 120 smpl_t vec_alpha_norm(fvec_t * DF, smpl_t alpha);
andrew@0 121 /** dc(min) removal */
andrew@0 122 void vec_dc_removal(fvec_t * mag);
andrew@0 123 /** alpha normalisation */
andrew@0 124 void vec_alpha_normalise(fvec_t * mag, ba_uint_t alpha);
andrew@0 125 /** add a constant to all members of a vector */
andrew@0 126 void vec_add(fvec_t * mag, smpl_t threshold);
andrew@0 127
andrew@0 128 /** compute adaptive threshold of input vector */
andrew@0 129 void vec_adapt_thres(fvec_t * vec, fvec_t * tmp,
andrew@0 130 ba_uint_t win_post, ba_uint_t win_pre);
andrew@0 131 /** adaptative thresholding
andrew@0 132 *
andrew@0 133 * y=fn_thresh(fn,x,post,pre)
andrew@0 134 * compute adaptive threshold at each time
andrew@0 135 * fn : a function name or pointer, eg 'median'
andrew@0 136 * x: signal vector
andrew@0 137 * post: window length, causal part
andrew@0 138 * pre: window length, anti-causal part
andrew@0 139 * Returns:
andrew@0 140 * y: signal the same length as x
andrew@0 141 *
andrew@0 142 * Formerly median_thresh, used compute median over a
andrew@0 143 * window of post+pre+1 samples, but now works with any
andrew@0 144 * function that takes a vector or matrix and returns a
andrew@0 145 * 'representative' value for each column, eg
andrew@0 146 * medians=fn_thresh(median,x,8,8)
andrew@0 147 * minima=fn_thresh(min,x,8,8)
andrew@0 148 * see SPARMS for explanation of post and pre
andrew@0 149 */
andrew@0 150 smpl_t vec_moving_thres(fvec_t * vec, fvec_t * tmp,
andrew@0 151 ba_uint_t win_post, ba_uint_t win_pre, ba_uint_t win_pos);
andrew@0 152
andrew@0 153 /** returns the median of the vector
andrew@0 154 *
andrew@0 155 * This Quickselect routine is based on the algorithm described in
andrew@0 156 * "Numerical recipes in C", Second Edition,
andrew@0 157 * Cambridge University Press, 1992, Section 8.5, ISBN 0-521-43108-5
andrew@0 158 *
andrew@0 159 * This code by Nicolas Devillard - 1998. Public domain,
andrew@0 160 * available at http://ndevilla.free.fr/median/median/
andrew@0 161 */
andrew@0 162 smpl_t vec_median(fvec_t * input);
andrew@0 163
andrew@0 164 /** finds exact maximum position by quadratic interpolation*/
andrew@0 165 smpl_t vec_quadint(fvec_t * x,ba_uint_t pos);
andrew@0 166
andrew@0 167 /** finds exact minimum position by quadratic interpolation*/
andrew@0 168 smpl_t vec_quadint_min(fvec_t * x,ba_uint_t pos, ba_uint_t span);
andrew@0 169
andrew@0 170 /** Quadratic interpolation using Lagrange polynomial.
andrew@0 171 *
andrew@0 172 * inspired from ``Comparison of interpolation algorithms in real-time sound
andrew@0 173 * processing'', Vladimir Arnost,
andrew@0 174 *
andrew@0 175 * estimate = s0 + (pf/2.)*((pf-3.)*s0-2.*(pf-2.)*s1+(pf-1.)*s2);
andrew@0 176 * where
andrew@0 177 * \param s0,s1,s2 are 3 known points on the curve,
andrew@0 178 * \param pf is the floating point index [0;2]
andrew@0 179 */
andrew@0 180 smpl_t aubio_quadfrac(smpl_t s0, smpl_t s1, smpl_t s2, smpl_t pf);
andrew@0 181
andrew@0 182 /** returns 1 if X1 is a peak and positive */
andrew@0 183 ba_uint_t vec_peakpick(fvec_t * input, ba_uint_t pos);
andrew@0 184
andrew@0 185 /** convert frequency bin to midi value */
andrew@0 186 smpl_t aubio_bintomidi(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
andrew@0 187 /** convert midi value to frequency bin */
andrew@0 188 smpl_t aubio_miditobin(smpl_t midi, smpl_t samplerate, smpl_t fftsize);
andrew@0 189 /** convert frequency bin to frequency (Hz) */
andrew@0 190 smpl_t aubio_bintofreq(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
andrew@0 191 /** convert frequency (Hz) to frequency bin */
andrew@0 192 smpl_t aubio_freqtobin(smpl_t freq, smpl_t samplerate, smpl_t fftsize);
andrew@0 193 /** convert frequency (Hz) to midi value (0-128) */
andrew@0 194 smpl_t aubio_freqtomidi(smpl_t freq);
andrew@0 195 /** convert midi value (0-128) to frequency (Hz) */
andrew@0 196 smpl_t aubio_miditofreq(smpl_t midi);
andrew@0 197
andrew@0 198 /** check if current buffer level is under a given threshold */
andrew@0 199 ba_uint_t aubio_silence_detection(fvec_t * ibuf, smpl_t threshold);
andrew@0 200 /** get the current buffer level */
andrew@0 201 smpl_t aubio_level_detection(fvec_t * ibuf, smpl_t threshold);
andrew@0 202 /**
andrew@0 203 * calculate normalised autocorrelation function
andrew@0 204 */
andrew@0 205 void aubio_autocorr(fvec_t * input, fvec_t * output);
andrew@0 206 /**
andrew@0 207 * clean up cached memory at the end of program
andrew@0 208 *
andrew@0 209 * use this function at the end of programs to purge all
andrew@0 210 * cached memory. so far this function is only used to clean
andrew@0 211 * fftw cache.
andrew@0 212 */
andrew@0 213 void aubio_cleanup(void);
andrew@0 214
andrew@0 215 #ifdef __cplusplus
andrew@0 216 }
andrew@0 217 #endif
andrew@0 218
andrew@0 219 #endif
andrew@0 220