comparison code-doc/PercussionOnsetDetector_8cpp-source.html @ 21:cc0be37dc9d3 website

* Updates for 2.0
author cannam
date Tue, 09 Dec 2008 11:02:57 +0000
parents 351c4ebce5f9
children 0976232e353b
comparison
equal deleted inserted replaced
20:34e758355884 21:cc0be37dc9d3
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3 <title>VampPluginSDK: PercussionOnsetDetector.cpp Source File</title> 3 <title>VampPluginSDK: PercussionOnsetDetector.cpp Source File</title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css"> 4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 <link href="tabs.css" rel="stylesheet" type="text/css"> 5 <link href="tabs.css" rel="stylesheet" type="text/css">
6 </head><body> 6 </head><body>
7 <!-- Generated by Doxygen 1.5.5 --> 7 <!-- Generated by Doxygen 1.5.6 -->
8 <div class="navigation" id="top"> 8 <div class="navigation" id="top">
9 <div class="tabs"> 9 <div class="tabs">
10 <ul> 10 <ul>
11 <li><a href="main.html"><span>Main&nbsp;Page</span></a></li> 11 <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
12 <li><a href="namespaces.html"><span>Namespaces</span></a></li> 12 <li><a href="namespaces.html"><span>Namespaces</span></a></li>
16 </ul> 16 </ul>
17 </div> 17 </div>
18 <div class="navpath"><a class="el" href="dir_35887283b966ca996e4ff77f459c38ce.html">examples</a> 18 <div class="navpath"><a class="el" href="dir_35887283b966ca996e4ff77f459c38ce.html">examples</a>
19 </div> 19 </div>
20 </div> 20 </div>
21 </div> 21 <div class="contents">
22 <h1>PercussionOnsetDetector.cpp</h1><a href="PercussionOnsetDetector_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */</span> 22 <h1>PercussionOnsetDetector.cpp</h1><a href="PercussionOnsetDetector_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */</span>
23 <a name="l00002"></a>00002 23 <a name="l00002"></a>00002
24 <a name="l00003"></a>00003 <span class="comment">/*</span> 24 <a name="l00003"></a>00003 <span class="comment">/*</span>
25 <a name="l00004"></a>00004 <span class="comment"> Vamp</span> 25 <a name="l00004"></a>00004 <span class="comment"> Vamp</span>
26 <a name="l00005"></a>00005 <span class="comment"></span> 26 <a name="l00005"></a>00005 <span class="comment"></span>
264 <a name="l00243"></a>00243 <span class="keywordtype">float</span> sqrmag = real * real + imag * imag; 264 <a name="l00243"></a>00243 <span class="keywordtype">float</span> sqrmag = real * real + imag * imag;
265 <a name="l00244"></a>00244 265 <a name="l00244"></a>00244
266 <a name="l00245"></a>00245 <span class="keywordflow">if</span> (<a class="code" href="classPercussionOnsetDetector.html#30daa717267251a9d49afe57c328e989">m_priorMagnitudes</a>[i] &gt; 0.f) { 266 <a name="l00245"></a>00245 <span class="keywordflow">if</span> (<a class="code" href="classPercussionOnsetDetector.html#30daa717267251a9d49afe57c328e989">m_priorMagnitudes</a>[i] &gt; 0.f) {
267 <a name="l00246"></a>00246 <span class="keywordtype">float</span> diff = 10.f * log10f(sqrmag / <a class="code" href="classPercussionOnsetDetector.html#30daa717267251a9d49afe57c328e989">m_priorMagnitudes</a>[i]); 267 <a name="l00246"></a>00246 <span class="keywordtype">float</span> diff = 10.f * log10f(sqrmag / <a class="code" href="classPercussionOnsetDetector.html#30daa717267251a9d49afe57c328e989">m_priorMagnitudes</a>[i]);
268 <a name="l00247"></a>00247 268 <a name="l00247"></a>00247
269 <a name="l00248"></a>00248 <span class="comment">// std::cout &lt;&lt; "i=" &lt;&lt; i &lt;&lt; ", mag=" &lt;&lt; mag &lt;&lt; ", prior=" &lt;&lt; m_priorMagnitudes[i] &lt;&lt; ", diff=" &lt;&lt; diff &lt;&lt; ", threshold=" &lt;&lt; m_threshold &lt;&lt; std::endl;</span> 269 <a name="l00248"></a>00248 <span class="comment">// std::cout &lt;&lt; "i=" &lt;&lt; i &lt;&lt; ", sqrmag=" &lt;&lt; sqrmag &lt;&lt; ", prior=" &lt;&lt; m_priorMagnitudes[i] &lt;&lt; ", diff=" &lt;&lt; diff &lt;&lt; ", threshold=" &lt;&lt; m_threshold &lt;&lt; " " &lt;&lt; (diff &gt;= m_threshold ? "[*]" : "") &lt;&lt; std::endl;</span>
270 <a name="l00249"></a>00249 270 <a name="l00249"></a>00249
271 <a name="l00250"></a>00250 <span class="keywordflow">if</span> (diff &gt;= <a class="code" href="classPercussionOnsetDetector.html#b04119adad56d87f2e633de289aab507">m_threshold</a>) ++count; 271 <a name="l00250"></a>00250 <span class="keywordflow">if</span> (diff &gt;= <a class="code" href="classPercussionOnsetDetector.html#b04119adad56d87f2e633de289aab507">m_threshold</a>) ++count;
272 <a name="l00251"></a>00251 } 272 <a name="l00251"></a>00251 }
273 <a name="l00252"></a>00252 273 <a name="l00252"></a>00252
274 <a name="l00253"></a>00253 <a class="code" href="classPercussionOnsetDetector.html#30daa717267251a9d49afe57c328e989">m_priorMagnitudes</a>[i] = sqrmag; 274 <a name="l00253"></a>00253 <a class="code" href="classPercussionOnsetDetector.html#30daa717267251a9d49afe57c328e989">m_priorMagnitudes</a>[i] = sqrmag;
283 <a name="l00262"></a>00262 283 <a name="l00262"></a>00262
284 <a name="l00263"></a>00263 <span class="keywordflow">if</span> (<a class="code" href="classPercussionOnsetDetector.html#6ad7d8353cc681ff42a63b127cca5779">m_dfMinus2</a> &lt; <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> &amp;&amp; 284 <a name="l00263"></a>00263 <span class="keywordflow">if</span> (<a class="code" href="classPercussionOnsetDetector.html#6ad7d8353cc681ff42a63b127cca5779">m_dfMinus2</a> &lt; <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> &amp;&amp;
285 <a name="l00264"></a>00264 <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> &gt;= count &amp;&amp; 285 <a name="l00264"></a>00264 <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> &gt;= count &amp;&amp;
286 <a name="l00265"></a>00265 <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> &gt; ((100 - <a class="code" href="classPercussionOnsetDetector.html#4e9770f246ba3bc75e7fc2cb8f9010af">m_sensitivity</a>) * <a class="code" href="classPercussionOnsetDetector.html#920de543dbcf70a2edd80b5b31313285">m_blockSize</a>) / 200) { 286 <a name="l00265"></a>00265 <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> &gt; ((100 - <a class="code" href="classPercussionOnsetDetector.html#4e9770f246ba3bc75e7fc2cb8f9010af">m_sensitivity</a>) * <a class="code" href="classPercussionOnsetDetector.html#920de543dbcf70a2edd80b5b31313285">m_blockSize</a>) / 200) {
287 <a name="l00266"></a>00266 287 <a name="l00266"></a>00266
288 <a name="l00267"></a>00267 <a class="code" href="structVamp_1_1Plugin_1_1Feature.html">Feature</a> onset; 288 <a name="l00267"></a>00267 <span class="comment">//std::cout &lt;&lt; "result at " &lt;&lt; ts &lt;&lt; "! (count == " &lt;&lt; count &lt;&lt; ", prev == " &lt;&lt; m_dfMinus1 &lt;&lt; ")" &lt;&lt; std::endl;</span>
289 <a name="l00268"></a>00268 onset.<a class="code" href="structVamp_1_1Plugin_1_1Feature.html#98907091d0b6a589720ae35ae588a82b" title="True if an output feature has its own timestamp.">hasTimestamp</a> = <span class="keyword">true</span>; 289 <a name="l00268"></a>00268
290 <a name="l00269"></a>00269 onset.<a class="code" href="structVamp_1_1Plugin_1_1Feature.html#caa605f36839c07e76f4882f5e22d8d7" title="Timestamp of the output feature.">timestamp</a> = ts - <a class="code" href="structVamp_1_1RealTime.html#3a5ecc8888b559aad3b7d96911786b3a" title="Convert a sample frame at the given sample rate into a RealTime.">Vamp::RealTime::frame2RealTime</a> 290 <a name="l00269"></a>00269 <a class="code" href="structVamp_1_1Plugin_1_1Feature.html">Feature</a> onset;
291 <a name="l00270"></a>00270 (<a class="code" href="classPercussionOnsetDetector.html#abac0cf7e961482b075777e5f0686e6c">m_stepSize</a>, lrintf(<a class="code" href="classVamp_1_1Plugin.html#59b9dd82a4f4eb946cd0474cc81abc23">m_inputSampleRate</a>)); 291 <a name="l00270"></a>00270 onset.<a class="code" href="structVamp_1_1Plugin_1_1Feature.html#98907091d0b6a589720ae35ae588a82b" title="True if an output feature has its own timestamp.">hasTimestamp</a> = <span class="keyword">true</span>;
292 <a name="l00271"></a>00271 returnFeatures[0].push_back(onset); 292 <a name="l00271"></a>00271 onset.<a class="code" href="structVamp_1_1Plugin_1_1Feature.html#caa605f36839c07e76f4882f5e22d8d7" title="Timestamp of the output feature.">timestamp</a> = ts - <a class="code" href="structVamp_1_1RealTime.html#939b4b1d1ca190db69a418883f16ce8a" title="Convert a sample frame at the given sample rate into a RealTime.">Vamp::RealTime::frame2RealTime</a>
293 <a name="l00272"></a>00272 } 293 <a name="l00272"></a>00272 (<a class="code" href="classPercussionOnsetDetector.html#abac0cf7e961482b075777e5f0686e6c">m_stepSize</a>, <span class="keywordtype">int</span>(<a class="code" href="classVamp_1_1Plugin.html#59b9dd82a4f4eb946cd0474cc81abc23">m_inputSampleRate</a> + 0.5));
294 <a name="l00273"></a>00273 294 <a name="l00273"></a>00273 returnFeatures[0].push_back(onset);
295 <a name="l00274"></a>00274 <a class="code" href="classPercussionOnsetDetector.html#6ad7d8353cc681ff42a63b127cca5779">m_dfMinus2</a> = <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a>; 295 <a name="l00274"></a>00274 }
296 <a name="l00275"></a>00275 <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> = count; 296 <a name="l00275"></a>00275
297 <a name="l00276"></a>00276 297 <a name="l00276"></a>00276 <a class="code" href="classPercussionOnsetDetector.html#6ad7d8353cc681ff42a63b127cca5779">m_dfMinus2</a> = <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a>;
298 <a name="l00277"></a>00277 <span class="keywordflow">return</span> returnFeatures; 298 <a name="l00277"></a>00277 <a class="code" href="classPercussionOnsetDetector.html#cd80162c65212be7fa91251263fb9c3d">m_dfMinus1</a> = count;
299 <a name="l00278"></a>00278 } 299 <a name="l00278"></a>00278
300 <a name="l00279"></a>00279 300 <a name="l00279"></a>00279 <span class="keywordflow">return</span> returnFeatures;
301 <a name="l00280"></a>00280 <a class="code" href="classVamp_1_1Plugin.html#448fb57dc245d47923ec9eeaf9856c5f">PercussionOnsetDetector::FeatureSet</a> 301 <a name="l00280"></a>00280 }
302 <a name="l00281"></a><a class="code" href="classPercussionOnsetDetector.html#d3d6767ed137783e84f842b4d4732ffa">00281</a> <a class="code" href="classPercussionOnsetDetector.html#d3d6767ed137783e84f842b4d4732ffa" title="After all blocks have been processed, calculate and return any remaining features...">PercussionOnsetDetector::getRemainingFeatures</a>() 302 <a name="l00281"></a>00281
303 <a name="l00282"></a>00282 { 303 <a name="l00282"></a>00282 <a class="code" href="classVamp_1_1Plugin.html#448fb57dc245d47923ec9eeaf9856c5f">PercussionOnsetDetector::FeatureSet</a>
304 <a name="l00283"></a>00283 <span class="keywordflow">return</span> <a class="code" href="classVamp_1_1Plugin.html#448fb57dc245d47923ec9eeaf9856c5f">FeatureSet</a>(); 304 <a name="l00283"></a><a class="code" href="classPercussionOnsetDetector.html#d3d6767ed137783e84f842b4d4732ffa">00283</a> <a class="code" href="classPercussionOnsetDetector.html#d3d6767ed137783e84f842b4d4732ffa" title="After all blocks have been processed, calculate and return any remaining features...">PercussionOnsetDetector::getRemainingFeatures</a>()
305 <a name="l00284"></a>00284 } 305 <a name="l00284"></a>00284 {
306 <a name="l00285"></a>00285 306 <a name="l00285"></a>00285 <span class="keywordflow">return</span> <a class="code" href="classVamp_1_1Plugin.html#448fb57dc245d47923ec9eeaf9856c5f">FeatureSet</a>();
307 <a name="l00286"></a>00286 }
308 <a name="l00287"></a>00287
307 </pre></div></div> 309 </pre></div></div>
308 <hr size="1"><address style="text-align: right;"><small>Generated on Wed Jul 9 11:36:06 2008 for VampPluginSDK by&nbsp; 310 <hr size="1"><address style="text-align: right;"><small>Generated on Mon Dec 8 14:37:18 2008 for VampPluginSDK by&nbsp;
309 <a href="http://www.doxygen.org/index.html"> 311 <a href="http://www.doxygen.org/index.html">
310 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address> 312 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
311 </body> 313 </body>
312 </html> 314 </html>