title: How to get exact timestamp of audio recording start in with PortAudio?
body: <p>We are using PortAudio for recording audio in our electron application. As a node wrapper, we use naudiodon.</p>
  
  <p>The application needs to record both audio and video, but using different sources. Audio, as said, is being recorded with Port Audio, with additional app logic on top. Video, on the other hand, is being recorded with standard MediaRecorder API, with its own formats, properties, and codecs.</p>
  
  <p>We use event 'onstart' to track actual video start and in order to sync audio and video, we must also know the exact audio start time.</p>
  
  <p>Problem is: We are not able to detect that exact timestamp of audio start. What should be the correct way of doing it?</p>
  
  <p>Here is what we tried:</p>
  
  <p> 1. The first option is to listen to portaudio.AudioIO events, such as 'data' and 'readable'. Those are called as soon as PortAudio has new data chunk, so tracking the very first chunk minus its length in milliseconds would result in approximate audio start.</p>
  
  <p> 2. The second option is to add Writable pipe to AudioIO, and do pretty much the same thing as with events.</p>
  
  <p>The issue is, that by doing any of those options, calculated start doesn't always result in the actual timestamp of audio start. While playing around with port audio it was known, that calculated timestamp is higher than it should be, as though some chunks are being buffered before actually released.</p>
  
  <p>Actual audio start and first chunk release can be different, in a range of around 50 - 500 ms with chunk length ~50ms. So chunks might buffer sometimes, and sometimes they don't. Is there any way to track the actual start time of the first chunk? I wasn't able to find any relevant info in checking port audio docs.</p>
  
  <p>Maybe there are any other ways to keep using PortAudio and record video separately, but finally achieve the same desired feature, of synching them together? </p>
  
  <p>PortAudio 19.5, Naudiodon 2.1.0, Electron 6.0.9, Node.js 12.4.0</p>