Skip to content

Commit

Permalink
Improved compatibility of sceAtracDecodeData: return less samples at …
Browse files Browse the repository at this point in the history
…the first call.
  • Loading branch information
gid15 committed Mar 7, 2015
1 parent a4d9bf4 commit d45d2ee
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/jpcsp/HLE/modules150/sceAtrac3plus.java
Expand Up @@ -166,6 +166,8 @@ public static class AtracID {
protected AtracFileInfo info;
protected int atracCurrentSample;
protected int maxSamples;
protected int skippedSamples;
private int startSkippedSamples;
protected int lastDecodedSamples;
protected int channels;
protected int outputChannels = 2; // Always default with 2 output channels
Expand Down Expand Up @@ -277,6 +279,20 @@ public int decodeData(int samplesAddr, TPointer32 outEndAddr) {
}
setAtracCurrentSample(nextCurrentSample);

if (currentSample == 0) {
skippedSamples = startSkippedSamples;
} else {
skippedSamples = 0;
}

if (skippedSamples > 0) {
Memory mem = Memory.getInstance();
int bytesPerSample = 2 * getOutputChannels();
int returnedSamples = getNumberOfSamples();
// Move the sample buffer to skip the needed samples
mem.memmove(samplesAddr, samplesAddr + skippedSamples * bytesPerSample, returnedSamples * bytesPerSample);
}

for (int i = 0; i < info.numLoops; i++) {
LoopInfo loop = info.loops[i];
if (currentSample <= loop.startSample && loop.startSample < nextCurrentSample) {
Expand Down Expand Up @@ -404,10 +420,13 @@ public void setCodecType(int codecType) {
this.codecType = codecType;
if (codecType == PSP_CODEC_AT3) {
maxSamples = Atrac3Decoder.SAMPLES_PER_FRAME;
startSkippedSamples = 69;
} else if (codecType == PSP_CODEC_AT3PLUS) {
maxSamples = Atrac3plusDecoder.ATRAC3P_FRAME_SAMPLES;
startSkippedSamples = 368;
} else {
maxSamples = 0;
startSkippedSamples = 0;
}
}

Expand Down Expand Up @@ -654,7 +673,7 @@ public void setCodecInitialized() {
}

public int getNumberOfSamples() {
return codec.getNumberOfSamples();
return codec.getNumberOfSamples() - skippedSamples;
}

public boolean isInUse() {
Expand Down

0 comments on commit d45d2ee

Please sign in to comment.