From bc7c533928406751b74970129b2e9f93d115e744 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Thu, 1 Dec 2016 07:57:54 -0800 Subject: Throttle the CPU if there are no audio devices. --- src/com/jsyn/engine/SynthesisEngine.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/com/jsyn/engine/SynthesisEngine.java b/src/com/jsyn/engine/SynthesisEngine.java index ae16405..c79083e 100644 --- a/src/com/jsyn/engine/SynthesisEngine.java +++ b/src/com/jsyn/engine/SynthesisEngine.java @@ -319,8 +319,11 @@ public class SynthesisEngine implements Synthesizer { } loadAnalyzer = new LoadAnalyzer(); while (go) { + boolean throttled = false; if (audioInputStream != null) { + // This call will block when the input is empty. audioInputStream.read(inputBuffer.interleavedBuffer); + throttled = true; } loadAnalyzer.start(); @@ -331,6 +334,10 @@ public class SynthesisEngine implements Synthesizer { if (audioOutputStream != null) { // This call will block when the output is full. audioOutputStream.write(outputBuffer.interleavedBuffer); + throttled = true; + } + if (!throttled && isRealTime()) { + Thread.sleep(2); // avoid spinning and eating up CPU } } -- cgit v1.2.3