aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2016-12-01 07:57:54 -0800
committerPhil Burk <[email protected]>2016-12-01 07:57:54 -0800
commitbc7c533928406751b74970129b2e9f93d115e744 (patch)
tree1b3e4387b1ffc589171a39663c3db35a75459dab /src
parentd8b670ca9dd985fd987cae992019ae1b77a83d8f (diff)
Throttle the CPU if there are no audio devices.
Diffstat (limited to 'src')
-rw-r--r--src/com/jsyn/engine/SynthesisEngine.java7
1 files changed, 7 insertions, 0 deletions
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
}
}