mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-14 20:06:16 +00:00
Drop audio samples if buffer space is not available to preserve real-time audio behavior
This commit is contained in:
@@ -20,7 +20,12 @@ public class JavaxAudioRenderer implements AudioRenderer {
|
|||||||
if (soundLine != null) {
|
if (soundLine != null) {
|
||||||
byte[] pcmDataBytes = new byte[length * 2];
|
byte[] pcmDataBytes = new byte[length * 2];
|
||||||
ByteBuffer.wrap(pcmDataBytes).asShortBuffer().put(pcmData, offset, length);
|
ByteBuffer.wrap(pcmDataBytes).asShortBuffer().put(pcmData, offset, length);
|
||||||
soundLine.write(pcmDataBytes, 0, pcmDataBytes.length);
|
if (soundLine.available() < length) {
|
||||||
|
soundLine.write(pcmDataBytes, 0, soundLine.available());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
soundLine.write(pcmDataBytes, 0, pcmDataBytes.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +42,7 @@ public class JavaxAudioRenderer implements AudioRenderer {
|
|||||||
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, OpusDecoder.getMaxOutputShorts());
|
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, OpusDecoder.getMaxOutputShorts());
|
||||||
try {
|
try {
|
||||||
soundLine = (SourceDataLine) AudioSystem.getLine(info);
|
soundLine = (SourceDataLine) AudioSystem.getLine(info);
|
||||||
soundLine.open(audioFormat, 131072);
|
soundLine.open(audioFormat, OpusDecoder.getMaxOutputShorts()*4*2);
|
||||||
soundLine.start();
|
soundLine.start();
|
||||||
} catch (LineUnavailableException e) {
|
} catch (LineUnavailableException e) {
|
||||||
soundLine = null;
|
soundLine = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user