kopia lustrzana https://github.com/jameshball/osci-render
Massively improve audio stability on Mac
rodzic
9fdab5a4f1
commit
3089cd2b15
|
@ -2,6 +2,7 @@
|
|||
/.idea
|
||||
osci-render.iml
|
||||
*.osci
|
||||
*.log
|
||||
|
||||
# ignore temporary files
|
||||
*~
|
||||
|
|
|
@ -47,28 +47,26 @@ public class JavaAudioEngine implements AudioEngine {
|
|||
|
||||
// connects to a device that can support the format above (i.e. default audio device)
|
||||
this.source = AudioSystem.getSourceDataLine(format);
|
||||
source.open(format);
|
||||
|
||||
int bufferSize = calculateBufferSize(device, UNSTABLE_LATENCY_MS);
|
||||
int remainingBufferSpace = source.getBufferSize() - bufferSize;
|
||||
|
||||
byte[] buffer = new byte[bufferSize * 2];
|
||||
|
||||
source.open(format, buffer.length);
|
||||
|
||||
source.start();
|
||||
while (!stopped) {
|
||||
if (makeMoreStable || makeLessStable) {
|
||||
int newLatency = makeMoreStable ? STABLE_LATENCY_MS : UNSTABLE_LATENCY_MS;
|
||||
bufferSize = calculateBufferSize(device, newLatency);
|
||||
remainingBufferSpace = source.getBufferSize() - bufferSize;
|
||||
|
||||
buffer = new byte[bufferSize * 2];
|
||||
isStable = makeMoreStable;
|
||||
makeMoreStable = false;
|
||||
makeLessStable = false;
|
||||
}
|
||||
int delta = source.available() - remainingBufferSpace;
|
||||
if (delta > 0) {
|
||||
int requiredSamples = (delta + bufferSize) / FRAME_SIZE;
|
||||
|
||||
int requiredSamples = bufferSize / FRAME_SIZE;
|
||||
|
||||
if (requiredSamples * NUM_CHANNELS > buffer.length / 2) {
|
||||
buffer = new byte[requiredSamples * NUM_CHANNELS * 2];
|
||||
|
@ -92,7 +90,6 @@ public class JavaAudioEngine implements AudioEngine {
|
|||
|
||||
source.write(buffer, 0, requiredSamples * FRAME_SIZE);
|
||||
}
|
||||
}
|
||||
source.stop();
|
||||
this.device = null;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ public class Gui extends Application {
|
|||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
|
||||
System.setProperty("prism.lcdtext", "false");
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
|
||||
|
|
Ładowanie…
Reference in New Issue