Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues in Sol Trigger with atrac/sas #8192

Merged
merged 4 commits into from Nov 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Core/HLE/sceAtrac.cpp
Expand Up @@ -562,6 +562,7 @@ static Atrac *getAtrac(int atracID) {
// Read in any changes from the game to the context.
// TODO: Might be better to just always track in RAM.
atrac->bufferState = atrac->atracContext->info.state;
atrac->loopNum = atrac->atracContext->info.loopNum;
}

return atrac;
Expand Down Expand Up @@ -1858,6 +1859,9 @@ static u32 sceAtracSetLoopNum(int atracID, int loopNum) {
atrac->loopStartSample = atrac->firstSampleoffset + atrac->firstOffsetExtra();
atrac->loopEndSample = atrac->endSample + atrac->firstSampleoffset + atrac->firstOffsetExtra();
}
if (atrac->atracContext.IsValid()) {
_AtracGenerateContext(atrac, atrac->atracContext);
}
}
return 0;
}
Expand Down Expand Up @@ -2121,7 +2125,7 @@ void _AtracGenerateContext(Atrac *atrac, SceAtracId *context) {
context->info.dataOff = atrac->dataOff;
context->info.endSample = atrac->endSample + atrac->firstSampleoffset + atrac->firstOffsetExtra();
context->info.dataEnd = atrac->first.filesize;
context->info.curOff = atrac->getFileOffsetBySample(atrac->currentSample);
context->info.curOff = atrac->first.fileoffset;
context->info.decodePos = atrac->getDecodePosBySample(atrac->currentSample);
context->info.streamDataByte = atrac->first.size - atrac->dataOff;

Expand Down
59 changes: 28 additions & 31 deletions Core/HW/SasAudio.cpp
Expand Up @@ -182,49 +182,55 @@ void VagDecoder::DoState(PointerWrap &p) {
}

int SasAtrac3::setContext(u32 context) {
contextAddr = context;
atracID = _AtracGetIDByContext(context);
if (!sampleQueue)
sampleQueue = new BufferQueue();
sampleQueue->clear();
contextAddr_ = context;
atracID_ = _AtracGetIDByContext(context);
if (!sampleQueue_)
sampleQueue_ = new BufferQueue();
sampleQueue_->clear();
end_ = false;
return 0;
}

int SasAtrac3::getNextSamples(s16* outbuf, int wantedSamples) {
if (atracID < 0)
return -1;
void SasAtrac3::getNextSamples(s16 *outbuf, int wantedSamples) {
if (atracID_ < 0) {
end_ = true;
return;
}
u32 finish = 0;
int wantedbytes = wantedSamples * sizeof(s16);
while (!finish && sampleQueue->getQueueSize() < wantedbytes) {
while (!finish && sampleQueue_->getQueueSize() < wantedbytes) {
u32 numSamples = 0;
int remains = 0;
static s16 buf[0x800];
_AtracDecodeData(atracID, (u8*)buf, 0, &numSamples, &finish, &remains);
_AtracDecodeData(atracID_, (u8*)buf, 0, &numSamples, &finish, &remains);
if (numSamples > 0)
sampleQueue->push((u8*)buf, numSamples * sizeof(s16));
sampleQueue_->push((u8*)buf, numSamples * sizeof(s16));
else
finish = 1;
}
sampleQueue->pop_front((u8*)outbuf, wantedbytes);
return finish;
sampleQueue_->pop_front((u8*)outbuf, wantedbytes);
end_ = finish == 1;
}

int SasAtrac3::addStreamData(u32 bufPtr, u32 addbytes) {
if (atracID > 0) {
_AtracAddStreamData(atracID, bufPtr, addbytes);
if (atracID_ > 0) {
_AtracAddStreamData(atracID_, bufPtr, addbytes);
}
return 0;
}

void SasAtrac3::DoState(PointerWrap &p) {
auto s = p.Section("SasAtrac3", 1);
auto s = p.Section("SasAtrac3", 1, 2);
if (!s)
return;

p.Do(contextAddr);
p.Do(atracID);
if (p.mode == p.MODE_READ && atracID >= 0 && !sampleQueue) {
sampleQueue = new BufferQueue();
p.Do(contextAddr_);
p.Do(atracID_);
if (p.mode == p.MODE_READ && atracID_ >= 0 && !sampleQueue_) {
sampleQueue_ = new BufferQueue();
}
if (s >= 2) {
p.Do(end_);
}
}

Expand Down Expand Up @@ -436,15 +442,7 @@ void SasVoice::ReadSamples(s16 *output, int numSamples) {
}
break;
case VOICETYPE_ATRAC3:
{
int ret = atrac3.getNextSamples(output, numSamples);
if (ret) {
// Hit atrac3 voice end
playing = false;
on = false; // ??
envelope.End();
}
}
atrac3.getNextSamples(output, numSamples);
break;
default:
{
Expand All @@ -463,8 +461,7 @@ bool SasVoice::HaveSamplesEnded() const {
return pcmIndex >= pcmSize;

case VOICETYPE_ATRAC3:
// TODO: Is it here, or before the samples are processed?
return false;
return atrac3.End();

default:
return false;
Expand Down
16 changes: 10 additions & 6 deletions Core/HW/SasAudio.h
Expand Up @@ -128,17 +128,21 @@ class VagDecoder {

class SasAtrac3 {
public:
SasAtrac3() : contextAddr(0), atracID(-1), sampleQueue(0) {}
~SasAtrac3() { if (sampleQueue) delete sampleQueue; }
SasAtrac3() : contextAddr_(0), atracID_(-1), sampleQueue_(0), end_(false) {}
~SasAtrac3() { if (sampleQueue_) delete sampleQueue_; }
int setContext(u32 context);
int getNextSamples(s16* outbuf, int wantedSamples);
void getNextSamples(s16 *outbuf, int wantedSamples);
int addStreamData(u32 bufPtr, u32 addbytes);
void DoState(PointerWrap &p);
bool End() const {
return end_;
}

private:
u32 contextAddr;
int atracID;
BufferQueue *sampleQueue;
u32 contextAddr_;
int atracID_;
BufferQueue *sampleQueue_;
bool end_;
};

class ADSREnvelope {
Expand Down
2 changes: 1 addition & 1 deletion Core/HW/SasReverb.cpp
Expand Up @@ -127,7 +127,7 @@ static const SasReverbData presets[10] = {
{
"Echo (almost infinite)",
0x18040,
0x0001,0x0001,0x7FFF,0x7FFF,0x0000,0x0000,0x0000,(int16_t)0x8100,
0x0001,0x0001,0x7FFF,0x7FFF,0x0000,0x0000,0x0000,(int16_t)0xC080,
0x0000,0x0000,0x1FFF,0x0FFF,0x1005,0x0005,0x0000,0x0000,
0x1005,0x0005,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x1004,0x1002,0x0004,0x0002, //(int16_t)0x8000,(int16_t)0x8000,
Expand Down