<div dir="ltr"><div>Hi Joel, Perry,</div><div><br></div><div>thanks for getting back to me. I remember there was a discussion about SinOsc, just I couldn&#39;t remember the outcome of that. <br></div><div>I&#39;ll give SndBuf/Wavetable/GenX a try and report some results back here in case there are any worth sharing.</div><div><br></div><div>thanks,<br></div><div>Mario<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 23 Oct 2018 at 22:43, Joel Matthys &lt;<a href="mailto:jwmatthys@gmail.com">jwmatthys@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi Mario.</div><br><div>We had a discussion about this on the chuck-dev a couple of years ago, when I created the Wavetable Chugin. I&#39;ve copied below a very interesting comment from Perry Cook. To my surprise, on modern architectures, RT trig isn&#39;t really any more expensive than table lookup. I tested the Wavetable chugin vs SinOsc and found no significant difference in performance.</div><br><div>I still think a wavetable UGen would be a good addition to ChucK (maybe adapted from my Chugin) but it seems that, unless someone were able to create some additional optimizations, it wouldn&#39;t be any more efficient than the existing SinOsc.</div><br><div>Joel</div><br><div>-------------------</div><div>Forwarded message from Perry Cook below:</div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Hey all,</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Chiming in on the various Sine-related topics here. SinOsc was designed like most of ChucK, to do things from the definition, without particular regard for  efficiencies. In fact, a native Math.sin(BLAH) call isn’t that hideous. It used to be in the olden days, and we avoided it like the plague. The Motorola DSP 56000 had a built in quarter-wave of sine in ROM. (It also had an 8-bit muLaw decoding table built in as well). Many papers (Snell, Others) were written about the optimal length, bit-depth, etc of a sine table given different types of interpolation. Yamaha chips stored sine quads in both linear (for addition) and log (for multiplication) ROM, or hard-coded into gates for the absolute minimum expense.</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Wavetables:</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Indeed, SndBuf is ChucK’s built-in wavetable (in .loop mode). And, it could be a  little cheaper, and it has built-in linear interpolation. If you want less distortion, just make your table longer. The “table” here is a .wav file you create and load.  All you need add is an accessing function to set rate as a function of frequency.</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">And you could also add FM, PM, and other .sync-like functions as well. By this time, it might be worth comparing to SinOsc efficiency for FM and other audio- rate modulation tho. I just did a quick check and find SndBuf to be about equal to SinOsc (the number I can run before audio starts breaking up, just over 400).</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">See code below.</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Note also that there are some other wavetable-like UGens already in the GenX family in ChucK. I don’t know about the relative efficiency of those, and I do know that that you need to drive (some of) them with a Phasor. So again, it might not end up being significantly cheaper.</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">On unit-circle sine generation: Spencer has already given us a great ChuGen called MagicSine, that does the rotation-based sine generation using only a couple of multiplies and adds. It’s most efficient if you’re not changing frequency rapidly.</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Julius and I also did a “waveguide resonator” oscillator (similar to Magic  Sine), but it also had built in exponential envelope (phasor that spins outward or inward), and allowed for modulation of the parameters for FM-like wave distortion. Not particularly efficient if you just want a sine wave. I have a ChuGen for that too, but never released it.</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">So the topic &quot;many ways to skin a sine&quot; is still active today!! </font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">My comparison codes (in terminal, miniAudicle may vary, also Audio BUFSIZE might help):</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">/* SinOscCompare.ck ***************************************/</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">SinOsc s[1000];</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Gain outMix =&gt; dac;</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">for (int i; i &lt; 4000; i++) {</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">if (i%100 == 0) &lt;&lt;&lt; &quot;Sines&quot;, i+1 &gt;&gt;&gt;; // this could be costing us some</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">s[i] =&gt; outMix;</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Math.random2f(100,3000) =&gt; s[i].freq; // as would this</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">1.0/(i+1.0) =&gt; outMix.gain; // and this</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">10*ms =&gt; now; // but if those dominated, we’d probably hear 100 Hz distortion</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">}</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">/* SndBufCompare.ck ***************************************/</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">SndBuf s[1000];</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Gain outMix =&gt; dac;</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">for (int i; i &lt; 4000; i++) {</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">if (i%100 == 0) &lt;&lt;&lt; &quot;SndBufs&quot;, i+1 &gt;&gt;&gt;; // this could be costing us some</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">&quot;special:dope&quot; =&gt; s[i].read; // maybe this too, but cacheing should help</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">1 =&gt; s[i].loop;</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">s[i] =&gt; outMix;</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">Math.random2f(0.2,5.0) =&gt; s[i].rate; // as would this</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">1.0/(i+1.0) =&gt; outMix.gain; // and this</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">10*ms =&gt; now; // but if those dominated, we’d probably hear 100 Hz distortion</font></font></span></div><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">}</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">_______________________________________________</font></font></span></div><br><div><span style="color:rgb(35,31,32)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif">chuck-dev mailing list</font></font></span></div><br><div><span style="color:rgb(16,129,247)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif"><a href="https://link.getmailspring.com/link/1540330200.local-c32b839e-ac26-v1.4.2-f587b7b7@getmailspring.com/0?redirect=mailto%3Achuck-dev%40lists.cs.princeton.edu&amp;recipient=Y2h1Y2stdXNlcnNAbGlzdHMuY3MucHJpbmNldG9uLmVkdQ%3D%3D" title="mailto:chuck-dev@lists.cs.princeton.edu" target="_blank">chuck-dev@lists.cs.princeton.edu</a></font></font></span></div><br><div><span style="color:rgb(16,129,247)"><font style="font-size:14.5px"><font style="font-family:Nylas-Pro,Helvetica,&quot;Lucidia Grande&quot;,sans-serif"><a href="https://link.getmailspring.com/link/1540330200.local-c32b839e-ac26-v1.4.2-f587b7b7@getmailspring.com/1?redirect=https%3A%2F%2Flists.cs.princeton.edu%2Fmailman%2Flistinfo%2Fchuck-dev&amp;recipient=Y2h1Y2stdXNlcnNAbGlzdHMuY3MucHJpbmNldG9uLmVkdQ%3D%3D" title="https://lists.cs.princeton.edu/mailman/listinfo/chuck-dev" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-dev</a></font></font></span></div><br><br><div><u></u><div><div>Sent from <a href="https://link.getmailspring.com/link/1540330200.local-c32b839e-ac26-v1.4.2-f587b7b7@getmailspring.com/2?redirect=https%3A%2F%2Fgetmailspring.com%2F&amp;recipient=Y2h1Y2stdXNlcnNAbGlzdHMuY3MucHJpbmNldG9uLmVkdQ%3D%3D" target="_blank">Mailspring</a>, the best free email app for work</div></div><u></u></div><div class="m_8386564549742317305gmail_quote_attribution">On Oct 23 2018, at 9:28 am, Mario Buoninfante &lt;<a href="mailto:mario.buoninfante@gmail.com" target="_blank">mario.buoninfante@gmail.com</a>&gt; wrote:</div><blockquote><br><div><div><div>Hi,</div><div><br></div><div>As already pointed out by someone else here, I noticed we&#39;ve got the SinOsc UGen that doesn&#39;t use a wavetable but instead uses the sin function. I don&#39;t know what the reason behind this decision, but I was wondering whether it would be possible to also have a variant that uses wavetable as well. I presume that would help a bit in terms of performances, and I think it would be useful in scenarios where ChucK runs on platforms like Raspberry Pi.</div><div><br></div><div>cheers,</div><div><div>Mario</div></div></div><div>_______________________________________________</div><div>chuck-users mailing list</div><div><a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a></div><div><a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a></div></div></blockquote>_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</blockquote></div>