<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.13"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>aubio: examples/aubionotes.c</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="search/searchdata.js"></script> <script type="text/javascript" src="search/search.js"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ extensions: ["tex2jax.js"], jax: ["input/TeX","output/HTML-CSS"], }); </script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">aubio  <span id="projectnumber">0.4.2~alpha</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.13 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> $(function() { initMenu('',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); </script> <div id="main-nav"></div> </div><!-- top --> <!-- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> </div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> <div class="header"> <div class="headertitle"> <div class="title">examples/aubionotes.c</div> </div> </div><!--header--> <div class="contents"> <div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> This file is part of aubio.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> aubio is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment"> the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment"> (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> aubio is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><span class="comment"> GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment"> along with aubio. If not, see <http://www.gnu.org/licenses/>.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">*/</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define AUBIO_UNSTABLE 1 // for fvec_median</span></div><div class="line"><span class="preprocessor">#include "utils.h"</span></div><div class="line"><span class="preprocessor">#define PROG_HAS_PITCH 1</span></div><div class="line"><span class="preprocessor">#define PROG_HAS_ONSET 1</span></div><div class="line"><span class="preprocessor">#define PROG_HAS_JACK 1</span></div><div class="line"><span class="comment">// TODO add PROG_HAS_OUTPUT</span></div><div class="line"><span class="preprocessor">#include "parse_args.h"</span></div><div class="line"></div><div class="line"><a class="code" href="types_8h.html#a12a1e9b3ce141648783a82445d02b58d">uint_t</a> median = 6;</div><div class="line"></div><div class="line"><a name="_a0"></a><a class="code" href="structfvec__t.html">fvec_t</a> *note_buffer;</div><div class="line"><a class="code" href="structfvec__t.html">fvec_t</a> *note_buffer2;</div><div class="line"></div><div class="line"><a class="code" href="types_8h.html#a5d7119468d78a1dc35cf76d0adfb1436">smpl_t</a> curnote = 0.;</div><div class="line"><a class="code" href="types_8h.html#a5d7119468d78a1dc35cf76d0adfb1436">smpl_t</a> newnote = 0.;</div><div class="line"><a class="code" href="types_8h.html#a12a1e9b3ce141648783a82445d02b58d">uint_t</a> isready = 0;</div><div class="line"></div><div class="line"><a class="code" href="pitch_8h.html#af76b14582e2b766e6b325038fe6426a0">aubio_pitch_t</a> *pitch;</div><div class="line"><a class="code" href="onset_8h.html#aab9be831df71952f95d3685f86fce281">aubio_onset_t</a> *o;</div><div class="line"><a class="code" href="structfvec__t.html">fvec_t</a> *onset;</div><div class="line"><a class="code" href="structfvec__t.html">fvec_t</a> *pitch_obuf;</div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">/** append new note candidate to the note_buffer and return filtered value. we</span></div><div class="line"><span class="comment"> * need to copy the input array as fvec_median destroy its input data.*/</span></div><div class="line"><span class="keywordtype">void</span> note_append (<a class="code" href="structfvec__t.html">fvec_t</a> * note_buffer, <a class="code" href="types_8h.html#a5d7119468d78a1dc35cf76d0adfb1436">smpl_t</a> curnote);</div><div class="line"><a class="code" href="types_8h.html#a12a1e9b3ce141648783a82445d02b58d">uint_t</a> get_note (<a class="code" href="structfvec__t.html">fvec_t</a> * note_buffer, <a class="code" href="structfvec__t.html">fvec_t</a> * note_buffer2);</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> process_block (<a class="code" href="structfvec__t.html">fvec_t</a> *ibuf, <a class="code" href="structfvec__t.html">fvec_t</a> *obuf)</div><div class="line">{</div><div class="line"> <a class="code" href="types_8h.html#a5d7119468d78a1dc35cf76d0adfb1436">smpl_t</a> new_pitch, curlevel;</div><div class="line"> <a name="a1"></a><a class="code" href="fvec_8h.html#aab4522ad4c26322858ecce0e7aad08ea">fvec_zeros</a>(obuf);</div><div class="line"> <a name="a2"></a><a class="code" href="onset_8h.html#aa38ddf8ec5fd506a870567fbe73c03d5">aubio_onset_do</a>(o, ibuf, onset);</div><div class="line"></div><div class="line"> <a name="a3"></a><a class="code" href="pitch_8h.html#aa813fd341d5af4c0dc672e319b0f0195">aubio_pitch_do</a> (pitch, ibuf, pitch_obuf);</div><div class="line"> new_pitch = <a name="a4"></a><a class="code" href="fvec_8h.html#ac4adbfa24102a9611e188df7b3da05d0">fvec_get_sample</a>(pitch_obuf, 0);</div><div class="line"> <span class="keywordflow">if</span>(median){</div><div class="line"> note_append(note_buffer, new_pitch);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/* curlevel is negatif or 1 if silence */</span></div><div class="line"> curlevel = <a name="a5"></a><a class="code" href="musicutils_8h.html#a6fbd8fb35d0547fcbba8c3a058c5b0cd">aubio_level_detection</a>(ibuf, silence_threshold);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="fvec_8h.html#ac4adbfa24102a9611e188df7b3da05d0">fvec_get_sample</a>(onset, 0)) {</div><div class="line"> <span class="comment">/* test for silence */</span></div><div class="line"> <span class="keywordflow">if</span> (curlevel == 1.) {</div><div class="line"> <span class="keywordflow">if</span> (median) isready = 0;</div><div class="line"> <span class="comment">/* send note off */</span></div><div class="line"> send_noteon(curnote,0);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="keywordflow">if</span> (median) {</div><div class="line"> isready = 1;</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="comment">/* kill old note */</span></div><div class="line"> send_noteon(curnote,0);</div><div class="line"> <span class="comment">/* get and send new one */</span></div><div class="line"> send_noteon(new_pitch,127+(<span class="keywordtype">int</span>)floor(curlevel));</div><div class="line"> curnote = new_pitch;</div><div class="line"> }</div><div class="line"> }</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="keywordflow">if</span> (median) {</div><div class="line"> <span class="keywordflow">if</span> (isready > 0)</div><div class="line"> isready++;</div><div class="line"> <span class="keywordflow">if</span> (isready == median)</div><div class="line"> {</div><div class="line"> <span class="comment">/* kill old note */</span></div><div class="line"> send_noteon(curnote,0);</div><div class="line"> newnote = get_note(note_buffer, note_buffer2);</div><div class="line"> curnote = newnote;</div><div class="line"> <span class="comment">/* get and send new one */</span></div><div class="line"> <span class="keywordflow">if</span> (curnote>45){</div><div class="line"> send_noteon(curnote,127+(<span class="keywordtype">int</span>)floor(curlevel));</div><div class="line"> }</div><div class="line"> }</div><div class="line"> } <span class="comment">// if median</span></div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> process_print (<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line"> <span class="comment">//if (verbose) outmsg("%f\n",pitch_obuf->data[0]);</span></div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span></div><div class="line">note_append (<a class="code" href="structfvec__t.html">fvec_t</a> * note_buffer, <a class="code" href="types_8h.html#a5d7119468d78a1dc35cf76d0adfb1436">smpl_t</a> curnote)</div><div class="line">{</div><div class="line"> <a class="code" href="types_8h.html#a12a1e9b3ce141648783a82445d02b58d">uint_t</a> i = 0;</div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < note_buffer-><a name="a6"></a><a class="code" href="structfvec__t.html#a419b7cd4468c28f824c917aa8c3f93f3">length</a> - 1; i++) {</div><div class="line"> note_buffer-><a name="a7"></a><a class="code" href="structfvec__t.html#a14bf045394eb718428b8cd64573caa54">data</a>[i] = note_buffer-><a class="code" href="structfvec__t.html#a14bf045394eb718428b8cd64573caa54">data</a>[i + 1];</div><div class="line"> }</div><div class="line"> note_buffer-><a class="code" href="structfvec__t.html#a14bf045394eb718428b8cd64573caa54">data</a>[note_buffer-><a class="code" href="structfvec__t.html#a419b7cd4468c28f824c917aa8c3f93f3">length</a> - 1] = curnote;</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><a class="code" href="types_8h.html#a12a1e9b3ce141648783a82445d02b58d">uint_t</a></div><div class="line">get_note (<a class="code" href="structfvec__t.html">fvec_t</a> * note_buffer, <a class="code" href="structfvec__t.html">fvec_t</a> * note_buffer2)</div><div class="line">{</div><div class="line"> <a class="code" href="types_8h.html#a12a1e9b3ce141648783a82445d02b58d">uint_t</a> i;</div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < note_buffer-><a class="code" href="structfvec__t.html#a419b7cd4468c28f824c917aa8c3f93f3">length</a>; i++) {</div><div class="line"> note_buffer2-><a class="code" href="structfvec__t.html#a14bf045394eb718428b8cd64573caa54">data</a>[i] = note_buffer-><a class="code" href="structfvec__t.html#a14bf045394eb718428b8cd64573caa54">data</a>[i];</div><div class="line"> }</div><div class="line"> <span class="keywordflow">return</span> fvec_median (note_buffer2);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) {</div><div class="line"> examples_common_init(argc,argv);</div><div class="line"></div><div class="line"> verbmsg (<span class="stringliteral">"using source: %s at %dHz\n"</span>, source_uri, samplerate);</div><div class="line"></div><div class="line"> verbmsg (<span class="stringliteral">"onset method: %s, "</span>, onset_method);</div><div class="line"> verbmsg (<span class="stringliteral">"buffer_size: %d, "</span>, buffer_size);</div><div class="line"> verbmsg (<span class="stringliteral">"hop_size: %d, "</span>, hop_size);</div><div class="line"> verbmsg (<span class="stringliteral">"threshold: %f\n"</span>, onset_threshold);</div><div class="line"></div><div class="line"> verbmsg (<span class="stringliteral">"pitch method: %s, "</span>, pitch_method);</div><div class="line"> verbmsg (<span class="stringliteral">"buffer_size: %d, "</span>, buffer_size * 4);</div><div class="line"> verbmsg (<span class="stringliteral">"hop_size: %d, "</span>, hop_size);</div><div class="line"> verbmsg (<span class="stringliteral">"tolerance: %f\n"</span>, pitch_tolerance);</div><div class="line"></div><div class="line"> o = <a name="a8"></a><a class="code" href="onset_8h.html#a00512092dd9dde0cdf0cf73b9109c149">new_aubio_onset</a> (onset_method, buffer_size, hop_size, samplerate);</div><div class="line"> <span class="keywordflow">if</span> (onset_threshold != 0.) <a name="a9"></a><a class="code" href="onset_8h.html#a1e76a2deb5bce2f491bbee5e5707ef4a">aubio_onset_set_threshold</a> (o, onset_threshold);</div><div class="line"> onset = <a name="a10"></a><a class="code" href="fvec_8h.html#aa9bc0906651523429a4ebf7b4342fe73">new_fvec</a> (1);</div><div class="line"></div><div class="line"> pitch = <a name="a11"></a><a class="code" href="pitch_8h.html#a962561ea270e0308ed26ac9bab554550">new_aubio_pitch</a> (pitch_method, buffer_size * 4, hop_size, samplerate);</div><div class="line"> <span class="keywordflow">if</span> (pitch_tolerance != 0.) <a name="a12"></a><a class="code" href="pitch_8h.html#ac7f0342944d7fde3cd509021069ee74d">aubio_pitch_set_tolerance</a> (pitch, pitch_tolerance);</div><div class="line"> pitch_obuf = <a class="code" href="fvec_8h.html#aa9bc0906651523429a4ebf7b4342fe73">new_fvec</a> (1);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (median) {</div><div class="line"> note_buffer = <a class="code" href="fvec_8h.html#aa9bc0906651523429a4ebf7b4342fe73">new_fvec</a> (median);</div><div class="line"> note_buffer2 = <a class="code" href="fvec_8h.html#aa9bc0906651523429a4ebf7b4342fe73">new_fvec</a> (median);</div><div class="line"> }</div><div class="line"></div><div class="line"> examples_common_process((aubio_process_func_t)process_block, process_print);</div><div class="line"></div><div class="line"> <span class="comment">// send a last note off</span></div><div class="line"> send_noteon (curnote, 0);</div><div class="line"></div><div class="line"> <a name="a13"></a><a class="code" href="pitch_8h.html#a23f6b16eabb9bff3c4ee5876af69f832">del_aubio_pitch</a> (pitch);</div><div class="line"> <span class="keywordflow">if</span> (median) {</div><div class="line"> <a name="a14"></a><a class="code" href="fvec_8h.html#a86fad6d27aad91c910d1b48195922cb9">del_fvec</a> (note_buffer);</div><div class="line"> <a class="code" href="fvec_8h.html#a86fad6d27aad91c910d1b48195922cb9">del_fvec</a> (note_buffer2);</div><div class="line"> }</div><div class="line"> <a class="code" href="fvec_8h.html#a86fad6d27aad91c910d1b48195922cb9">del_fvec</a> (pitch_obuf);</div><div class="line"></div><div class="line"> examples_common_del();</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.13 </small></address> </body> </html>