src/onset/onset.h: improve documentation
[aubio.git] / src / onset / onset.h
1 /*
2   Copyright (C) 2006-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
23   Onset detection object
24
25   The following routines compute the onset detection function and detect peaks
26   in these functions. When onsets are found above a given silence threshold,
27   and after a minimum inter-onset interval, the output vector returned by
28   aubio_onset_do() is filled with `1`. Otherwise, the output vector remains
29   `0`.
30
31   The peak-picking threshold, the silence threshold, and the minimum
32   inter-onset interval can be adjusted during the execution of the
33   aubio_onset_do routine using the corresponding functions.
34
35   \example onset/test-onset.c
36
37 */
38
39
40 #ifndef ONSET_H
41 #define ONSET_H
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /** onset detection object */
48 typedef struct _aubio_onset_t aubio_onset_t;
49
50 /** create onset detection object
51
52   \param method onset detection type as specified in specdesc.h
53   \param buf_size buffer size for phase vocoder
54   \param hop_size hop size for phase vocoder
55   \param samplerate sampling rate of the input signal
56
57   \return newly created ::aubio_onset_t
58
59 */
60 aubio_onset_t * new_aubio_onset (char_t * method,
61     uint_t buf_size, uint_t hop_size, uint_t samplerate);
62
63 /** execute onset detection
64
65   \param o onset detection object as returned by new_aubio_onset()
66   \param input new audio vector of length hop_size
67   \param onset output vector of length 1, containing 0 if no onset was found,
68   and a value equal or greater than 1 otherwise
69
70   When no onset was detected, the first element of the output vector `onset`
71   is set to 0.
72
73   When an onset is found, the first element of the output vector `onset` is set
74   to `offset = 1 + a` where `a` is a number in the range`[0, 1]`.
75
76   The final onset detection time, in samples, can be obtained with
77   aubio_onset_get_last(). It can also be derived from `offset` as
78   follows:
79
80   \code
81     t = total_frames + offset * hop_size - delay
82   \endcode
83
84   where `total_frames` is the total number of frames processed so far, and
85   `delay` is the current delay of the onset object, as returned by
86   aubio_onset_get_delay().
87
88 */
89 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset);
90
91 /** get the time of the latest onset detected, in samples
92
93   \param o onset detection object as returned by new_aubio_onset()
94
95   \return onset detection timestamps (in samples)
96
97 */
98 uint_t aubio_onset_get_last (aubio_onset_t *o);
99
100 /** get the time of the latest onset detected, in seconds
101
102   \param o onset detection object as returned by new_aubio_onset()
103
104   \return onset detection timestamps (in seconds)
105
106 */
107 smpl_t aubio_onset_get_last_s (aubio_onset_t *o);
108
109 /** get the time of the latest onset detected, in milliseconds
110
111   \param o onset detection object as returned by new_aubio_onset()
112
113   \return onset detection timestamps (in milliseconds)
114
115 */
116 smpl_t aubio_onset_get_last_ms (aubio_onset_t *o);
117
118 /** set onset detection silence threshold
119
120   \param o onset detection object as returned by new_aubio_onset()
121   \param silence new silence detection threshold
122
123 */
124 uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence);
125
126 /** get onset detection function
127
128   \param o onset detection object as returned by new_aubio_onset()
129   \return the current value of the descriptor
130
131 */
132 smpl_t aubio_onset_get_descriptor ( aubio_onset_t *o);
133
134 /** get thresholded onset detection function
135
136   \param o onset detection object as returned by new_aubio_onset()
137   \return the value of the thresholded descriptor
138
139 */
140 smpl_t aubio_onset_get_thresholded_descriptor ( aubio_onset_t *o);
141
142 /** set onset detection peak picking threshold
143
144   \param o onset detection object as returned by new_aubio_onset()
145   \param threshold new peak-picking threshold
146
147 */
148 uint_t aubio_onset_set_threshold(aubio_onset_t * o, smpl_t threshold);
149
150 /** set minimum inter onset interval in samples
151
152   \param o onset detection object as returned by new_aubio_onset()
153   \param minioi minimum interval between two consecutive onsets (in
154   samples)
155
156 */
157 uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi);
158
159 /** set minimum inter onset interval in seconds
160
161   \param o onset detection object as returned by new_aubio_onset()
162   \param minioi minimum interval between two consecutive onsets (in
163   seconds)
164
165 */
166 uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi);
167
168 /** set minimum inter onset interval in milliseconds
169
170   \param o onset detection object as returned by new_aubio_onset()
171   \param minioi minimum interval between two consecutive onsets (in
172   milliseconds)
173
174 */
175 uint_t aubio_onset_set_minioi_ms(aubio_onset_t * o, smpl_t minioi);
176
177 /** set minimum inter onset interval in samples
178
179   \param o onset detection object as returned by new_aubio_onset()
180   \param delay constant system delay to take back from detection time
181   (in samples)
182
183 */
184 uint_t aubio_onset_set_delay(aubio_onset_t * o, uint_t delay);
185
186 /** set minimum inter onset interval in seconds
187
188   \param o onset detection object as returned by new_aubio_onset()
189   \param delay constant system delay to take back from detection time
190   (in seconds)
191
192 */
193 uint_t aubio_onset_set_delay_s(aubio_onset_t * o, smpl_t delay);
194
195 /** set minimum inter onset interval in milliseconds
196
197   \param o onset detection object as returned by new_aubio_onset()
198   \param delay constant system delay to take back from detection time
199   (in milliseconds)
200
201 */
202 uint_t aubio_onset_set_delay_ms(aubio_onset_t * o, smpl_t delay);
203
204 /** get minimum inter onset interval in samples
205
206   \param o onset detection object as returned by new_aubio_onset()
207   \return minimum interval between two consecutive onsets (in
208   samples)
209
210 */
211 uint_t aubio_onset_get_minioi(aubio_onset_t * o);
212
213 /** get minimum inter onset interval in seconds
214
215   \param o onset detection object as returned by new_aubio_onset()
216   \return minimum interval between two consecutive onsets (in
217   seconds)
218
219 */
220 smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o);
221
222 /** get minimum inter onset interval in milliseconds
223
224   \param o onset detection object as returned by new_aubio_onset()
225   \return minimum interval between two consecutive onsets (in
226   milliseconds)
227
228 */
229 smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o);
230
231 /** get minimum inter onset interval in samples
232
233   \param o onset detection object as returned by new_aubio_onset()
234   \return constant system delay to take back from detection time
235   (in samples)
236
237 */
238 uint_t aubio_onset_get_delay(aubio_onset_t * o);
239
240 /** get minimum inter onset interval in seconds
241
242   \param o onset detection object as returned by new_aubio_onset()
243   \return constant system delay to take back from detection time
244   (in seconds)
245
246 */
247 smpl_t aubio_onset_get_delay_s(aubio_onset_t * o);
248
249 /** get minimum inter onset interval in milliseconds
250
251   \param o onset detection object as returned by new_aubio_onset()
252   \return constant system delay to take back from detection time
253   (in milliseconds)
254
255 */
256 smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o);
257
258 /** delete onset detection object
259
260   \param o onset detection object to delete
261
262 */
263 void del_aubio_onset(aubio_onset_t * o);
264
265 #ifdef __cplusplus
266 }
267 #endif
268
269 #endif /* ONSET_H */