mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
track_ removal, part 2 - done!
This commit is contained in:
1 parent
02f06faad1
commit
34c21ed271
4 files changed
+50
-36
No files matched your search
+14
-14
@@ -146,9 +146,9 @@ void Atrac::DoState(PointerWrap &p) {
|
||||
bufferState_ = ATRAC_STATUS_STREAMED_LOOP_FROM_END;
|
||||
}
|
||||
|
||||
// Make sure to do this late; it depends on things like bytesPerFrame_.
|
||||
// Make sure to do this late; it depends on track parameters.
|
||||
if (p.mode == p.MODE_READ && bufferState_ != ATRAC_STATUS_NO_DATA) {
|
||||
CreateDecoder();
|
||||
CreateDecoder(track_.codecType, track_.channels, track_.jointStereo, track_.bytesPerFrame);
|
||||
}
|
||||
|
||||
if (s >= 2 && s < 9) {
|
||||
@@ -585,24 +585,24 @@ void Atrac::CalculateStreamInfo(u32 *outReadOffset) {
|
||||
}
|
||||
}
|
||||
|
||||
void AtracBase::CreateDecoder() {
|
||||
void AtracBase::CreateDecoder(int codecType, int channels, int jointStereo, int bytesPerFrame) {
|
||||
if (decoder_) {
|
||||
delete decoder_;
|
||||
}
|
||||
|
||||
// First, init the standalone decoder.
|
||||
if (track_.codecType == PSP_MODE_AT_3) {
|
||||
if (codecType == PSP_MODE_AT_3) {
|
||||
// We don't pull this from the RIFF so that we can support OMA also.
|
||||
uint8_t extraData[14]{};
|
||||
// The only thing that changes are the jointStereo_ values.
|
||||
extraData[0] = 1;
|
||||
extraData[3] = track_.channels << 3;
|
||||
extraData[6] = track_.jointStereo;
|
||||
extraData[8] = track_.jointStereo;
|
||||
extraData[3] = channels << 3;
|
||||
extraData[6] = jointStereo;
|
||||
extraData[8] = jointStereo;
|
||||
extraData[10] = 1;
|
||||
decoder_ = CreateAtrac3Audio(track_.channels, track_.bytesPerFrame, extraData, sizeof(extraData));
|
||||
decoder_ = CreateAtrac3Audio(channels, bytesPerFrame, extraData, sizeof(extraData));
|
||||
} else {
|
||||
decoder_ = CreateAtrac3PlusAudio(track_.channels, track_.bytesPerFrame);
|
||||
decoder_ = CreateAtrac3PlusAudio(channels, bytesPerFrame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -745,7 +745,7 @@ int Atrac::SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize,
|
||||
u32 copybytes = std::min(bufferSize, track_.fileSize);
|
||||
Memory::Memcpy(dataBuf_, buffer, copybytes, "AtracSetData");
|
||||
}
|
||||
CreateDecoder();
|
||||
CreateDecoder(track.codecType, track.channels, track.jointStereo, track.bytesPerFrame);
|
||||
INFO_LOG(Log::ME, "Atrac::SetData (buffer=%08x, readSize=%d, bufferSize=%d): %s %s (%d channels) audio", buffer, readSize, bufferSize, codecName, channelName, track_.channels);
|
||||
|
||||
if (track_.channels == 2 && outputChannels == 1) {
|
||||
@@ -755,7 +755,7 @@ int Atrac::SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize,
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 Atrac::SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) {
|
||||
int Atrac::SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) {
|
||||
u32 secondFileOffset = track_.FileOffsetBySample(track_.loopEndSample - track_.firstSampleOffset);
|
||||
u32 desiredSize = track_.fileSize - secondFileOffset;
|
||||
|
||||
@@ -773,7 +773,7 @@ u32 Atrac::SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AtracBase::GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) {
|
||||
int Atrac::GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) {
|
||||
if (BufferState() != ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER) {
|
||||
// Writes zeroes in this error case.
|
||||
*fileOffset = 0;
|
||||
@@ -1055,7 +1055,7 @@ u32 Atrac::DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, i
|
||||
if (!gotFrame && currentSample_ < track_.endSample) {
|
||||
// Never got a frame. We may have dropped a GHA frame or otherwise have a bug.
|
||||
// For now, let's try to provide an extra "frame" if possible so games don't infinite loop.
|
||||
if (track_.FileOffsetBySample(currentSample_) < track_.fileSize) {
|
||||
if (track_.FileOffsetBySample(currentSample_) < (int)track_.fileSize) {
|
||||
numSamples = std::min(maxSamples, track_.SamplesPerFrame());
|
||||
u32 outBytes = numSamples * outputChannels_ * sizeof(s16);
|
||||
if (outbuf != nullptr) {
|
||||
@@ -1225,7 +1225,7 @@ void Atrac::InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) {
|
||||
track_.fileSize = track_.bytesPerFrame; // not really meaningful
|
||||
bufferState_ = ATRAC_STATUS_LOW_LEVEL;
|
||||
currentSample_ = 0;
|
||||
CreateDecoder();
|
||||
CreateDecoder(codecType, track_.channels, track_.jointStereo, track_.bytesPerFrame);
|
||||
WriteContextToPSPMem();
|
||||
}
|
||||
|
||||
|
||||
+12
-8
@@ -198,14 +198,13 @@ public:
|
||||
virtual int LoopNum() const = 0;
|
||||
virtual int LoopStatus() const = 0;
|
||||
|
||||
u32 CodecType() const {
|
||||
return track_.codecType;
|
||||
}
|
||||
virtual int CodecType() const = 0;
|
||||
|
||||
AudioDecoder *Decoder() const {
|
||||
return decoder_;
|
||||
}
|
||||
|
||||
void CreateDecoder();
|
||||
void CreateDecoder(int codecType, int channels, int jointStereo, int bytesPerFrame);
|
||||
|
||||
virtual void NotifyGetContextAddress() = 0;
|
||||
|
||||
@@ -223,8 +222,8 @@ public:
|
||||
virtual int GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) = 0;
|
||||
virtual int SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize, int outputChannels) = 0;
|
||||
|
||||
virtual int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize);
|
||||
virtual u32 SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) = 0;
|
||||
virtual int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) = 0;
|
||||
virtual int SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) = 0;
|
||||
virtual u32 DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, int *remains) = 0;
|
||||
virtual int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) = 0;
|
||||
virtual u32 GetNextSamples() = 0;
|
||||
@@ -235,7 +234,6 @@ public:
|
||||
virtual bool IsNewAtracImpl() const { return false; }
|
||||
|
||||
protected:
|
||||
Track track_{};
|
||||
u16 outputChannels_ = 2;
|
||||
|
||||
// TODO: Save the internal state of this, now technically possible.
|
||||
@@ -275,6 +273,9 @@ public:
|
||||
return atracID_;
|
||||
}
|
||||
|
||||
int CodecType() const override {
|
||||
return track_.codecType;
|
||||
}
|
||||
bool HasSecondBuffer() const override {
|
||||
return second_.size != 0;
|
||||
}
|
||||
@@ -316,7 +317,8 @@ public:
|
||||
int ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf, bool *delay) override;
|
||||
int GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) override;
|
||||
int SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize, int outputChannels) override;
|
||||
u32 SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) override;
|
||||
int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) override;
|
||||
int SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) override;
|
||||
u32 DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, int *remains) override;
|
||||
int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) override;
|
||||
// Returns how many samples the next DecodeData will write.
|
||||
@@ -343,6 +345,8 @@ private:
|
||||
void ConsumeFrame();
|
||||
void CalculateStreamInfo(u32 *readOffset);
|
||||
|
||||
Track track_{};
|
||||
|
||||
InputBuffer first_{};
|
||||
InputBuffer second_{}; // only addr, size, fileoffset are used (incomplete)
|
||||
|
||||
|
||||
+21
-13
@@ -163,7 +163,6 @@ int Atrac2::RemainingFrames() const {
|
||||
|
||||
Atrac2::Atrac2(int atracID, u32 contextAddr, int codecType) {
|
||||
context_ = PSPPointer<SceAtracContext>::Create(contextAddr);
|
||||
track_.codecType = codecType;
|
||||
SceAtracIdInfo &info = context_->info;
|
||||
info.codec = codecType;
|
||||
info.atracID = atracID;
|
||||
@@ -438,16 +437,14 @@ u32 Atrac2::GetNextSamples() {
|
||||
int Atrac2::GetNextDecodePosition(int *pos) const {
|
||||
const SceAtracIdInfo &info = context_->info;
|
||||
// Check if we reached the end.
|
||||
int firstSampleOffsetFull = track_.FirstSampleOffsetFull();
|
||||
const int currentSample = info.decodePos - info.firstValidSample;
|
||||
if (currentSample >= track_.endSample) {
|
||||
if (info.decodePos > info.endSample) {
|
||||
return SCE_ERROR_ATRAC_ALL_DATA_DECODED;
|
||||
}
|
||||
// Check if remaining data in the file is smaller than a frame.
|
||||
if (info.fileDataEnd - info.curFileOff < info.sampleSize) {
|
||||
return SCE_ERROR_ATRAC_ALL_DATA_DECODED;
|
||||
}
|
||||
*pos = currentSample;
|
||||
*pos = info.decodePos - info.firstValidSample;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -777,9 +774,7 @@ int Atrac2::SetData(const Track &track, u32 bufferAddr, u32 readSize, u32 buffer
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_ADDRESS;
|
||||
}
|
||||
|
||||
// TODO: Remove track_.
|
||||
track.DebugLog();
|
||||
track_ = track;
|
||||
|
||||
SceAtracIdInfo &info = context_->info;
|
||||
|
||||
@@ -793,7 +788,7 @@ int Atrac2::SetData(const Track &track, u32 bufferAddr, u32 readSize, u32 buffer
|
||||
INFO_LOG(Log::ME, "Atrac2::SetData: outputChannels %d doesn't match track_.channels %d, decoder will expand.", outputChannels, track.channels);
|
||||
}
|
||||
|
||||
CreateDecoder();
|
||||
CreateDecoder(track.codecType, track.channels, track.jointStereo, track.bytesPerFrame);
|
||||
|
||||
outputChannels_ = outputChannels;
|
||||
|
||||
@@ -919,7 +914,23 @@ u32 Atrac2::SkipFrames(int *skipCount) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 Atrac2::SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) {
|
||||
// Where to read from to fill the second buffer.
|
||||
int Atrac2::GetSecondBufferInfo(u32 *fileOffset, u32 *readSize) {
|
||||
const SceAtracIdInfo &info = context_->info;
|
||||
if (info.state != ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER) {
|
||||
// No second buffer needed in this state.
|
||||
*fileOffset = 0;
|
||||
*readSize = 0;
|
||||
return SCE_ERROR_ATRAC_SECOND_BUFFER_NOT_NEEDED;
|
||||
}
|
||||
|
||||
const int loopEndFileOffset = ComputeLoopEndFileOffset(info, info.loopEnd);
|
||||
*fileOffset = loopEndFileOffset;
|
||||
*readSize = info.fileDataEnd - loopEndFileOffset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Atrac2::SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) {
|
||||
SceAtracIdInfo &info = context_->info;
|
||||
|
||||
u32 loopEndFileOffset = ComputeLoopEndFileOffset(info, info.loopEnd);
|
||||
@@ -957,8 +968,6 @@ int Atrac2::Bitrate() const {
|
||||
}
|
||||
|
||||
void Atrac2::InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) {
|
||||
// TODO: We shouldn't need to look at track_ later, so we shouldn't need to init it here.
|
||||
// Not true yet.
|
||||
SceAtracIdInfo &info = context_->info;
|
||||
info.codec = codecType;
|
||||
info.numChan = Memory::ReadUnchecked_U32(paramsAddr);
|
||||
@@ -967,8 +976,7 @@ void Atrac2::InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) {
|
||||
info.dataOff = 0;
|
||||
info.decodePos = 0;
|
||||
info.state = ATRAC_STATUS_LOW_LEVEL;
|
||||
info.numChan = 2;
|
||||
CreateDecoder();
|
||||
CreateDecoder(codecType, info.numChan, jointStereo, info.sampleSize);
|
||||
}
|
||||
|
||||
int Atrac2::DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) {
|
||||
|
||||
@@ -29,14 +29,16 @@ public:
|
||||
int Channels() const override { return context_->info.numChan; }
|
||||
int BytesPerFrame() const override { return context_->info.sampleSize; }
|
||||
int SetLoopNum(int loopNum) override;
|
||||
int CodecType() const override { return context_->info.codec; }
|
||||
|
||||
void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) override;
|
||||
int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) override;
|
||||
int AddStreamData(u32 bytesToAdd) override;
|
||||
u32 AddStreamDataSas(u32 bufPtr, u32 bytesToAdd) override;
|
||||
int ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf, bool *delay) override;
|
||||
int GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) override;
|
||||
int SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize, int outputChannels) override;
|
||||
u32 SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) override;
|
||||
int SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) override;
|
||||
bool HasSecondBuffer() const override;
|
||||
|
||||
u32 DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, int *remains) override;
|
||||
|
||||
Reference in new issue
Block a user