Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed terribly stupid bug causing latency. Lingering popping now though.

  • Loading branch information...
commit cbd8c94eaabf9a4e6c70c8ff198cab74644e4203 1 parent 0c43025
@finnkuusisto authored
View
13 src/kuusisto/tinysound/TinySound.java
@@ -219,18 +219,19 @@ public static void update(boolean fillNextBuffer) {
if (!TinySound.inited) {
System.err.println("TinySound not initialized!");
return;
- } //read from the mixer (maybe this should be synchronized)
- if (TinySound.numBytesRead <= 0) {
+ }
+ //read from the mixer if not filling for the next update
+ if (TinySound.numBytesRead <= 0 && !fillNextBuffer) {
TinySound.fillAudioBuffer();
}
//and write to the speakers
int numBytesWritten = 0;
while (numBytesWritten < TinySound.numBytesRead) {
- numBytesWritten = TinySound.outLine.write(TinySound.audioBuffer,
+ numBytesWritten += TinySound.outLine.write(TinySound.audioBuffer,
numBytesWritten, TinySound.numBytesRead);
}
TinySound.numBytesRead = 0;
- //now refill the buffer if desired
+ //now fill the buffer for the next update if desired
if (fillNextBuffer) {
TinySound.fillAudioBuffer();
}
@@ -262,7 +263,9 @@ private static void fillAudioBuffer() {
}
TinySound.numBytesRead = length;
//accrue drift
- TinySound.driftFramesAccrued += TinySound.driftFramesPerUpdate;
+ if (length == TinySound.audioBuffer.length) {
+ TinySound.driftFramesAccrued += TinySound.driftFramesPerUpdate;
+ }
}
/**
View
6 src/kuusisto/tinysound/internal/UpdateRunner.java
@@ -68,12 +68,14 @@ public void run() {
//keep running until told to stop
while (this.running.get()) {
long currTime = System.nanoTime();
- if ((currTime - lastUpdate) >= nanosPerUpdate) {
+ long delta = currTime - lastUpdate;
+ if (delta >= nanosPerUpdate) {
TinySound.update();
+ lastUpdate = currTime;
}
//give the CPU back to the OS for a bit
try {
- Thread.sleep(0, 100000);
+ Thread.sleep(0, 500000);
} catch (InterruptedException e) {}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.