mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-03 11:13:44 +01:00
Merge pull request #19064 from hrydgard/split-atrac-dec
Atrac: Split the context into a base class and a derived class, to be able to replace the buffering logic
This commit is contained in:
4 files changed
+248
-192
No files matched your search
@@ -71,6 +71,17 @@ void DoClass(PointerWrap &p, T *&x) {
|
||||
x->DoState(p);
|
||||
}
|
||||
|
||||
template<class T, class S>
|
||||
void DoSubClass(PointerWrap &p, T *&x) {
|
||||
if (p.mode == PointerWrap::MODE_READ) {
|
||||
if (x != nullptr)
|
||||
delete x;
|
||||
x = new S();
|
||||
}
|
||||
x->DoState(p);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void DoArray(PointerWrap &p, T *x, int count) {
|
||||
DoHelper_<T>::DoArray(p, x, count);
|
||||
|
||||
+45
-32
@@ -167,18 +167,15 @@ void Atrac::ResetData() {
|
||||
|
||||
void Atrac::AnalyzeReset() {
|
||||
// Reset some values.
|
||||
track_.AnalyzeReset();
|
||||
|
||||
currentSample_ = 0;
|
||||
track_.endSample = -1;
|
||||
loopNum_ = 0;
|
||||
track_.loopinfo.clear();
|
||||
track_.loopStartSample = -1;
|
||||
track_.loopEndSample = -1;
|
||||
decodePos_ = 0;
|
||||
bufferPos_ = 0;
|
||||
track_.channels = 2;
|
||||
}
|
||||
|
||||
void Atrac::UpdateContextFromPSPMem() {
|
||||
void AtracBase::UpdateContextFromPSPMem() {
|
||||
if (!context_.IsValid()) {
|
||||
return;
|
||||
}
|
||||
@@ -220,7 +217,7 @@ void Atrac::WriteContextToPSPMem() {
|
||||
context->info.endSample = track_.endSample + track_.firstSampleOffset + FirstOffsetExtra();
|
||||
context->info.dataEnd = track_.fileSize;
|
||||
context->info.curOff = first_.fileoffset;
|
||||
context->info.decodePos = DecodePosBySample(currentSample_);
|
||||
context->info.decodePos = track_.DecodePosBySample(currentSample_);
|
||||
context->info.streamDataByte = first_.size - track_.dataOff;
|
||||
|
||||
u8 *buf = (u8 *)context;
|
||||
@@ -540,7 +537,7 @@ void Atrac::CalculateStreamInfo(u32 *outReadOffset) {
|
||||
first_.offset = 0;
|
||||
first_.writableBytes = 0;
|
||||
} else {
|
||||
readOffset = FileOffsetBySample(track_.loopStartSample - FirstOffsetExtra() - track_.firstSampleOffset - track_.SamplesPerFrame() * 2);
|
||||
readOffset = track_.FileOffsetBySample(track_.loopStartSample - FirstOffsetExtra() - track_.firstSampleOffset - track_.SamplesPerFrame() * 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,7 +559,7 @@ void Atrac::CalculateStreamInfo(u32 *outReadOffset) {
|
||||
}
|
||||
}
|
||||
|
||||
void Atrac::CreateDecoder() {
|
||||
void AtracBase::CreateDecoder() {
|
||||
if (decoder_) {
|
||||
delete decoder_;
|
||||
}
|
||||
@@ -581,8 +578,6 @@ void Atrac::CreateDecoder() {
|
||||
} else {
|
||||
decoder_ = CreateAtrac3PlusAudio(track_.channels, track_.bytesPerFrame);
|
||||
}
|
||||
// reinit decodePos, because ffmpeg had changed it.
|
||||
decodePos_ = 0;
|
||||
}
|
||||
|
||||
void Atrac::GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample) {
|
||||
@@ -597,7 +592,7 @@ void Atrac::GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample) {
|
||||
// This is because we're filling the buffer start to finish, not streaming.
|
||||
bufferInfo->first.writePosPtr = first_.addr + first_.size;
|
||||
bufferInfo->first.writableBytes = track_.fileSize - first_.size;
|
||||
int minWriteBytes = FileOffsetBySample(sample) - first_.size;
|
||||
int minWriteBytes = track_.FileOffsetBySample(sample) - first_.size;
|
||||
if (minWriteBytes > 0) {
|
||||
bufferInfo->first.minWriteBytes = minWriteBytes;
|
||||
} else {
|
||||
@@ -606,7 +601,7 @@ void Atrac::GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample) {
|
||||
bufferInfo->first.filePos = first_.size;
|
||||
} else {
|
||||
// This is without the sample offset. The file offset also includes the previous batch of samples?
|
||||
int sampleFileOffset = FileOffsetBySample(sample - track_.firstSampleOffset - track_.SamplesPerFrame());
|
||||
int sampleFileOffset = track_.FileOffsetBySample(sample - track_.firstSampleOffset - track_.SamplesPerFrame());
|
||||
|
||||
// Update the writable bytes. When streaming, this is just the number of bytes until the end.
|
||||
const u32 bufSizeAligned = (bufferMaxSize_ / track_.bytesPerFrame) * track_.bytesPerFrame;
|
||||
@@ -693,7 +688,7 @@ int Atrac::SetData(u32 buffer, u32 readSize, u32 bufferSize, int outputChannels,
|
||||
}
|
||||
|
||||
u32 Atrac::SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) {
|
||||
u32 secondFileOffset = FileOffsetBySample(track_.loopEndSample - track_.firstSampleOffset);
|
||||
u32 secondFileOffset = track_.FileOffsetBySample(track_.loopEndSample - track_.firstSampleOffset);
|
||||
u32 desiredSize = track_.fileSize - secondFileOffset;
|
||||
|
||||
// 3 seems to be the number of frames required to handle a loop.
|
||||
@@ -718,17 +713,39 @@ int Atrac::GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) {
|
||||
return hleLogWarning(ME, ATRAC_ERROR_SECOND_BUFFER_NOT_NEEDED, "not needed");
|
||||
}
|
||||
|
||||
*fileOffset = FileOffsetBySample(track_.loopEndSample - track_.firstSampleOffset);
|
||||
*fileOffset = track_.FileOffsetBySample(track_.loopEndSample - track_.firstSampleOffset);
|
||||
*desiredSize = track_.fileSize - *fileOffset;
|
||||
return hleLogSuccessI(ME, 0);
|
||||
}
|
||||
|
||||
void Atrac::UpdateBitrate() {
|
||||
track_.bitrate = (track_.bytesPerFrame * 352800) / 1000;
|
||||
if (track_.codecType == PSP_MODE_AT_3_PLUS)
|
||||
track_.bitrate = ((track_.bitrate >> 11) + 8) & 0xFFFFFFF0;
|
||||
else
|
||||
track_.bitrate = (track_.bitrate + 511) >> 10;
|
||||
void Atrac::GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) {
|
||||
u32 calculatedReadOffset;
|
||||
// TODO: Feels like this should already have been computed?
|
||||
CalculateStreamInfo(&calculatedReadOffset);
|
||||
|
||||
*writePtr = first_.addr + first_.offset;
|
||||
*writableBytes = first_.writableBytes;
|
||||
*readOffset = calculatedReadOffset;
|
||||
}
|
||||
|
||||
void Atrac::UpdateBufferState() {
|
||||
if (bufferMaxSize_ >= track_.fileSize) {
|
||||
if (first_.size < track_.fileSize) {
|
||||
// The buffer is big enough, but we don't have all the data yet.
|
||||
bufferState_ = ATRAC_STATUS_HALFWAY_BUFFER;
|
||||
} else {
|
||||
bufferState_ = ATRAC_STATUS_ALL_DATA_LOADED;
|
||||
}
|
||||
} else {
|
||||
if (track_.loopEndSample <= 0) {
|
||||
// There's no looping, but we need to stream the data in our buffer.
|
||||
bufferState_ = ATRAC_STATUS_STREAMED_WITHOUT_LOOP;
|
||||
} else if (track_.loopEndSample == track_.endSample + track_.firstSampleOffset + (int)FirstOffsetExtra()) {
|
||||
bufferState_ = ATRAC_STATUS_STREAMED_LOOP_FROM_END;
|
||||
} else {
|
||||
bufferState_ = ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Atrac::AddStreamData(u32 bytesToAdd) {
|
||||
@@ -800,10 +817,6 @@ u32 Atrac::GetNextSamples() {
|
||||
return numSamples;
|
||||
}
|
||||
|
||||
u8 *Atrac::BufferStart() {
|
||||
return ignoreDataBuf_ ? Memory::GetPointerWrite(first_.addr) : dataBuf_;
|
||||
}
|
||||
|
||||
void Atrac::ForceSeekToSample(int sample) {
|
||||
if (decoder_) {
|
||||
decoder_->FlushBuffers();
|
||||
@@ -826,7 +839,7 @@ void Atrac::SeekToSample(int sample) {
|
||||
int offsetSamples = track_.firstSampleOffset + FirstOffsetExtra();
|
||||
adjust = -(int)(offsetSamples % track_.SamplesPerFrame());
|
||||
}
|
||||
const u32 off = FileOffsetBySample(sample + adjust);
|
||||
const u32 off = track_.FileOffsetBySample(sample + adjust);
|
||||
const u32 backfill = track_.bytesPerFrame * 2;
|
||||
const u32 start = off - track_.dataOff < backfill ? track_.dataOff : off - backfill;
|
||||
|
||||
@@ -844,7 +857,7 @@ int Atrac::RemainingFrames() const {
|
||||
return PSP_ATRAC_ALLDATA_IS_ON_MEMORY;
|
||||
}
|
||||
|
||||
u32 currentFileOffset = FileOffsetBySample(currentSample_ - track_.SamplesPerFrame() + FirstOffsetExtra());
|
||||
u32 currentFileOffset = track_.FileOffsetBySample(currentSample_ - track_.SamplesPerFrame() + FirstOffsetExtra());
|
||||
if (first_.fileoffset >= track_.fileSize) {
|
||||
if (bufferState_ == ATRAC_STATUS_STREAMED_WITHOUT_LOOP) {
|
||||
return PSP_ATRAC_NONLOOP_STREAM_DATA_IS_ON_MEMORY;
|
||||
@@ -928,7 +941,7 @@ u32 Atrac::DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, i
|
||||
SeekToSample(currentSample_);
|
||||
|
||||
bool gotFrame = false;
|
||||
u32 off = FileOffsetBySample(currentSample_ - skipSamples);
|
||||
u32 off = track_.FileOffsetBySample(currentSample_ - skipSamples);
|
||||
if (off < first_.size) {
|
||||
uint8_t *indata = BufferStart() + off;
|
||||
int bytesConsumed = 0;
|
||||
@@ -964,7 +977,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 (FileOffsetBySample(currentSample_) < track_.fileSize) {
|
||||
if (track_.FileOffsetBySample(currentSample_) < track_.fileSize) {
|
||||
numSamples = std::min(maxSamples, track_.SamplesPerFrame());
|
||||
u32 outBytes = numSamples * outputChannels_ * sizeof(s16);
|
||||
if (outbuf != nullptr) {
|
||||
@@ -977,7 +990,7 @@ u32 Atrac::DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, i
|
||||
*SamplesNum = numSamples;
|
||||
// update current sample and decodePos
|
||||
currentSample_ += numSamples;
|
||||
decodePos_ = DecodePosBySample(currentSample_);
|
||||
decodePos_ = track_.DecodePosBySample(currentSample_);
|
||||
|
||||
ConsumeFrame();
|
||||
|
||||
@@ -993,11 +1006,11 @@ u32 Atrac::DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, i
|
||||
}
|
||||
if ((bufferState_ & ATRAC_STATUS_STREAMED_MASK) == ATRAC_STATUS_STREAMED_MASK) {
|
||||
// Whatever bytes we have left were added from the loop.
|
||||
u32 loopOffset = FileOffsetBySample(track_.loopStartSample - FirstOffsetExtra() - track_.firstSampleOffset - track_.SamplesPerFrame() * 2);
|
||||
u32 loopOffset = track_.FileOffsetBySample(track_.loopStartSample - FirstOffsetExtra() - track_.firstSampleOffset - track_.SamplesPerFrame() * 2);
|
||||
// TODO: Hmm, need to manage the buffer better. But don't move fileoffset if we already have valid data.
|
||||
if (loopOffset > first_.fileoffset || loopOffset + bufferValidBytes_ < first_.fileoffset) {
|
||||
// Skip the initial frame at the start.
|
||||
first_.fileoffset = FileOffsetBySample(track_.loopStartSample - FirstOffsetExtra() - track_.firstSampleOffset - track_.SamplesPerFrame() * 2);
|
||||
first_.fileoffset = track_.FileOffsetBySample(track_.loopStartSample - FirstOffsetExtra() - track_.firstSampleOffset - track_.SamplesPerFrame() * 2);
|
||||
}
|
||||
}
|
||||
} else if (hitEnd) {
|
||||
|
||||
+132
-101
@@ -132,86 +132,57 @@ struct Track {
|
||||
u32 SamplesPerFrame() const {
|
||||
return codecType == PSP_MODE_AT_3_PLUS ? ATRAC3PLUS_MAX_SAMPLES : ATRAC3_MAX_SAMPLES;
|
||||
}
|
||||
|
||||
void UpdateBitrate() {
|
||||
bitrate = (bytesPerFrame * 352800) / 1000;
|
||||
if (codecType == PSP_MODE_AT_3_PLUS)
|
||||
bitrate = ((bitrate >> 11) + 8) & 0xFFFFFFF0;
|
||||
else
|
||||
bitrate = (bitrate + 511) >> 10;
|
||||
}
|
||||
|
||||
u32 DecodePosBySample(int sample) const {
|
||||
return (u32)(firstSampleOffset + sample / (int)SamplesPerFrame() * bytesPerFrame);
|
||||
}
|
||||
|
||||
u32 FileOffsetBySample(int sample) const {
|
||||
int offsetSample = sample + firstSampleOffset;
|
||||
int frameOffset = offsetSample / (int)SamplesPerFrame();
|
||||
return (u32)(dataOff + bytesPerFrame + frameOffset * bytesPerFrame);
|
||||
}
|
||||
|
||||
void AnalyzeReset() {
|
||||
endSample = -1;
|
||||
loopinfo.clear();
|
||||
loopStartSample = -1;
|
||||
loopEndSample = -1;
|
||||
channels = 2;
|
||||
// TODO: Could probably reset more.
|
||||
}
|
||||
};
|
||||
|
||||
int AnalyzeAA3Track(u32 addr, u32 size, u32 filesize, Track *track);
|
||||
int AnalyzeAtracTrack(u32 addr, u32 size, Track *track);
|
||||
|
||||
struct Atrac {
|
||||
~Atrac() {
|
||||
ResetData();
|
||||
}
|
||||
class AtracBase {
|
||||
public:
|
||||
virtual ~AtracBase() {}
|
||||
|
||||
void ResetData();
|
||||
void UpdateBufferState() {
|
||||
if (bufferMaxSize_ >= track_.fileSize) {
|
||||
if (first_.size < track_.fileSize) {
|
||||
// The buffer is big enough, but we don't have all the data yet.
|
||||
bufferState_ = ATRAC_STATUS_HALFWAY_BUFFER;
|
||||
} else {
|
||||
bufferState_ = ATRAC_STATUS_ALL_DATA_LOADED;
|
||||
}
|
||||
} else {
|
||||
if (track_.loopEndSample <= 0) {
|
||||
// There's no looping, but we need to stream the data in our buffer.
|
||||
bufferState_ = ATRAC_STATUS_STREAMED_WITHOUT_LOOP;
|
||||
} else if (track_.loopEndSample == track_.endSample + track_.firstSampleOffset + (int)FirstOffsetExtra()) {
|
||||
bufferState_ = ATRAC_STATUS_STREAMED_LOOP_FROM_END;
|
||||
} else {
|
||||
bufferState_ = ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
|
||||
u32 SamplesPerFrame() const {
|
||||
return track_.SamplesPerFrame();
|
||||
}
|
||||
|
||||
u32 DecodePosBySample(int sample) const {
|
||||
return (u32)(track_.firstSampleOffset + sample / (int)track_.SamplesPerFrame() * track_.bytesPerFrame);
|
||||
}
|
||||
|
||||
u32 FileOffsetBySample(int sample) const {
|
||||
int offsetSample = sample + track_.firstSampleOffset;
|
||||
int frameOffset = offsetSample / (int)track_.SamplesPerFrame();
|
||||
return (u32)(track_.dataOff + track_.bytesPerFrame + frameOffset * track_.bytesPerFrame);
|
||||
}
|
||||
virtual void DoState(PointerWrap &p) = 0;
|
||||
|
||||
const Track &GetTrack() const {
|
||||
return track_;
|
||||
}
|
||||
|
||||
void UpdateBitrate();
|
||||
|
||||
int Bitrate() const {
|
||||
return track_.bitrate;
|
||||
}
|
||||
int Channels() const {
|
||||
return track_.channels;
|
||||
// This should be rare.
|
||||
Track &GetTrackMut() {
|
||||
return track_;
|
||||
}
|
||||
|
||||
int RemainingFrames() const;
|
||||
int GetOutputChannels() const {
|
||||
return outputChannels_;
|
||||
}
|
||||
|
||||
u8 *dataBuf_ = nullptr;
|
||||
// Indicates that the dataBuf_ array should not be used.
|
||||
bool ignoreDataBuf_ = false;
|
||||
u32 decodePos_ = 0;
|
||||
|
||||
int atracID_ = -1;
|
||||
u16 outputChannels_ = 2;
|
||||
|
||||
int currentSample_ = 0;
|
||||
int loopNum_ = 0;
|
||||
|
||||
InputBuffer first_{};
|
||||
InputBuffer second_{};
|
||||
|
||||
Track track_{};
|
||||
|
||||
PSPPointer<SceAtracContext> context_{};
|
||||
|
||||
@@ -219,20 +190,65 @@ struct Atrac {
|
||||
return bufferState_;
|
||||
}
|
||||
|
||||
void ForceSeekToSample(int sample);
|
||||
u8 *BufferStart();
|
||||
|
||||
void SeekToSample(int sample);
|
||||
|
||||
int LoopNum() const {
|
||||
return loopNum_;
|
||||
}
|
||||
u32 CodecType() const {
|
||||
return track_.codecType;
|
||||
}
|
||||
AudioDecoder *GetDecoder() const {
|
||||
AudioDecoder *Decoder() const {
|
||||
return decoder_;
|
||||
}
|
||||
u32 FirstOffsetExtra() const {
|
||||
return ::FirstOffsetExtra(track_.codecType);
|
||||
}
|
||||
|
||||
uint32_t CurBufferAddress(int adjust = 0) {
|
||||
u32 off = FileOffsetBySample(currentSample_ + adjust);
|
||||
void CreateDecoder();
|
||||
|
||||
virtual uint32_t CurBufferAddress(int adjust = 0) const = 0;
|
||||
virtual int CurrentSample() const = 0;
|
||||
virtual int RemainingFrames() const = 0;
|
||||
virtual u32 SecondBufferSize() const = 0;
|
||||
|
||||
virtual int Analyze(u32 addr, u32 size) = 0;
|
||||
virtual int AnalyzeAA3(u32 addr, u32 size, u32 filesize) = 0;
|
||||
|
||||
void UpdateContextFromPSPMem();
|
||||
virtual void WriteContextToPSPMem() = 0;
|
||||
|
||||
virtual void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) = 0;
|
||||
virtual int AddStreamData(u32 bytesToAdd) = 0;
|
||||
virtual u32 AddStreamDataSas(u32 bufPtr, u32 bytesToAdd) = 0;
|
||||
virtual void SetLoopNum(int loopNum) = 0;
|
||||
virtual u32 ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf) = 0;
|
||||
virtual void GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample) = 0;
|
||||
virtual int SetData(u32 buffer, u32 readSize, u32 bufferSize, int outputChannels, int successCode) = 0;
|
||||
virtual u32 SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) = 0;
|
||||
virtual int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) = 0;
|
||||
virtual u32 DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, int *remains) = 0;
|
||||
virtual u32 GetNextSamples() = 0;
|
||||
virtual void InitLowLevel(u32 paramsAddr, bool jointStereo) = 0;
|
||||
|
||||
protected:
|
||||
virtual void AnalyzeReset() = 0;
|
||||
|
||||
Track track_{};
|
||||
u16 outputChannels_ = 2;
|
||||
int loopNum_ = 0;
|
||||
|
||||
// TODO: Save the internal state of this, now technically possible.
|
||||
AudioDecoder *decoder_ = nullptr;
|
||||
AtracStatus bufferState_ = ATRAC_STATUS_NO_DATA;
|
||||
};
|
||||
|
||||
class Atrac : public AtracBase {
|
||||
public:
|
||||
~Atrac() {
|
||||
ResetData();
|
||||
}
|
||||
|
||||
uint32_t CurBufferAddress(int adjust = 0) const override {
|
||||
u32 off = track_.FileOffsetBySample(currentSample_ + adjust);
|
||||
if (off < first_.size && ignoreDataBuf_) {
|
||||
return first_.addr + off;
|
||||
}
|
||||
@@ -240,52 +256,67 @@ struct Atrac {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CalculateStreamInfo(u32 *readOffset);
|
||||
|
||||
u32 FirstOffsetExtra() const {
|
||||
return ::FirstOffsetExtra(track_.codecType);
|
||||
u8 *BufferStart() {
|
||||
return ignoreDataBuf_ ? Memory::GetPointerWrite(first_.addr) : dataBuf_;
|
||||
}
|
||||
|
||||
void DoState(PointerWrap &p) override;
|
||||
void WriteContextToPSPMem() override;
|
||||
|
||||
int Analyze(u32 addr, u32 size) override;
|
||||
int AnalyzeAA3(u32 addr, u32 size, u32 filesize) override;
|
||||
|
||||
int CurrentSample() const override {
|
||||
return currentSample_;
|
||||
}
|
||||
int RemainingFrames() const override;
|
||||
u32 SecondBufferSize() const override {
|
||||
return second_.size;
|
||||
}
|
||||
|
||||
void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) override;
|
||||
int AddStreamData(u32 bytesToAdd) override;
|
||||
u32 AddStreamDataSas(u32 bufPtr, u32 bytesToAdd) override;
|
||||
void SetLoopNum(int loopNum) override;
|
||||
u32 ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf) override;
|
||||
void GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample) override;
|
||||
int SetData(u32 buffer, u32 readSize, u32 bufferSize, int outputChannels, int successCode) override;
|
||||
u32 SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) override;
|
||||
int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) override;
|
||||
u32 DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, int *remains) override;
|
||||
u32 GetNextSamples() override;
|
||||
void InitLowLevel(u32 paramsAddr, bool jointStereo);
|
||||
|
||||
protected:
|
||||
void AnalyzeReset();
|
||||
|
||||
private:
|
||||
void UpdateBufferState();
|
||||
void ResetData();
|
||||
void SeekToSample(int sample);
|
||||
void ForceSeekToSample(int sample);
|
||||
u32 StreamBufferEnd() const {
|
||||
// The buffer is always aligned to a frame in size, not counting an optional header.
|
||||
// The header will only initially exist after the data is first set.
|
||||
u32 framesAfterHeader = (bufferMaxSize_ - bufferHeaderSize_) / track_.bytesPerFrame;
|
||||
return framesAfterHeader * track_.bytesPerFrame + bufferHeaderSize_;
|
||||
}
|
||||
|
||||
int Analyze(u32 addr, u32 size);
|
||||
int AnalyzeAA3(u32 addr, u32 size, u32 filesize);
|
||||
|
||||
void UpdateContextFromPSPMem();
|
||||
void WriteContextToPSPMem();
|
||||
|
||||
int AddStreamData(u32 bytesToAdd);
|
||||
u32 AddStreamDataSas(u32 bufPtr, u32 bytesToAdd);
|
||||
void CreateDecoder();
|
||||
void SetLoopNum(int loopNum);
|
||||
u32 ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf);
|
||||
void GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample);
|
||||
int SetData(u32 buffer, u32 readSize, u32 bufferSize, int outputChannels, int successCode);
|
||||
u32 SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize);
|
||||
int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize);
|
||||
u32 DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, int *remains);
|
||||
void ConsumeFrame();
|
||||
u32 GetNextSamples();
|
||||
void CalculateStreamInfo(u32 *readOffset);
|
||||
|
||||
void InitLowLevel(u32 paramsAddr, bool jointStereo);
|
||||
InputBuffer first_{};
|
||||
InputBuffer second_{};
|
||||
|
||||
private:
|
||||
void AnalyzeReset();
|
||||
u8 *dataBuf_ = nullptr;
|
||||
// Indicates that the dataBuf_ array should not be used.
|
||||
bool ignoreDataBuf_ = false;
|
||||
|
||||
int currentSample_ = 0;
|
||||
u32 decodePos_ = 0;
|
||||
u32 bufferMaxSize_ = 0;
|
||||
|
||||
// Used to track streaming.
|
||||
u32 bufferPos_ = 0;
|
||||
u32 bufferValidBytes_ = 0;
|
||||
u32 bufferHeaderSize_ = 0;
|
||||
|
||||
// TODO: Save the internal state of this, now technically possible.
|
||||
AudioDecoder *decoder_ = nullptr;
|
||||
|
||||
AtracStatus bufferState_ = ATRAC_STATUS_NO_DATA;
|
||||
};
|
||||
+60
-59
@@ -76,7 +76,7 @@ static const int atracDecodeDelay = 2300;
|
||||
|
||||
const int PSP_NUM_ATRAC_IDS = 6;
|
||||
static bool atracInited = true;
|
||||
static Atrac *atracContexts[PSP_NUM_ATRAC_IDS];
|
||||
static AtracBase *atracContexts[PSP_NUM_ATRAC_IDS];
|
||||
static u32 atracContextTypes[PSP_NUM_ATRAC_IDS];
|
||||
static int atracLibVersion = 0;
|
||||
static u32 atracLibCrc = 0;
|
||||
@@ -119,7 +119,7 @@ void __AtracDoState(PointerWrap &p) {
|
||||
bool valid = atracContexts[i] != nullptr;
|
||||
Do(p, valid);
|
||||
if (valid) {
|
||||
Do(p, atracContexts[i]);
|
||||
DoSubClass<AtracBase, Atrac>(p, atracContexts[i]);
|
||||
} else {
|
||||
delete atracContexts[i];
|
||||
atracContexts[i] = nullptr;
|
||||
@@ -136,18 +136,18 @@ void __AtracDoState(PointerWrap &p) {
|
||||
}
|
||||
}
|
||||
|
||||
static Atrac *getAtrac(int atracID) {
|
||||
static AtracBase *getAtrac(int atracID) {
|
||||
if (atracID < 0 || atracID >= PSP_NUM_ATRAC_IDS) {
|
||||
return nullptr;
|
||||
}
|
||||
Atrac *atrac = atracContexts[atracID];
|
||||
AtracBase *atrac = atracContexts[atracID];
|
||||
if (atrac) {
|
||||
atrac->UpdateContextFromPSPMem();
|
||||
}
|
||||
return atrac;
|
||||
}
|
||||
|
||||
static int createAtrac(Atrac *atrac) {
|
||||
static int createAtrac(AtracBase *atrac) {
|
||||
for (int i = 0; i < (int)ARRAY_SIZE(atracContexts); ++i) {
|
||||
if (atracContextTypes[i] == atrac->CodecType() && atracContexts[i] == 0) {
|
||||
atracContexts[i] = atrac;
|
||||
@@ -175,8 +175,8 @@ static u32 sceAtracGetAtracID(int codecType) {
|
||||
return hleReportError(ME, ATRAC_ERROR_INVALID_CODECTYPE, "invalid codecType");
|
||||
}
|
||||
|
||||
Atrac *atrac = new Atrac();
|
||||
atrac->track_.codecType = codecType;
|
||||
AtracBase *atrac = new Atrac();
|
||||
atrac->GetTrackMut().codecType = codecType;
|
||||
int atracID = createAtrac(atrac);
|
||||
if (atracID < 0) {
|
||||
delete atrac;
|
||||
@@ -186,7 +186,7 @@ static u32 sceAtracGetAtracID(int codecType) {
|
||||
return hleLogSuccessInfoI(ME, atracID);
|
||||
}
|
||||
|
||||
static u32 AtracValidateData(const Atrac *atrac) {
|
||||
static u32 AtracValidateData(const AtracBase *atrac) {
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "bad atrac ID");
|
||||
} else if (atrac->BufferState() == ATRAC_STATUS_NO_DATA) {
|
||||
@@ -196,7 +196,7 @@ static u32 AtracValidateData(const Atrac *atrac) {
|
||||
}
|
||||
}
|
||||
|
||||
static u32 AtracValidateManaged(const Atrac *atrac) {
|
||||
static u32 AtracValidateManaged(const AtracBase *atrac) {
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "bad atrac ID");
|
||||
} else if (atrac->BufferState() == ATRAC_STATUS_NO_DATA) {
|
||||
@@ -215,7 +215,7 @@ static u32 AtracValidateManaged(const Atrac *atrac) {
|
||||
//
|
||||
// The total size of the buffer is atrac->bufferMaxSize_.
|
||||
static u32 sceAtracAddStreamData(int atracID, u32 bytesToAdd) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -238,7 +238,7 @@ static u32 sceAtracAddStreamData(int atracID, u32 bytesToAdd) {
|
||||
|
||||
// Note that outAddr being null is completely valid here, used to skip data.
|
||||
static u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishFlagAddr, u32 remainAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -279,7 +279,7 @@ static u32 sceAtracEndEntry() {
|
||||
static u32 sceAtracGetBufferInfoForResetting(int atracID, int sample, u32 bufferInfoAddr) {
|
||||
auto bufferInfo = PSPPointer<AtracResetBufferInfo>::Create(bufferInfoAddr);
|
||||
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -288,7 +288,7 @@ static u32 sceAtracGetBufferInfoForResetting(int atracID, int sample, u32 buffer
|
||||
|
||||
if (!bufferInfo.IsValid()) {
|
||||
return hleReportError(ME, SCE_KERNEL_ERROR_ILLEGAL_ADDR, "invalid buffer, should crash");
|
||||
} else if (atrac->BufferState() == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER && atrac->second_.size == 0) {
|
||||
} else if (atrac->BufferState() == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER && atrac->SecondBufferSize() == 0) {
|
||||
return hleReportError(ME, ATRAC_ERROR_SECOND_BUFFER_NEEDED, "no second buffer");
|
||||
} else if ((u32)sample + atrac->GetTrack().firstSampleOffset > (u32)atrac->GetTrack().endSample + atrac->GetTrack().firstSampleOffset) {
|
||||
// NOTE: Above we have to add firstSampleOffset to both sides - we seem to rely on wraparound.
|
||||
@@ -300,17 +300,17 @@ static u32 sceAtracGetBufferInfoForResetting(int atracID, int sample, u32 buffer
|
||||
}
|
||||
|
||||
static u32 sceAtracGetBitrate(int atracID, u32 outBitrateAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
return err;
|
||||
}
|
||||
|
||||
atrac->UpdateBitrate();
|
||||
atrac->GetTrackMut().UpdateBitrate();
|
||||
|
||||
if (Memory::IsValidAddress(outBitrateAddr)) {
|
||||
Memory::WriteUnchecked_U32(atrac->Bitrate(), outBitrateAddr);
|
||||
Memory::WriteUnchecked_U32(atrac->GetTrack().bitrate, outBitrateAddr);
|
||||
return hleLogSuccessI(ME, 0);
|
||||
} else {
|
||||
return hleLogError(ME, 0, "invalid address");
|
||||
@@ -318,7 +318,7 @@ static u32 sceAtracGetBitrate(int atracID, u32 outBitrateAddr) {
|
||||
}
|
||||
|
||||
static u32 sceAtracGetChannel(int atracID, u32 channelAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -326,7 +326,7 @@ static u32 sceAtracGetChannel(int atracID, u32 channelAddr) {
|
||||
}
|
||||
|
||||
if (Memory::IsValidAddress(channelAddr)){
|
||||
Memory::WriteUnchecked_U32(atrac->Channels(), channelAddr);
|
||||
Memory::WriteUnchecked_U32(atrac->GetTrack().channels, channelAddr);
|
||||
return hleLogSuccessI(ME, 0);
|
||||
} else {
|
||||
return hleLogError(ME, 0, "invalid address");
|
||||
@@ -334,7 +334,7 @@ static u32 sceAtracGetChannel(int atracID, u32 channelAddr) {
|
||||
}
|
||||
|
||||
static u32 sceAtracGetLoopStatus(int atracID, u32 loopNumAddr, u32 statusAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -342,7 +342,7 @@ static u32 sceAtracGetLoopStatus(int atracID, u32 loopNumAddr, u32 statusAddr) {
|
||||
}
|
||||
|
||||
if (Memory::IsValidAddress(loopNumAddr))
|
||||
Memory::WriteUnchecked_U32(atrac->loopNum_, loopNumAddr);
|
||||
Memory::WriteUnchecked_U32(atrac->LoopNum(), loopNumAddr);
|
||||
// return audio's loopinfo in at3 file
|
||||
if (Memory::IsValidAddress(statusAddr)) {
|
||||
if (atrac->GetTrack().loopinfo.size() > 0)
|
||||
@@ -356,7 +356,7 @@ static u32 sceAtracGetLoopStatus(int atracID, u32 loopNumAddr, u32 statusAddr) {
|
||||
}
|
||||
|
||||
static u32 sceAtracGetInternalErrorInfo(int atracID, u32 errorAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -369,7 +369,7 @@ static u32 sceAtracGetInternalErrorInfo(int atracID, u32 errorAddr) {
|
||||
}
|
||||
|
||||
static u32 sceAtracGetMaxSample(int atracID, u32 maxSamplesAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -377,7 +377,7 @@ static u32 sceAtracGetMaxSample(int atracID, u32 maxSamplesAddr) {
|
||||
}
|
||||
|
||||
if (Memory::IsValidAddress(maxSamplesAddr)) {
|
||||
Memory::WriteUnchecked_U32(atrac->SamplesPerFrame(), maxSamplesAddr);
|
||||
Memory::WriteUnchecked_U32(atrac->GetTrack().SamplesPerFrame(), maxSamplesAddr);
|
||||
return hleLogSuccessI(ME, 0);
|
||||
} else {
|
||||
return hleLogError(ME, 0, "invalid address");
|
||||
@@ -385,7 +385,7 @@ static u32 sceAtracGetMaxSample(int atracID, u32 maxSamplesAddr) {
|
||||
}
|
||||
|
||||
static u32 sceAtracGetNextDecodePosition(int atracID, u32 outposAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -393,11 +393,11 @@ static u32 sceAtracGetNextDecodePosition(int atracID, u32 outposAddr) {
|
||||
}
|
||||
|
||||
if (Memory::IsValidAddress(outposAddr)) {
|
||||
if (atrac->currentSample_ >= atrac->GetTrack().endSample) {
|
||||
if (atrac->CurrentSample() >= atrac->GetTrack().endSample) {
|
||||
Memory::WriteUnchecked_U32(0, outposAddr);
|
||||
return hleLogSuccessI(ME, ATRAC_ERROR_ALL_DATA_DECODED, "all data decoded");
|
||||
} else {
|
||||
Memory::WriteUnchecked_U32(atrac->currentSample_, outposAddr);
|
||||
Memory::WriteUnchecked_U32(atrac->CurrentSample(), outposAddr);
|
||||
return hleLogSuccessI(ME, 0);
|
||||
}
|
||||
} else {
|
||||
@@ -406,13 +406,13 @@ static u32 sceAtracGetNextDecodePosition(int atracID, u32 outposAddr) {
|
||||
}
|
||||
|
||||
static u32 sceAtracGetNextSample(int atracID, u32 outNAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
return err;
|
||||
}
|
||||
if (atrac->currentSample_ >= atrac->GetTrack().endSample) {
|
||||
if (atrac->CurrentSample() >= atrac->GetTrack().endSample) {
|
||||
if (Memory::IsValidAddress(outNAddr))
|
||||
Memory::WriteUnchecked_U32(0, outNAddr);
|
||||
return hleLogSuccessI(ME, 0, "0 samples left");
|
||||
@@ -430,7 +430,7 @@ static u32 sceAtracGetNextSample(int atracID, u32 outNAddr) {
|
||||
static u32 sceAtracGetRemainFrame(int atracID, u32 remainAddr) {
|
||||
auto remainingFrames = PSPPointer<u32_le>::Create(remainAddr);
|
||||
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -450,7 +450,7 @@ static u32 sceAtracGetSecondBufferInfo(int atracID, u32 fileOffsetAddr, u32 desi
|
||||
auto fileOffset = PSPPointer<u32_le>::Create(fileOffsetAddr);
|
||||
auto desiredSize = PSPPointer<u32_le>::Create(desiredSizeAddr);
|
||||
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -466,7 +466,7 @@ static u32 sceAtracGetSecondBufferInfo(int atracID, u32 fileOffsetAddr, u32 desi
|
||||
}
|
||||
|
||||
static u32 sceAtracGetSoundSample(int atracID, u32 outEndSampleAddr, u32 outLoopStartSampleAddr, u32 outLoopEndSampleAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -493,20 +493,22 @@ static u32 sceAtracGetSoundSample(int atracID, u32 outEndSampleAddr, u32 outLoop
|
||||
// such as where the data read from, where the data add to,
|
||||
// and how many bytes are allowed to add.
|
||||
static u32 sceAtracGetStreamDataInfo(int atracID, u32 writePtrAddr, u32 writableBytesAddr, u32 readOffsetAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
return err;
|
||||
}
|
||||
|
||||
u32 writePtr;
|
||||
u32 writableBytes;
|
||||
u32 readOffset;
|
||||
atrac->CalculateStreamInfo(&readOffset);
|
||||
atrac->GetStreamDataInfo(&writePtr, &writableBytes, &readOffset);
|
||||
|
||||
if (Memory::IsValidAddress(writePtrAddr))
|
||||
Memory::WriteUnchecked_U32(atrac->first_.addr + atrac->first_.offset, writePtrAddr);
|
||||
Memory::WriteUnchecked_U32(writePtr, writePtrAddr);
|
||||
if (Memory::IsValidAddress(writableBytesAddr))
|
||||
Memory::WriteUnchecked_U32(atrac->first_.writableBytes, writableBytesAddr);
|
||||
Memory::WriteUnchecked_U32(writableBytes, writableBytesAddr);
|
||||
if (Memory::IsValidAddress(readOffsetAddr))
|
||||
Memory::WriteUnchecked_U32(readOffset, readOffsetAddr);
|
||||
|
||||
@@ -525,14 +527,14 @@ static u32 sceAtracReleaseAtracID(int atracID) {
|
||||
// Normally, sceAtracGetBufferInfoForResetting() is called to determine how to buffer.
|
||||
// The game must add sufficient packets to the buffer in order to complete the seek.
|
||||
static u32 sceAtracResetPlayPosition(int atracID, int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
return err;
|
||||
}
|
||||
|
||||
if (atrac->BufferState() == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER && atrac->second_.size == 0) {
|
||||
if (atrac->BufferState() == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER && atrac->SecondBufferSize() == 0) {
|
||||
return hleReportError(ME, ATRAC_ERROR_SECOND_BUFFER_NEEDED, "no second buffer");
|
||||
} else if ((u32)sample + atrac->GetTrack().firstSampleOffset > (u32)atrac->GetTrack().endSample + atrac->GetTrack().firstSampleOffset) {
|
||||
// NOTE: Above we have to add firstSampleOffset to both sides - we seem to rely on wraparound.
|
||||
@@ -549,7 +551,7 @@ static u32 sceAtracResetPlayPosition(int atracID, int sample, int bytesWrittenFi
|
||||
}
|
||||
|
||||
static int _AtracSetData(int atracID, u32 buffer, u32 readSize, u32 bufferSize, int outputChannels, bool needReturnAtracID) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
// Don't use AtracValidateManaged here.
|
||||
if (!atrac)
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "invalid atrac ID");
|
||||
@@ -559,7 +561,7 @@ static int _AtracSetData(int atracID, u32 buffer, u32 readSize, u32 bufferSize,
|
||||
}
|
||||
|
||||
static u32 sceAtracSetHalfwayBuffer(int atracID, u32 buffer, u32 readSize, u32 bufferSize) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
// Don't use AtracValidateManaged here.
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "invalid atrac ID");
|
||||
@@ -579,7 +581,7 @@ static u32 sceAtracSetHalfwayBuffer(int atracID, u32 buffer, u32 readSize, u32 b
|
||||
}
|
||||
|
||||
static u32 sceAtracSetSecondBuffer(int atracID, u32 secondBuffer, u32 secondBufferSize) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -590,7 +592,7 @@ static u32 sceAtracSetSecondBuffer(int atracID, u32 secondBuffer, u32 secondBuff
|
||||
}
|
||||
|
||||
static u32 sceAtracSetData(int atracID, u32 buffer, u32 bufferSize) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "bad atrac ID");
|
||||
}
|
||||
@@ -601,7 +603,7 @@ static u32 sceAtracSetData(int atracID, u32 buffer, u32 bufferSize) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (atrac->track_.codecType != atracContextTypes[atracID]) {
|
||||
if (atrac->GetTrack().codecType != atracContextTypes[atracID]) {
|
||||
// TODO: Should this not change the buffer size?
|
||||
return hleReportError(ME, ATRAC_ERROR_WRONG_CODECTYPE, "atracID uses different codec type than data");
|
||||
}
|
||||
@@ -658,7 +660,7 @@ static u32 sceAtracStartEntry() {
|
||||
}
|
||||
|
||||
static u32 sceAtracSetLoopNum(int atracID, int loopNum) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -718,7 +720,7 @@ static int sceAtracReinit(int at3Count, int at3plusCount) {
|
||||
}
|
||||
|
||||
static int sceAtracGetOutputChannel(int atracID, u32 outputChanPtr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateData(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -733,7 +735,7 @@ static int sceAtracGetOutputChannel(int atracID, u32 outputChanPtr) {
|
||||
}
|
||||
|
||||
static int sceAtracIsSecondBufferNeeded(int atracID) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
u32 err = AtracValidateManaged(atrac);
|
||||
if (err != 0) {
|
||||
// Already logged.
|
||||
@@ -746,7 +748,7 @@ static int sceAtracIsSecondBufferNeeded(int atracID) {
|
||||
}
|
||||
|
||||
static int sceAtracSetMOutHalfwayBuffer(int atracID, u32 buffer, u32 readSize, u32 bufferSize) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
// Don't use AtracValidate* here.
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "bad atrac ID");
|
||||
@@ -771,7 +773,7 @@ static int sceAtracSetMOutHalfwayBuffer(int atracID, u32 buffer, u32 readSize, u
|
||||
|
||||
// Note: This doesn't seem to be part of any available libatrac3plus library.
|
||||
static u32 sceAtracSetMOutData(int atracID, u32 buffer, u32 bufferSize) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
// Don't use AtracValidate* here.
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "bad atrac ID");
|
||||
@@ -787,7 +789,6 @@ static u32 sceAtracSetMOutData(int atracID, u32 buffer, u32 bufferSize) {
|
||||
atrac->SetData(buffer, bufferSize, bufferSize, 2, 0);
|
||||
return hleReportError(ME, ATRAC_ERROR_NOT_MONO, "not mono data");
|
||||
} else {
|
||||
atrac->outputChannels_ = 1;
|
||||
return _AtracSetData(atracID, buffer, bufferSize, bufferSize, 1, false);
|
||||
}
|
||||
}
|
||||
@@ -856,7 +857,7 @@ static int sceAtracSetAA3DataAndGetID(u32 buffer, u32 bufferSize, u32 fileSize,
|
||||
}
|
||||
|
||||
static u32 _sceAtracGetContextAddress(int atracID) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
if (!atrac) {
|
||||
ERROR_LOG(ME, "_sceAtracGetContextAddress(%i): bad atrac id", atracID);
|
||||
return 0;
|
||||
@@ -881,8 +882,8 @@ struct At3HeaderMap {
|
||||
u16 channels;
|
||||
u8 jointStereo;
|
||||
|
||||
bool Matches(const Atrac *at) const {
|
||||
return bytes == at->GetTrack().BytesPerFrame() && channels == at->Channels();
|
||||
bool Matches(const AtracBase *at) const {
|
||||
return bytes == at->GetTrack().BytesPerFrame() && channels == at->GetTrack().channels;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -897,7 +898,7 @@ static const At3HeaderMap at3HeaderMap[] = {
|
||||
};
|
||||
|
||||
static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "bad atrac ID");
|
||||
}
|
||||
@@ -908,7 +909,7 @@ static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) {
|
||||
}
|
||||
|
||||
bool jointStereo = false;
|
||||
if (atrac->track_.codecType == PSP_MODE_AT_3) {
|
||||
if (atrac->GetTrack().codecType == PSP_MODE_AT_3) {
|
||||
// See if we can match the actual jointStereo value.
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < ARRAY_SIZE(at3HeaderMap); ++i) {
|
||||
@@ -918,14 +919,14 @@ static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
ERROR_LOG_REPORT(ME, "AT3 header map lacks entry for bpf: %i channels: %i", atrac->GetTrack().BytesPerFrame(), atrac->Channels());
|
||||
ERROR_LOG_REPORT(ME, "AT3 header map lacks entry for bpf: %i channels: %i", atrac->GetTrack().BytesPerFrame(), atrac->GetTrack().channels);
|
||||
// TODO: Should we return an error code for these values?
|
||||
}
|
||||
}
|
||||
|
||||
atrac->InitLowLevel(paramsAddr, jointStereo);
|
||||
|
||||
const char *codecName = atrac->track_.codecType == PSP_MODE_AT_3 ? "atrac3" : "atrac3+";
|
||||
const char *codecName = atrac->GetTrack().codecType == PSP_MODE_AT_3 ? "atrac3" : "atrac3+";
|
||||
const char *channelName = atrac->GetTrack().channels == 1 ? "mono" : "stereo";
|
||||
return hleLogSuccessInfoI(ME, 0, "%s %s audio", codecName, channelName);
|
||||
}
|
||||
@@ -936,7 +937,7 @@ static int sceAtracLowLevelDecode(int atracID, u32 sourceAddr, u32 sourceBytesCo
|
||||
auto outp = PSPPointer<u8>::Create(samplesAddr);
|
||||
auto outWritten = PSPPointer<u32_le>::Create(sampleBytesAddr);
|
||||
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
if (!atrac) {
|
||||
return hleLogError(ME, ATRAC_ERROR_BAD_ATRACID, "bad atrac ID");
|
||||
}
|
||||
@@ -948,7 +949,7 @@ static int sceAtracLowLevelDecode(int atracID, u32 sourceAddr, u32 sourceBytesCo
|
||||
|
||||
int bytesConsumed = 0;
|
||||
int bytesWritten = 0;
|
||||
atrac->GetDecoder()->Decode(srcp, atrac->GetTrack().BytesPerFrame(), &bytesConsumed, 2, outp, &bytesWritten);
|
||||
atrac->Decoder()->Decode(srcp, atrac->GetTrack().BytesPerFrame(), &bytesConsumed, 2, outp, &bytesWritten);
|
||||
*srcConsumed = bytesConsumed;
|
||||
*outWritten = bytesWritten;
|
||||
|
||||
@@ -980,14 +981,14 @@ static int sceAtracSetAA3HalfwayBufferAndGetID(u32 buffer, u32 readSize, u32 buf
|
||||
// External interface used by sceSas' AT3 integration.
|
||||
|
||||
u32 AtracSasAddStreamData(int atracID, u32 bufPtr, u32 bytesToAdd) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
if (!atrac)
|
||||
return 0;
|
||||
return atrac->AddStreamDataSas(bufPtr, bytesToAdd);
|
||||
}
|
||||
|
||||
u32 AtracSasDecodeData(int atracID, u8* outbuf, u32 outbufPtr, u32 *SamplesNum, u32* finish, int *remains) {
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
AtracBase *atrac = getAtrac(atracID);
|
||||
if (!atrac)
|
||||
return 0;
|
||||
return atrac->DecodeData(outbuf, outbufPtr, SamplesNum, finish, remains);
|
||||
|
||||
Reference in new issue
Block a user