1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
4 Vamp feature extraction plugins using Paul Brossier's Aubio library.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
25 Onset::Onset(float inputSampleRate
) :
26 Plugin(inputSampleRate
),
33 m_onsettype(aubio_onset_complex
),
42 if (m_onsetdet
) aubio_onsetdetection_free(m_onsetdet
);
43 if (m_ibuf
) del_fvec(m_ibuf
);
44 if (m_onset
) del_fvec(m_onset
);
45 if (m_fftgrain
) del_cvec(m_fftgrain
);
46 if (m_pv
) del_aubio_pvoc(m_pv
);
47 if (m_peakpick
) del_aubio_peakpicker(m_peakpick
);
51 Onset::getIdentifier() const
57 Onset::getName() const
59 return "Aubio Onset Detector";
63 Onset::getDescription() const
65 return "Estimate note onset times";
69 Onset::getMaker() const
71 return "Paul Brossier (plugin by Chris Cannam)";
75 Onset::getPluginVersion() const
81 Onset::getCopyright() const
87 Onset::initialise(size_t channels
, size_t stepSize
, size_t blockSize
)
89 m_channelCount
= channels
;
90 m_stepSize
= stepSize
;
91 m_blockSize
= blockSize
;
93 m_ibuf
= new_fvec(stepSize
, channels
);
94 m_onset
= new_fvec(1, channels
);
95 m_fftgrain
= new_cvec(blockSize
, channels
);
96 m_pv
= new_aubio_pvoc(blockSize
, stepSize
, channels
);
97 m_peakpick
= new_aubio_peakpicker(m_threshold
);
99 m_onsetdet
= new_aubio_onsetdetection(m_onsettype
, blockSize
, channels
);
101 m_delay
= Vamp::RealTime::frame2RealTime(4 * stepSize
,
102 lrintf(m_inputSampleRate
));
104 m_lastOnset
= Vamp::RealTime::zeroTime
- m_delay
- m_delay
;
115 Onset::getPreferredStepSize() const
121 Onset::getPreferredBlockSize() const
123 return 2 * getPreferredStepSize();
127 Onset::getParameterDescriptors() const
131 ParameterDescriptor desc
;
132 desc
.identifier
= "onsettype";
133 desc
.name
= "Onset Detection Function Type";
136 desc
.defaultValue
= (int)aubio_onset_complex
;
137 desc
.isQuantized
= true;
138 desc
.quantizeStep
= 1;
139 desc
.valueNames
.push_back("Energy Based");
140 desc
.valueNames
.push_back("Spectral Difference");
141 desc
.valueNames
.push_back("High-Frequency Content");
142 desc
.valueNames
.push_back("Complex Domain");
143 desc
.valueNames
.push_back("Phase Deviation");
144 desc
.valueNames
.push_back("Kullback-Liebler");
145 desc
.valueNames
.push_back("Modified Kullback-Liebler");
146 list
.push_back(desc
);
148 desc
= ParameterDescriptor();
149 desc
.identifier
= "peakpickthreshold";
150 desc
.name
= "Peak Picker Threshold";
153 desc
.defaultValue
= 0.3;
154 desc
.isQuantized
= false;
155 list
.push_back(desc
);
157 desc
= ParameterDescriptor();
158 desc
.identifier
= "silencethreshold";
159 desc
.name
= "Silence Threshold";
160 desc
.minValue
= -120;
162 desc
.defaultValue
= -90;
164 desc
.isQuantized
= false;
165 list
.push_back(desc
);
171 Onset::getParameter(std::string param
) const
173 if (param
== "onsettype") {
175 } else if (param
== "peakpickthreshold") {
177 } else if (param
== "silencethreshold") {
185 Onset::setParameter(std::string param
, float value
)
187 if (param
== "onsettype") {
188 switch (lrintf(value
)) {
189 case 0: m_onsettype
= aubio_onset_energy
; break;
190 case 1: m_onsettype
= aubio_onset_specdiff
; break;
191 case 2: m_onsettype
= aubio_onset_hfc
; break;
192 case 3: m_onsettype
= aubio_onset_complex
; break;
193 case 4: m_onsettype
= aubio_onset_phase
; break;
194 case 5: m_onsettype
= aubio_onset_kl
; break;
195 case 6: m_onsettype
= aubio_onset_mkl
; break;
197 } else if (param
== "peakpickthreshold") {
199 } else if (param
== "silencethreshold") {
205 Onset::getOutputDescriptors() const
210 d
.identifier
= "onsets";
213 d
.hasFixedBinCount
= true;
215 d
.sampleType
= OutputDescriptor::VariableSampleRate
;
219 d
= OutputDescriptor();
220 d
.identifier
= "detectionfunction";
221 d
.name
= "Onset Detection Function";
223 d
.hasFixedBinCount
= true;
224 d
.binCount
= m_channelCount
;
225 d
.hasKnownExtents
= false;
226 d
.isQuantized
= false;
227 d
.sampleType
= OutputDescriptor::OneSamplePerStep
;
234 Onset::process(const float *const *inputBuffers
,
235 Vamp::RealTime timestamp
)
237 for (size_t i
= 0; i
< m_stepSize
; ++i
) {
238 for (size_t j
= 0; j
< m_channelCount
; ++j
) {
239 fvec_write_sample(m_ibuf
, inputBuffers
[j
][i
], j
, i
);
243 aubio_pvoc_do(m_pv
, m_ibuf
, m_fftgrain
);
244 aubio_onsetdetection(m_onsetdet
, m_fftgrain
, m_onset
);
246 bool isonset
= aubio_peakpick_pimrt(m_onset
, m_peakpick
);
249 if (aubio_silence_detection(m_ibuf
, m_silence
)) {
254 FeatureSet returnFeatures
;
257 if (timestamp
- m_lastOnset
>= m_delay
) {
259 onsettime
.hasTimestamp
= true;
260 if (timestamp
< m_delay
) timestamp
= m_delay
;
261 onsettime
.timestamp
= timestamp
- m_delay
;
262 returnFeatures
[0].push_back(onsettime
);
263 m_lastOnset
= timestamp
;
267 for (size_t j
= 0; j
< m_channelCount
; ++j
) {
268 feature
.values
.push_back(m_onset
->data
[j
][0]);
270 returnFeatures
[1].push_back(feature
);
272 return returnFeatures
;
276 Onset::getRemainingFeatures()