<div dir="ltr"><div><div><div><div><div>Hi everybody,<br></div>I've been thinking about latency compensation in the context of making a Pd external for Ableton Link. For the purposes of latency sensitive externals, it would be good to have functions in m_pd.h that allow externals to query the input and output latencies of the underlying platform. There's no general way to discover those values; the audio glue would have to implement them individually for each audio API. For some platforms we'd have to eyeball the latency figures, but that would still be useful.<br><br>The sample code that comes with the Link distribution may be instructive here: <a href="https://github.com/Ableton/link/tree/master/examples/linkaudio">https://github.com/Ableton/link/tree/master/examples/linkaudio</a><br><br></div>Those samples use the latency provided by the audio API when available. Otherwise, e.g., for JACK, they seem to use audio buffer size as a proxy for latency.<br><br></div>Shall we consider adding latency-related functions to m_pd.h?<br></div>Cheers,<br></div>     Peter<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 19, 2016 at 10:20 AM, david medine <span dir="ltr"><<a href="mailto:dmedine@ucsd.edu" target="_blank">dmedine@ucsd.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><span class="">
    <br>
    <blockquote type="cite">
      <div>
        <blockquote type="cite">
          <div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">why don't  you patch a little tester app that
              sends some generated<br>
              sounds, preferably with very clear attack, out and record
              this back<br>
              in. that way you can measure the (roundtrip) latency of
              the whole<br>
              system.<br>
            </blockquote>
            <br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Of course, that is a way.
              "Knowing" the latency instead of "measuring"</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">it would be so nice, though.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
          </div>
        </blockquote>
        of course knowing is better than measuring :)</div>
      <div><br>
      </div>
      <div>i think it is easy enough to measure roundtrip latency, it is
        harder to measure just “output” latency.</div>
    </blockquote></span>
    A good way to do this is to make this patch: [adc~]-[dac~]. Then,
    attach one channel of your scope to an old (cut-able) audio cable
    connected to the input and another channel to another old cable on
    the output. Then just send pulses or snap your fingers or whatever
    and look at the lag on the scope. <br>
    <br>
    Whatever the latency is that results from DtoA will be nearly
    identical on the AtoD side because any pro audio device is going to
    have exactly the same filter on both ends. The sampling part of the
    conversion is nearly instantaneous. It depends on your audio backend
    how (when) the samples get pushed and pulled onto the CPU but that
    will be short too, especially if you set the latency value in Pd's
    to as low as it will go. So the RTT is the only thing you can
    measure, but it will probably be very, very close to 2x the output
    latency (unless you use Windows, in which case all bets are off!). <br><div><div class="h5">
    <br>
    <blockquote type="cite">
      <div><br>
      </div>
      <div><br>
        <blockquote type="cite">
          <div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">with a click track and a good musician that plays
              with it (that you<br>
              record) you should be able to align generated sounds and
              live<br>
              recorded material. this is how we do it in the studio if
              necessary :)<br>
              but it is far from an automated process...<br>
            </blockquote>
            <br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">To make things at least a bit
              more feasible, I make the measured or</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">calculated latency a
              configuration parameter, so that when you fire Pd</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">up the next time with the
              same setup, the patch remembers the latency.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
          </div>
        </blockquote>
        that sounds reasonable.<br>
        <blockquote type="cite">
          <div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Roman</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Am Sonntag, 9. Oktober 2016 schrieb Roman Haefeli
              :<br>
              <blockquote type="cite">Hi all, <br>
                <br>
                I'm currently investigating audio latency compensation
                in Pd. The<br>
                goal<br>
                is for recorded audio to align well with generated
                sounds timing-<br>
                wise.<br>
                I'm wondering now what methods people already have
                employed in<br>
                order to<br>
                achieve that goal.<br>
                <br>
                So far, I was able to find the formulas to calculate the
                correct<br>
                latency when using ALSA and JACK audio back-ends as long
                as the<br>
                paramaters 'Delay(msec)' and 'Block size' for ALSA,
                respectively<br>
                'Frames/period' and 'Periods/buffer' for JACK are known.
                Currently,<br>
                this approach works, but requires me to tell the latency<br>
                compensation<br>
                calculator what driver I'm using and what the current
                settings are.<br>
                Also, it yet only works on Linux, but not with any other
                drivers<br>
                like<br>
                CoreAudio, ASIO, etc.<br>
                <br>
                How can I achieve correct latency compensation reliably
                on any<br>
                platform? Is there some more generic way?<br>
                <br>
                I'm also looking at IEM's mediasettings library, hoping
                it would<br>
                deliver the required information to calculate latency.
                The<br>
                README.txt<br>
                says 'get/set Audio and MIDI settings within Pd', but I
                wasn't able<br>
                to<br>
                find a way to _get_ current settings other than 'advance
                100',<br>
                which<br>
                probably refers to 'Delay(msec)' set to '100'. But
                still, if it<br>
                would<br>
                give all Pd audio settings, how would it know about
                current jackd<br>
                settings?<br>
                <br>
                Roman</blockquote>
            </blockquote>
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">______________________________<wbr>_________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <a href="mailto:Pd-list@lists.iem.at" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">Pd-list@lists.iem.at</a><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span class="m_3427372947451087842Apple-converted-space"> </span>mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
            <span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">UNSUBSCRIBE and
              account-management -><span class="m_3427372947451087842Apple-converted-space"> </span></span><a href="https://lists.puredata.info/listinfo/pd-list" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.puredata.<wbr>info/listinfo/pd-list</a></div>
        </blockquote>
      </div>
      <br>
      <br>
      <fieldset class="m_3427372947451087842mimeAttachmentHeader"></fieldset>
      <br>
      <pre>______________________________<wbr>_________________
<a class="m_3427372947451087842moz-txt-link-abbreviated" href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a> mailing list
UNSUBSCRIBE and account-management -> <a class="m_3427372947451087842moz-txt-link-freetext" href="https://lists.puredata.info/listinfo/pd-list" target="_blank">https://lists.puredata.info/<wbr>listinfo/pd-list</a>
</pre>
    </blockquote>
    <p><br>
    </p>
  </div></div></div>

<br>______________________________<wbr>_________________<br>
<a href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">https://lists.puredata.info/<wbr>listinfo/pd-list</a><br>
<br></blockquote></div><br></div>