2 Copyright (C) 2006-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/>.
23 Onset detection object
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
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.
35 \example onset/test-onset.c
47 /** onset detection object */
48 typedef struct _aubio_onset_t aubio_onset_t;
50 /** create onset detection object
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
57 \return newly created ::aubio_onset_t
60 aubio_onset_t * new_aubio_onset (char_t * method,
61 uint_t buf_size, uint_t hop_size, uint_t samplerate);
63 /** execute onset detection
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
70 When no onset was detected, the first element of the output vector `onset`
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]`.
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
81 t = total_frames + offset * hop_size - delay
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().
89 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset);
91 /** get the time of the latest onset detected, in samples
93 \param o onset detection object as returned by new_aubio_onset()
95 \return onset detection timestamps (in samples)
98 uint_t aubio_onset_get_last (aubio_onset_t *o);
100 /** get the time of the latest onset detected, in seconds
102 \param o onset detection object as returned by new_aubio_onset()
104 \return onset detection timestamps (in seconds)
107 smpl_t aubio_onset_get_last_s (aubio_onset_t *o);
109 /** get the time of the latest onset detected, in milliseconds
111 \param o onset detection object as returned by new_aubio_onset()
113 \return onset detection timestamps (in milliseconds)
116 smpl_t aubio_onset_get_last_ms (aubio_onset_t *o);
118 /** set onset detection silence threshold
120 \param o onset detection object as returned by new_aubio_onset()
121 \param silence new silence detection threshold
124 uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence);
126 /** get onset detection function
128 \param o onset detection object as returned by new_aubio_onset()
129 \return the current value of the descriptor
132 smpl_t aubio_onset_get_descriptor ( aubio_onset_t *o);
134 /** get thresholded onset detection function
136 \param o onset detection object as returned by new_aubio_onset()
137 \return the value of the thresholded descriptor
140 smpl_t aubio_onset_get_thresholded_descriptor ( aubio_onset_t *o);
142 /** set onset detection peak picking threshold
144 \param o onset detection object as returned by new_aubio_onset()
145 \param threshold new peak-picking threshold
148 uint_t aubio_onset_set_threshold(aubio_onset_t * o, smpl_t threshold);
150 /** set minimum inter onset interval in samples
152 \param o onset detection object as returned by new_aubio_onset()
153 \param minioi minimum interval between two consecutive onsets (in
157 uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi);
159 /** set minimum inter onset interval in seconds
161 \param o onset detection object as returned by new_aubio_onset()
162 \param minioi minimum interval between two consecutive onsets (in
166 uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi);
168 /** set minimum inter onset interval in milliseconds
170 \param o onset detection object as returned by new_aubio_onset()
171 \param minioi minimum interval between two consecutive onsets (in
175 uint_t aubio_onset_set_minioi_ms(aubio_onset_t * o, smpl_t minioi);
177 /** set minimum inter onset interval in samples
179 \param o onset detection object as returned by new_aubio_onset()
180 \param delay constant system delay to take back from detection time
184 uint_t aubio_onset_set_delay(aubio_onset_t * o, uint_t delay);
186 /** set minimum inter onset interval in seconds
188 \param o onset detection object as returned by new_aubio_onset()
189 \param delay constant system delay to take back from detection time
193 uint_t aubio_onset_set_delay_s(aubio_onset_t * o, smpl_t delay);
195 /** set minimum inter onset interval in milliseconds
197 \param o onset detection object as returned by new_aubio_onset()
198 \param delay constant system delay to take back from detection time
202 uint_t aubio_onset_set_delay_ms(aubio_onset_t * o, smpl_t delay);
204 /** get minimum inter onset interval in samples
206 \param o onset detection object as returned by new_aubio_onset()
207 \return minimum interval between two consecutive onsets (in
211 uint_t aubio_onset_get_minioi(aubio_onset_t * o);
213 /** get minimum inter onset interval in seconds
215 \param o onset detection object as returned by new_aubio_onset()
216 \return minimum interval between two consecutive onsets (in
220 smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o);
222 /** get minimum inter onset interval in milliseconds
224 \param o onset detection object as returned by new_aubio_onset()
225 \return minimum interval between two consecutive onsets (in
229 smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o);
231 /** get minimum inter onset interval in samples
233 \param o onset detection object as returned by new_aubio_onset()
234 \return constant system delay to take back from detection time
238 uint_t aubio_onset_get_delay(aubio_onset_t * o);
240 /** get minimum inter onset interval in seconds
242 \param o onset detection object as returned by new_aubio_onset()
243 \return constant system delay to take back from detection time
247 smpl_t aubio_onset_get_delay_s(aubio_onset_t * o);
249 /** get minimum inter onset interval in milliseconds
251 \param o onset detection object as returned by new_aubio_onset()
252 \return constant system delay to take back from detection time
256 smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o);
258 /** delete onset detection object
260 \param o onset detection object to delete
263 void del_aubio_onset(aubio_onset_t * o);