<div dir="ltr"><div><br></div><div>Hi all,</div><div><br></div><div>I'm working on a software synthesizer based on JavaSound in Windows 10, and I have been encountering inexplicably long delays in srcLine.write() operation.</div><div><br></div><div>Most of the time, it works just fine, but I've traced the problem to a particular voice I've created that is somehow different. It involves more computation, is all I can figure. When I play that sound I get gaps in the playback. (I know about the latency and jitter of MIDI messages. This is different) But if the problem is the surfeit of computation, why does the delay show up in srcLine.write(), and not in the time my own code takes?</div><div><br></div><div>I'm using a 2k buffer, (16 bit stereo 44.1khz) so it has about 46 ms for each buffer-full.
I'm using System.nanoTime() to measure timing.
</div><div><br></div><div>My code completes its part in about 10ms, as a rough average. But never even close to 46. And the srcLine.write() portion of the cycle fills in (blocks) for the rest of the 46 ms, approximately, most of the time.</div><div><br></div><div>However, sometimes when I'm playing this sound, srcLine.write() will occasionally, sometimes for no apparent reason, block for over 200 ms, which puts an audible (ugly) gap in the sound. As far as I can tell, there is 100% correspondence between these gaps and the long srcLine.write() blocking. It seems to happen when I'm playing lots of notes, hence more computation, I guess, although that doesn't show up as a significant increase in my code's work in the log. The only increase is in the gap introduced by srcLine.write() blocking. </div><div><br></div><div>I've split everything out onto separate threads, and set the priority highest for the "dispatcher" and lowest for my own threads. Doesn't help. I've made sure all the resource allocation happens beforehand, so it is pooling the voices rather than creating from "new." Doesn't help. </div><div><br></div><div>And I don't see anything significant in terms of CPU usage in jconsole or Task Manager. </div><div><br></div><div>Here is what I am running: </div><div><br></div><div>$ java -version<br>openjdk version "11.0.7" 2020-04-14 LTS<br>OpenJDK Runtime Environment 18.9 (build 11.0.7+10-LTS)<br>OpenJDK 64-Bit Server VM 18.9 (build 11.0.7+10-LTS, mixed mode)<br></div><div><br></div><div>Source code is on github</div><div><a href="https://github.com/mlzarathustra/ondes">https://github.com/mlzarathustra/ondes</a> <br></div><div><br></div><div> Any insight would be appreciated. </div><div><br></div><div>Thanks,</div><div> -=miles=-</div><div><br></div><div><br></div></div>