<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,<br>
      <br>
      Just to follow up on this, I was using audio files with a
      different sample rate and that was obviously causing trouble.<br>
    </p>
    <p>When dealing with stereo files, both in SndBuf and SndBuf2
      samples are accessed in frames:</p>
    <p>```</p>
    <p>buffer[0] = sample 0 left channel<br>
    </p>
    <p>buffer[1] = sample 0 right channel<br>
    </p>
    <p>buffer[2] = sample 1 left channel<br>
    </p>
    <p>...</p>
    <p>```<br>
    </p>
    <p>The only thing that could be a bit misleading is that .samples()
      doesn't return the actual number of samples, but number of samples
      per channel.<br>
      Looking at the source code (ugen_xxx.cpp - row 770) I found the
      documentation for .samples() says:</p>
    <p>"Total number of sample in frames in the file"</p>
    <p>Thus what .samples() returns is technically correct, but I'm
      wondering couldn't this be a bit confusing? Maybe not and I should
      have just checked that out. Might be one for the SndBuf example.<br>
      <br>
      Cheers,</p>
    <p>Mario<br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 16/06/2021 17:03, Dana Batali wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAByuf_3A2qo7WBD8WVxAEhXYV8MZ7tNq_6ji1VyvkaqQ2H27=Q@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="auto">Hi Mario , I’m not at my computer right now, but
        wonder if you’ve tried SndBuf2?</div>
      <div><br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Wed, Jun 16, 2021 at 8:57
            AM mario buoninfante &lt;<a
              href="mailto:mario.buoninfante@gmail.com"
              moz-do-not-send="true">mario.buoninfante@gmail.com</a>&gt;
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">Hi,<br>
            <br>
            I'm working on an algorithm that requires accessing samples
            from a <br>
            stereo file and am using SndBuf to achieve that.<br>
            I was expecting that to work so that samples were returned
            in "frames", <br>
            for example:<br>
            <br>
            '''<br>
            <br>
            buffer.valueAt(0) = sample 0 on left channel<br>
            <br>
            buffer.valueAt(1) = sample 0 on right channel<br>
            <br>
            buffer.valueAt(2) = sample 1 on left channel<br>
            <br>
            buffer.valueAt(3) = sample 1 on right channel<br>
            <br>
            ...<br>
            <br>
            '''<br>
            <br>
            but that doesn't seem to be the case.<br>
            <br>
            Also SndBuf.samples() always returns the same amount of
            samples, <br>
            regardless the file being mono or stereo (the size matches
            the time in <br>
            msec, so it seems that reports the size of a single
            channel).<br>
            <br>
            I also played around with .channel(n), but I get the same
            set of samples <br>
            regardless the channel number used.<br>
            <br>
            Then I just now found out that basically the channels seem
            to be stored <br>
            (or at least accessed) sequentially.<br>
            Let's say you have a stereo file containing 1024 samples
            (512 per <br>
            channel), you get:<br>
            <br>
            samples 0-511 = left channel<br>
            <br>
            samples 512-1023 = right channel<br>
            <br>
            I was wondering if my assumption is correct, but also if
            this is <br>
            intentional.<br>
            <br>
            <br>
            Cheers,<br>
            <br>
            Mario<br>
            <br>
            <br>
            <br>
            -- <br>
            musician, QA engineer<br>
            <a href="http://mbuoninfante.tumblr.com/" rel="noreferrer"
              target="_blank" moz-do-not-send="true">http://mbuoninfante.tumblr.com/</a><br>
            <a href="https://vimeo.com/creativecodingsalerno"
              rel="noreferrer" target="_blank" moz-do-not-send="true">https://vimeo.com/creativecodingsalerno</a><br>
            <a href="https://github.com/mariobuoninfante"
              rel="noreferrer" target="_blank" moz-do-not-send="true">https://github.com/mariobuoninfante</a><br>
            <br>
            _______________________________________________<br>
            chuck-users mailing list<br>
            <a href="mailto:chuck-users@lists.cs.princeton.edu"
              target="_blank" moz-do-not-send="true">chuck-users@lists.cs.princeton.edu</a><br>
            <a
              href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users"
              rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
          </blockquote>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
chuck-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a>
<a class="moz-txt-link-freetext" href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
musician, QA engineer
<a class="moz-txt-link-freetext" href="http://mbuoninfante.tumblr.com/">http://mbuoninfante.tumblr.com/</a>
<a class="moz-txt-link-freetext" href="https://vimeo.com/creativecodingsalerno">https://vimeo.com/creativecodingsalerno</a>
<a class="moz-txt-link-freetext" href="https://github.com/mariobuoninfante">https://github.com/mariobuoninfante</a></pre>
  </body>
</html>