<div dir="ltr"><div>Thanks, Arthur.</div><div><br></div><div>Not all commercial synths discretize events to the frame boundaries. For example, it&#39;s possible to trigger Native Instruments Battery with sample accuracy when sequenced via a DAW, and even when being triggered via external MIDI it does so with sub-frame accuracy within the limits of the host MIDI driver. I have no illusions of achieving sample accuracy, but if I can achieve sub-frame accuracy I will be happy. My intended application is percussion-oriented so low jitter is a very desirable property for me. I understand that RtMidi has been designed for ease of use, and not necessarily for the highest performance.<br></div><div><br></div><div>I&#39;m measuring the delta between MIDI events in the callback using a high_resolution_clock, and the delta times differ from those reported by the callback somewhat significantly, sometimes &gt; 1ms. I suppose this is due to the low precision of the timestamps with the Windows MM API? Or is the timestamp reliable, and there is a variable time between the MIDI event and the callback invocation? I haven&#39;t measured the jitter in the audio callback yet. If the time between audio callbacks is reasonably stable then the system clock might be a reliable-enough reference.<br></div><div><br></div><div>Also, perhaps this is a bug, but the delta time for the first event is not zero, but some (often large) value like 4291232.2280 seconds. If that&#39;s unexpected then I can file an issue on GitHub.<br></div><div><br></div><div>Thanks,</div><div><br></div><div>Tim<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 12, 2022 at 4:38 PM Arthur Benilov &lt;<a href="mailto:arthur.benilov@gmail.com">arthur.benilov@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Tim,<div>You can timestamp the MIDI events relative to the next audio frame using the system steady clock. The very first MIDI event received will have delta time zero, all following events will have delta time measured relative to the first event. By relating these to the system clock and the system time recorded at the audio callback you can estimate for a particular MIDI event its time within the next audio frame. Also you don&#39;t need to be sample-perfect, all commercial software synths I know will discretize the MIDI events processing within an audio frame to 16 or 32 samples @44.1-48kHz. You may also let the jitter be and just decrease the audio frame size to minimize it (Raspberry Pi will be able to do 256 samples per frame @44.1kHz with its onboard audio), it may not be that critical for an instrument you are developing.</div><div><br></div><div>Cheers,</div><div><br></div><div>Arthur.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 12, 2022 at 10:06 PM Tim Grant &lt;<a href="mailto:tim@rootdown.net" target="_blank">tim@rootdown.net</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello!<br><br>I&#39;ve recently started prototyping a synthesizer project using RtAudio and RtMidi. I&#39;m doing the initial development in Windows and I plan to eventually port the project to something like a Raspberry Pi if the prototype goes well.</div><div><br></div><div>I have the audio output and MIDI input working, and I&#39;m starting to think about triggering the synth voices with MIDI notes. I would like to keep the jitter between the notes and the triggered sounds low, but I&#39;m not quite sure how to achieve this with these two APIs.</div><div><br></div><div>A diagram might be helpful here:<br><span style="font-family:monospace">MIDI      -----N----------------------N--------------------------&gt;<br>Input          |                      |<br>               |                      |<br>Audio     |----*-----|----P-----|-----*----|-----P----|----------&gt;<br>Stream       Frame 1    Frame 2    Frame 3    Frame 4    Frame 5</span></div><div><br></div><div>My thinking is that I need to know at what point in the current audio frame an MIDI note arrives. From the diagram, assume a note (N) arrives at the moment corresponding to the 5th sample in Frame 1; knowing this, I can begin playback at the 5th sample on the next frame (P). This way, the latency is held constant at 1 frame and the amount of jitter is minimized.</div><div><br></div><div>So with that long-winded introduction out of the way, my question is:</div><div><br></div><div>Is it possible to recover the timing of MIDI events relative to the audio stream? I can&#39;t see how to do this using the delta time provided with the MIDI note and the stream time provided by RtAudio, but my hope is that I&#39;m missing something.</div><div><br></div><div>Thanks!</div><div><br></div><div>Tim<br></div></div>
_______________________________________________<br>
Stk mailing list<br>
<a href="mailto:Stk@ccrma.stanford.edu" target="_blank">Stk@ccrma.stanford.edu</a><br>
<a href="https://cm-mail.stanford.edu/mailman/listinfo/stk" rel="noreferrer" target="_blank">https://cm-mail.stanford.edu/mailman/listinfo/stk</a><br>
</blockquote></div>
</blockquote></div>