src/Makefile.am: rename peakpicker.h here too, thanks to Laurent Feron for noticing it
[aubio.git] / src / musicutils.h
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 functions useful in audio signal processing
23  */
24
25 #ifndef MUSICUTILS_H
26 #define MUSICUTILS_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /** create window 
33  
34   References:
35     
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">
43   ps.gz</a>)
44
45 */
46 fvec_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
51 range \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 */
58 smpl_t aubio_unwrap2pi (smpl_t phase);
59
60 /** convert frequency bin to midi value */
61 smpl_t aubio_bintomidi (smpl_t bin, smpl_t samplerate, smpl_t fftsize);
62
63 /** convert midi value to frequency bin */
64 smpl_t aubio_miditobin (smpl_t midi, smpl_t samplerate, smpl_t fftsize);
65
66 /** convert frequency bin to frequency (Hz) */
67 smpl_t aubio_bintofreq (smpl_t bin, smpl_t samplerate, smpl_t fftsize);
68
69 /** convert frequency (Hz) to frequency bin */
70 smpl_t aubio_freqtobin (smpl_t freq, smpl_t samplerate, smpl_t fftsize);
71
72 /** convert frequency (Hz) to midi value (0-128) */
73 smpl_t aubio_freqtomidi (smpl_t freq);
74
75 /** convert midi value (0-128) to frequency (Hz) */
76 smpl_t aubio_miditofreq (smpl_t midi);
77
78 /** clean up cached memory at the end of program
79  
80   This function should be used at the end of programs to purge all cached
81   memory. So far it is only useful to clean FFTW's cache.
82
83 */
84 void aubio_cleanup (void);
85
86 /** zero-crossing rate (ZCR)
87
88   The zero-crossing rate is the number of times a signal changes sign,
89   divided by the length of this signal.
90
91   \param v vector to compute ZCR from
92
93   \return zero-crossing rate of v
94
95 */
96 smpl_t aubio_zero_crossing_rate (fvec_t * v);
97
98 /** compute sound pressure level (SPL) in dB
99
100   This quantity is often wrongly called 'loudness'.
101
102   \param v vector to compute dB SPL from
103
104   \return level of v in dB SPL
105
106 */
107 smpl_t aubio_db_spl (fvec_t * v);
108
109 /** check if buffer level in dB SPL is under a given threshold
110  
111   \param v vector to get level from
112   \param threshold threshold in dB SPL
113
114   \return 0 if level is under the given threshold, 1 otherwise
115
116 */
117 uint_t aubio_silence_detection (fvec_t * v, smpl_t threshold);
118
119 /** get buffer level if level >= threshold, 1. otherwise
120
121   \param v vector to get level from
122   \param threshold threshold in dB SPL
123
124   \return level in dB SPL if level >= threshold, 1. otherwise
125
126 */
127 smpl_t aubio_level_detection (fvec_t * v, smpl_t threshold);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif
134