Skip to content

Commit

Permalink
sceMp3: better handling of audio looping
Browse files Browse the repository at this point in the history
  • Loading branch information
gid15 committed Nov 2, 2015
1 parent a6181d8 commit 25281bc
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/jpcsp/HLE/modules/sceMp3.java
Expand Up @@ -152,6 +152,7 @@ public static class Mp3Info extends AudiocodecInfo {
private int outputIndex;
private int loopNum;
private int startPos;
private long endPos;
private int sampleRate;
private int bitRate;
private int maxSamples;
Expand All @@ -170,6 +171,7 @@ public void reserve(int bufferAddr, int bufferSize, int outputAddr, int outputSi
this.outputAddr = outputAddr;
this.outputSize = outputSize;
this.startPos = (int) startPos;
this.endPos = endPos;
inputBuffer = new pspFileBuffer(bufferAddr + reservedBufferSize, bufferSize - reservedBufferSize, 0, this.startPos);
inputBuffer.setFileMaxSize((int) endPos);
loopNum = -1; // Looping indefinitely by default
Expand Down Expand Up @@ -206,7 +208,12 @@ public pspFileBuffer getInputBuffer() {
}

public boolean isStreamDataNeeded() {
boolean isDataNeeded = getWritableBytes() > 0;
boolean isDataNeeded;
if (inputBuffer.isFileEnd()) {
isDataNeeded = false;
} else {
isDataNeeded = getWritableBytes() > 0;
}

return isDataNeeded;
}
Expand Down Expand Up @@ -267,16 +274,18 @@ public int decode(TPointer32 outputBufferAddress) {
result = outputBytes;
}

if (inputBuffer.getCurrentSize() < minimumInputBufferSize && inputBuffer.isFileEnd() && loopNum != 0) {
if (log.isDebugEnabled()) {
log.debug(String.format("Looping loopNum=%d", loopNum));
}
if (inputBuffer.isFileEnd() && loopNum != 0) {
if (inputBuffer.getCurrentSize() < minimumInputBufferSize || (inputBuffer.getFilePosition() - inputBuffer.getCurrentSize()) > endPos) {
if (log.isDebugEnabled()) {
log.debug(String.format("Looping loopNum=%d", loopNum));
}

if (loopNum > 0) {
loopNum--;
}
if (loopNum > 0) {
loopNum--;
}

resetPlayPosition(0);
resetPlayPosition(0);
}
}
}

Expand Down

0 comments on commit 25281bc

Please sign in to comment.