<div>I did some of my own experimentation, which seems to point to method calls themselves (even with all of the calculation inside them commented out) being responsible for much of the cpu use of HevyMetl.</div><div><br></div>
I&#39;ve been using STK all along with the assumption that all calls to tick() without frames, or any other per-sample function call was going to be significantly less efficient than operating on buffers. I&#39;m aware of the existence of inlining, but not savvy enough to understand if it&#39;s happening or not, and under what conditions it can happen. It seems suspicious to me to think that inlining could happen on pointers. I mean, if you have a pointer to an stk::Generator, and you call tick() on it, I don&#39;t see how the compiler could know ahead of time which subclass of Generator it should be inlining. <div>
<br></div><div>I&#39;d love to find out that all my meticulous buffer passing in order to get reasonably performant code is unnecessary, but until I understand otherwise, or better, I&#39;m working with the assumption that method calls are expensive and best to minimize. Another thing I like about calculating samples in batches/buffers/stkframes is it allows me to use Apple&#39;s accelerate framework, which offers some very nice performance boosts.</div>
<div><br></div><div>However, I certainly trust Gary&#39;s assertion that this HevyMetl ran just fine on 90&#39;s machines, and I&#39;m very curious about what has changed. Has the code itself changed, breaking inlining? Is there something about method calls on the Apple hardware that makes them much more expensive than on Gary&#39;s 90&#39;s hardware?</div>
<div><br></div><div>From a place of great ignorance and curiosity.</div><div><br></div><div>-Morgan<br><br><div class="gmail_quote">On Tue, Sep 18, 2012 at 11:07 AM, Stephen Sinclair <span dir="ltr">&lt;<a href="mailto:sinclair@music.mcgill.ca" target="_blank">sinclair@music.mcgill.ca</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I also messed around a little with a program used to time a bunch of<br>
calls to HevyMetl::tick().  It was indeed slower than e.g. Clarinet.<br>
I couldn&#39;t get to the bottom of it, but for what it&#39;s worth removing<br>
the calls to setFrequency() made it about twice as fast.  Removing<br>
those and all calls to tick() (for ADSR and wave objects) made it like<br>
10 times faster.<br>
<br>
Not sure why this stuff would be slow, as I traced through and<br>
couldn&#39;t find an unexpected amount of indirections and virtual calls.<br>
I had a quick look at assembly output to see about inlining but had<br>
trouble immediately making sense of it.  I think there were some<br>
&quot;call&quot; instructions in there, but it didn&#39;t seem like a lot of them.<br>
I would want to step through the assembly with a debugger but don&#39;t<br>
really have time for that right now.<br>
<br>
I played around with removing the std::vectors, and also removing the<br>
indirection of the arrays (e.g. making them arrays of ADSR instead of<br>
ADSR*), and also using link-time optimisation, none of which seems to<br>
really help.<br>
<br>
Steve<br>
<br>
On Tue, Sep 18, 2012 at 10:39 AM, Tristan Matthews<br>
&lt;<a href="mailto:le.businessman@gmail.com">le.businessman@gmail.com</a>&gt; wrote:<br>
&gt; 2012/9/17 Rumi Humphrey &lt;rumi@refresh.vu&gt;:<br>
<div class="im HOEnZb">&gt;&gt; I think you can get your (modified for momu) FM class to compile if you<br>
&gt;&gt; comment out this line in FM.h:<br>
&gt;&gt;<br>
&gt;&gt; virtual StkFrames&amp; tick( StkFrames&amp; frames, unsigned int channel = 0 ) = 0;<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m not exactly sure why that is or how to use tick with frames i think the<br>
&gt;&gt; MoMu version of STK might implement it differently or something.<br>
&gt;&gt;<br>
&gt;&gt; Unfortunately though doing this and using arrays instead of vectors didn&#39;t<br>
&gt;&gt; seem to help performance that much at least not on my ipod touch. I&#39;m still<br>
&gt;&gt; only able to get one voice to play using HevyMetl.<br>
&gt;<br>
</div><div class="im HOEnZb">&gt; How does your hardware handle denormal floats? The FM class contains a<br>
&gt; TwoZero filter,<br>
&gt; which I believe can lead to denormals. You could try adding a small DC<br>
&gt; offset the samples<br>
&gt; before they are input to the TwoZero filter.<br>
&gt;<br>
&gt; This article has some background, as well as how to test denormal<br>
&gt; computation on your hardware:<br>
&gt; <a href="http://stackoverflow.com/questions/9350810/denormalized-floating-point-in-objective-c" target="_blank">http://stackoverflow.com/questions/9350810/denormalized-floating-point-in-objective-c</a><br>
&gt;<br>
&gt; The only other thing I might try is changing StkFloat from double to float.<br>
&gt;<br>
&gt; Best,<br>
&gt; Tristan<br>
&gt;<br>
&gt;&gt;<br>
</div><div class="HOEnZb"><div class="h5">&gt;&gt; On Sep 17, 2012, at 7:27 PM, Patrick J. Collins wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hmmm..  So after I put replaced the FM files with those two that you<br>
&gt;&gt; provided, building failed first because of:<br>
&gt;&gt;  #include &quot;SKINI.msg&quot;<br>
&gt;&gt;<br>
&gt;&gt; Claiming that file was not found...  I changed it to what it was<br>
&gt;&gt; previously:<br>
&gt;&gt;<br>
&gt;&gt;  #include &quot;Skini_msg.h&quot;<br>
&gt;&gt;<br>
&gt;&gt; Then the .cp failed with:<br>
&gt;&gt;        if ( nOperators_ == 0 ) {<br>
&gt;&gt;            oStream_ &lt;&lt; &quot;FM::FM: Number of operators must be greater than<br>
&gt;&gt; zero!&quot;;<br>
&gt;&gt;            handleError( StkError::FUNCTION_ARGUMENT );<br>
&gt;&gt;        }<br>
&gt;&gt;<br>
&gt;&gt; Saying &quot;use of undeclared identifier oStream_&quot;...  So I changed that to<br>
&gt;&gt; errorString_ as it was before...<br>
&gt;&gt;<br>
&gt;&gt; Then finally after doing that, the build fails at a point in my own code<br>
&gt;&gt; where I am doing:<br>
&gt;&gt;<br>
&gt;&gt;  // in my .h:<br>
&gt;&gt;    HevyMetl *instrument[4];<br>
&gt;&gt;<br>
&gt;&gt;  // in my .mm:<br>
&gt;&gt;    voicer = new Voicer();<br>
&gt;&gt;    instrument[0] = new HevyMetl();<br>
&gt;&gt;    instrument[1] = new HevyMetl();<br>
&gt;&gt;    voicer-&gt;addInstrument(instrument[0]);<br>
&gt;&gt;    voicer-&gt;addInstrument(instrument[1]);<br>
&gt;&gt;    voicer-&gt;silence();<br>
&gt;&gt;<br>
&gt;&gt; ...  It&#39;s failing at &quot;new HevyMetl()&quot; saying &quot;Allocating an object of<br>
&gt;&gt; abstract class type &#39;HevyMetl&#39;&quot;...<br>
&gt;&gt;<br>
&gt;&gt; Patrick J. Collins<br>
&gt;&gt; <a href="http://collinatorstudios.com" target="_blank">http://collinatorstudios.com</a><br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Stk mailing list<br>
&gt;&gt; <a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
&gt;&gt; <a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Stk mailing list<br>
&gt;&gt; <a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
&gt;&gt; <a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div><div class="im HOEnZb">&gt; --<br>
&gt; Tristan Matthews<br>
&gt; web: <a href="http://tristanswork.blogspot.com" target="_blank">http://tristanswork.blogspot.com</a><br>
&gt;<br>
</div><div class="HOEnZb"><div class="h5">&gt; _______________________________________________<br>
&gt; Stk mailing list<br>
&gt; <a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
&gt; <a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
Stk mailing list<br>
<a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
<a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><font size="1" color="#999999">===============</font></div><div><font size="1" color="#999999">Morgan Packard</font></div><div><font size="1" color="#999999">cell: (720) 891-0122</font></div>
<div><font size="1" color="#999999">aim: mpackardatwork</font></div><div><font size="1" color="#999999">twitter: @morganpackard</font></div><br>
</div>