title: Core Audio iOS: Retrieving the past & future timestamps for captured & to-be-rendered samples
body: <h2>Question</h2>
  
  <p>I have a very simple iOS Core Audio application with the following structure:</p>
  
  <p><code>Remote I/O Unit Input Bus --&gt; Render Callback --&gt; Remote I/O Unit Output Bus</code></p>
  
  <p>The render callback function, invoked by the Remote I/O output bus, pulls samples from the input hardware by calling <code>AudioUnitRender()</code> on the Remote I/O input bus. It then processes/affects these samples, writing to the supplied <code>AudioBufferList*</code> and returns, causing the affected samples to be played via the output hardware. All works well.</p>
  
  <p>My question is how can I know, or calculate, the <strong>precise</strong> time at which:</p>
  
  <ul>
  <li>The samples were captured by the input hardware</li>
  <li>The samples were actually played on the output hardware</li>
  </ul>
  
  <h2>Discussion</h2>
  
  <p>An <code>AudioTimeStamp</code> struct is passed into the render callback with valid <code>mHostTime</code>, <code>mSampleTime</code> &amp; <code>mRateScalar</code> values. It is not clear to me exactly what this time stamp reflects. The documentation states:</p>
  
  <blockquote>
    <p><em>inTimeStamp</em>
    The timestamp associated with this call of audio unit render.</p>
  </blockquote>
  
  <p>This sounds like it represents the time the render was invoked, but how does that relate (if at all) to the time at which the input samples <strong>were</strong> captured and the output samples <strong>will be</strong> rendered?</p>
  
  <p>Several resources online speak of using <code>mach_absolute_time()</code> or <code>CACurrentMediaTime()</code> to calculate the current host time, however again I can't seem to make the connection from current host time to past or future host time.</p>
  
  <p>The following quote from an Apple mailing list thread talks of three time stamps, including a separate time stamp for both input data in the past and output data in the future. This is exactly what I am looking for, however I believe this is running on OS X and using the AUHAL I/O. I cannot find a way of retrieving these time stamps on iOS.</p>
  
  <blockquote>
    <p>So, the way CoreAudio works is that an I/O proc fires and gives you 3
    time stamps: (1) Is the time stamp of the input data - if any of
    course. This will always be at least a buffer size in the past (2) Is
    the time stamp for now - when the I/O proc was woken up to run (3) Is
    the time stamp for the output data you will provide. This will is
    always some time in the future - usually it is a buffer size in the
    future. (<a href="http://lists.apple.com/archives/coreaudio-api/2005/Sep/msg00220.html" rel="noreferrer">http://lists.apple.com/archives/coreaudio-api/2005/Sep/msg00220.html</a>)</p>
  </blockquote>
  
  <p>I suspect I may be missing something obvious so hopefully someone can shed some light on this.</p>
  
  <p>Thanks in advance.</p>