<div dir="ltr"><div><div><div><div><div><div>Hi,<br><br></div>a quick update, basically there are a couple of things I missed before. I was using a stereo file in a mono SndBuf and the Phasor I was using to drive the Wavetable (I was copying the audio file into a Wavetable) needed twice the normal freq. it seems like loading a stereo file in a mono SndBuf means filling an array with samples form both left and right channel, something like:<br></div>sndbuf = [1_left, 1_right, 2_left, 2_right, 3_left, 3_right, ...] - numbers indicate sample number<br></div>of course I&#39;m not sure about that, but this will justify the fact that Phasor needs a freq twice faster then the expected one when I load a stereo file, and also the fact that the sample length is half the original.<br></div>apart from that, I think .valueAt() and .sample() both access to the raw data, as expected. <br></div><div>basically I think there&#39;s no issue with SndBuf at all, it was me not considering all this obvious thing when I used Phasor to read the file, and the issue  I was experiencing with this can be fixed simply multiplying phasor frequency by (audio file sample rate / ChucK sample rate).<br></div><div>ie to read the entire file at the original speed: phasor.freq( (1000*(audioFileSR/ChucK_SR)) / (sample2.samples()::samp/ms) ) - sorry for the terrible syntax, it&#39;s just to show the logic behind.<br></div><div>all this makes me think that it would be great having a method that returns the sample rate of the audio file loaded. :)<br><br></div><div>cheers,<br></div><div>Mario<br></div><div><br></div>cheers,<br></div>Mario<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 24, 2018 at 5:29 PM, Mario Buoninfante <span dir="ltr">&lt;<a href="mailto:mario.buoninfante@gmail.com" target="_blank">mario.buoninfante@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi Spencer,<br><br></div>thanks for your help, you&#39;re perfectly right about the floating point comparison, I didn&#39;t think about it. and I think you&#39;re also right when you say that valueAt() and samples() are ignoring the sample rate conversion made by SndBuf. What I didn&#39;t say in the previous mail is that the way I discovered this <span class="m_-6396922194180447783gmail-tlid-translation m_-6396922194180447783gmail-translation"><span title="" class="m_-6396922194180447783gmail-">discrepancy</span></span><span class="m_-6396922194180447783gmail-tlid-trans-verified-button m_-6396922194180447783gmail-trans-verified-button"></span> is when I transferred all the samples from SndBuf to Wavetable (chugin). basically I load an audio file in SndBuf then read trough it using valueAt() and copy all the samples into an array (array length set using .sample() ). then this array is used with Wavetable. I noticed that something was wrong when I played Wavetable with a Phasor and the pitch was wrong. only at that point I ran the test where I compared the 2 two SnbBuf .valueAt().<br></div>Btw later I&#39;ll have another look at .valueAt()/.samples()  and try to figure out whether they consider the sample rate conversion or not.<br><br></div>cheers,<br></div>Mario<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 24, 2018 at 5:11 PM, Spencer Salazar <span dir="ltr">&lt;<a href="mailto:spencer.salazar@gmail.com" target="_blank">spencer.salazar@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey Mario,<div><br></div><div>Thanks so much for your work on the manual, its looking great! </div><div><br></div><div>SndBuf/SndBuf2 are designed to resample the audio file to the native rate when doing audio playback, although off the top of my head I don&#39;t know if valueAt()/samples() are also resampling (seems like they shouldn&#39;t, to allow true sample-level access).  </div><div><br></div><div>Generally speaking, comparing two floats for exact equality is too rigorous for digital audio. Its preferred to test that they are &quot;close enough&quot; within a desired order of magnitude, e.g. Math.fabs(f1-f2) &lt; Math.fabs(f1)*<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">0.0001 (see e.g. [1]). </span></div><div><br></div><div>Secondly, there are at least two resamplings involved in this test (when you created perc2.wav, it was resampled from perc1.wav at 44100 to 48000, and then ChucK might be resampling it back to 44100). Under certain conditions resampling can be theoretically &quot;perfect,&quot; but otherwise its just making a guess what the sample would be at the new rate. Even under perfect conditions, the inexact nature of floating point arithmetic means that resampling from 44100 -&gt; 48000 -&gt; 44100 will most likely result in a different series of actual values. </div><div><br></div><div>Spencer</div><div><br></div><div>[1] <a href="http://floating-point-gui.de/errors/comparison/" target="_blank">http://floating-point-gui.<wbr>de/errors/comparison/</a></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-6396922194180447783h5">On Sat, Mar 24, 2018 at 8:59 AM, mario buoninfante <span dir="ltr">&lt;<a href="mailto:mario.buoninfante@gmail.com" target="_blank">mario.buoninfante@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-6396922194180447783h5">I forgot to say, that the program I posted in the previous mail returns a lot of errors, basically 97% of the file length. I suppose the samples which are the same are all 0. btw the bit depth is the same, they&#39;re both 16 bit.<br>
<br>
<br>
cheers,<br>
<br>
Mario</div></div><div class="m_-6396922194180447783m_-3413427898555113537HOEnZb"><div class="m_-6396922194180447783m_-3413427898555113537h5"><br>
<br>
______________________________<wbr>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton<wbr>.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu<wbr>/mailman/listinfo/chuck-users</a><br>
<br>
<br><span class="m_-6396922194180447783HOEnZb"><font color="#888888">
</font></span></div></div></blockquote></div><span class="m_-6396922194180447783HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="m_-6396922194180447783m_-3413427898555113537gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="font-family:arial;font-size:small"><div style="font-family:arial,sans-serif;font-size:12.8px"><font size="2">Spencer Salazar, PhD</font></div><div style="font-family:arial,sans-serif;font-size:12.8px"><font size="2">Special Faculty</font></div><div style="font-family:arial,sans-serif;font-size:12.8px"><font size="2">Music Technology: Interaction, Intelligence, and Design</font></div><div style="font-family:arial,sans-serif;font-size:12.8px"><font size="2">California Institute of the Arts</font></div><div style="font-family:arial,sans-serif;font-size:12.8px"><font size="2"><br></font></div><div style="font-family:arial,sans-serif;font-size:12.8px"><font size="2"><a href="mailto:ssalazar@calarts.edu" target="_blank">ssalazar@calarts.edu</a> | <a href="tel:(831)%20277-4654" value="+18312774654" target="_blank">+1 831.277.4654</a></font></div><div style="font-family:arial,sans-serif;font-size:12.8px"><font size="2"><a href="https://spencersalazar.com/" target="_blank">https://spencersalazar.com</a> </font></div><div><font size="2"><br></font></div></div></div></div>
</font></span></div>
<br>______________________________<wbr>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton<wbr>.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu<wbr>/mailman/listinfo/chuck-users</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>