Skip to content

Commit db5ef6f

Browse files
committed
Merge pull request #20566 from hrydgard/atrac-cleanup
Atrac code cleanup, logging and comment fixes
1 parent dde8d22 commit db5ef6f

File tree

17 files changed

+462
-389
lines changed

17 files changed

+462
-389
lines changed

Common/Log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ enum class Log {
4040
HLE,
4141
JIT,
4242
Loader,
43+
Mpeg,
44+
Atrac,
4345
ME,
4446
MemMap,
4547
SasMix,

Common/Log/LogManager.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ static const char * const g_logTypeNames[] = {
7979
"HLE",
8080
"JIT",
8181
"LOADER",
82-
"ME", // Media Engine
82+
"MPEG",
83+
"ATRAC",
84+
"ME", // Rest of the media Engine
8385
"MEMMAP",
8486
"SASMIX",
8587
"SAVESTATE",
@@ -213,12 +215,12 @@ void LogManager::SaveConfig(Section *section) {
213215
}
214216
}
215217

216-
void LogManager::LoadConfig(const Section *section, bool debugDefaults) {
218+
void LogManager::LoadConfig(const Section *section) {
217219
for (int i = 0; i < (int)Log::NUMBER_OF_LOGS; i++) {
218220
bool enabled = false;
219221
int level = 0;
220222
section->Get((std::string(g_logTypeNames[i]) + "Enabled"), &enabled, true);
221-
section->Get((std::string(g_logTypeNames[i]) + "Level"), &level, (int)(debugDefaults ? LogLevel::LDEBUG : LogLevel::LERROR));
223+
section->Get((std::string(g_logTypeNames[i]) + "Level"), &level, (int)LogLevel::LERROR);
222224
g_log[i].enabled = enabled;
223225
g_log[i].level = (LogLevel)level;
224226
}

Common/Log/LogManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class LogManager {
153153
const Path &GetLogFilePath() const { return logFilename_; }
154154

155155
void SaveConfig(Section *section);
156-
void LoadConfig(const Section *section, bool debugDefaults);
156+
void LoadConfig(const Section *section);
157157

158158
static const char *GetLogTypeName(Log type);
159159

Common/System/Request.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool RequestManager::MakeSystemRequest(SystemRequestType type, RequesterToken to
7272
callbackMap_[requestId] = { callback, failedCallback, token };
7373
}
7474

75-
DEBUG_LOG(Log::System, "Making system request %s: id %d", RequestTypeAsString(type), requestId);
75+
VERBOSE_LOG(Log::System, "Making system request %s: id %d", RequestTypeAsString(type), requestId);
7676
std::string p1(param1);
7777
std::string p2(param2);
7878
// TODO: Convert to string_view

Core/Config.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,11 +1223,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
12231223

12241224
Section *log = iniFile.GetOrCreateSection(logSectionName);
12251225

1226-
bool debugDefaults = false;
1227-
#ifdef _DEBUG
1228-
debugDefaults = true;
1229-
#endif
1230-
g_logManager.LoadConfig(log, debugDefaults);
1226+
g_logManager.LoadConfig(log);
12311227

12321228
Section *recent = iniFile.GetOrCreateSection("Recent");
12331229
recent->Get("MaxRecent", &iMaxRecent, 60);

Core/HLE/AtracCtx.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ void Atrac::WriteContextToPSPMem() {
225225
}
226226

227227
void Track::DebugLog() const {
228-
DEBUG_LOG(Log::ME, "ATRAC analyzed: %s channels: %d filesize: %d bitrate: %d kbps jointStereo: %d",
228+
DEBUG_LOG(Log::Atrac, "ATRAC analyzed: %s channels: %d filesize: %d bitrate: %d kbps jointStereo: %d",
229229
codecType == PSP_CODEC_AT3 ? "AT3" : "AT3Plus", channels, fileSize, bitrate / 1024, jointStereo);
230-
DEBUG_LOG(Log::ME, "dataoff: %d firstSampleOffset: %d endSample: %d", dataByteOffset, firstSampleOffset, endSample);
231-
DEBUG_LOG(Log::ME, "loopStartSample: %d loopEndSample: %d", loopStartSample, loopEndSample);
232-
DEBUG_LOG(Log::ME, "sampleSize: %d (%03x", bytesPerFrame, bytesPerFrame);
230+
DEBUG_LOG(Log::Atrac, "dataoff: %d firstSampleOffset: %d endSample: %d", dataByteOffset, firstSampleOffset, endSample);
231+
DEBUG_LOG(Log::Atrac, "loopStartSample: %d loopEndSample: %d", loopStartSample, loopEndSample);
232+
DEBUG_LOG(Log::Atrac, "sampleSize: %d (%03x)", bytesPerFrame, bytesPerFrame);
233233
}
234234

235235
int Atrac::GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const {
@@ -291,7 +291,7 @@ void Atrac::CalculateStreamInfo(u32 *outReadOffset) {
291291

292292
// If you don't think this should be here, remove it. It's just a temporary safety check.
293293
if (first_.offset + first_.writableBytes > bufferMaxSize_) {
294-
ERROR_LOG_REPORT(Log::ME, "Somehow calculated too many writable bytes: %d + %d > %d", first_.offset, first_.writableBytes, bufferMaxSize_);
294+
ERROR_LOG_REPORT(Log::Atrac, "Somehow calculated too many writable bytes: %d + %d > %d", first_.offset, first_.writableBytes, bufferMaxSize_);
295295
first_.offset = 0;
296296
first_.writableBytes = bufferMaxSize_;
297297
}
@@ -327,7 +327,7 @@ void AtracBase::CreateDecoder(int codecType, int bytesPerFrame, int channels) {
327327
}
328328
}
329329

330-
int Atrac::GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) {
330+
int Atrac::GetBufferInfoForResetting(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) {
331331
*delay = false;
332332
if (BufferState() == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER && !HasSecondBuffer()) {
333333
return SCE_ERROR_ATRAC_SECOND_BUFFER_NEEDED;
@@ -417,7 +417,7 @@ int Atrac::SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize,
417417
first_._filesize_dontuse = track_.fileSize;
418418

419419
if (outputChannels != track_.channels) {
420-
WARN_LOG(Log::ME, "Atrac::SetData: outputChannels %d doesn't match track_.channels %d", outputChannels, track_.channels);
420+
WARN_LOG(Log::Atrac, "Atrac::SetData: outputChannels %d doesn't match track_.channels %d", outputChannels, track_.channels);
421421
}
422422

423423
first_.addr = buffer;
@@ -438,7 +438,7 @@ int Atrac::SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize,
438438
if (track_.codecType != PSP_CODEC_AT3 && track_.codecType != PSP_CODEC_AT3PLUS) {
439439
// Shouldn't have gotten here, Analyze() checks this.
440440
bufferState_ = ATRAC_STATUS_NO_DATA;
441-
ERROR_LOG(Log::ME, "unexpected codec type %d in set data", track_.codecType);
441+
ERROR_LOG(Log::Atrac, "unexpected codec type %d in set data", track_.codecType);
442442
return SCE_ERROR_ATRAC_UNKNOWN_FORMAT;
443443
}
444444

@@ -467,10 +467,16 @@ int Atrac::SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize,
467467
Memory::Memcpy(dataBuf_, buffer, copybytes, "AtracSetData");
468468
}
469469
CreateDecoder(track.codecType, track.bytesPerFrame, track.channels);
470-
INFO_LOG(Log::ME, "Atrac::SetData (buffer=%08x, readSize=%d, bufferSize=%d): %s %s (%d channels) audio", buffer, readSize, bufferSize, codecName, channelName, track_.channels);
470+
INFO_LOG(Log::Atrac, "Atrac::SetData (buffer=%08x, readSize=%d, bufferSize=%d): %s %s (%d channels) audio", buffer, readSize, bufferSize, codecName, channelName, track_.channels);
471+
INFO_LOG(Log::Atrac, "BufferState: %s", AtracStatusToString(bufferState_));
472+
INFO_LOG(Log::Atrac,
473+
"buffer: %08x bufferSize: %d readSize: %d bufferPos: %d\n",
474+
buffer, bufferSize, readSize, bufferPos_
475+
);
471476

472477
if (track_.channels == 2 && outputChannels == 1) {
473478
// We still do all the tasks, we just return this error.
479+
WARN_LOG(Log::Atrac, "Tried to load a stereo track into a mono context, returning NOT_MONO");
474480
return SCE_ERROR_ATRAC_NOT_MONO;
475481
}
476482
return 0;
@@ -494,7 +500,7 @@ int Atrac::SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) {
494500
return 0;
495501
}
496502

497-
int Atrac::GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) {
503+
int Atrac::GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) const {
498504
if (BufferState() != ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER) {
499505
// Writes zeroes in this error case.
500506
*fileOffset = 0;
@@ -715,14 +721,18 @@ u32 Atrac::DecodeData(u8 *outbuf, u32 outbufPtr, int *SamplesNum, int *finish, i
715721
// Skip the initial frame used to load state for the looped frame.
716722
// TODO: We will want to actually read this in.
717723
// TODO again: This seems to happen on the first frame of playback regardless of loops.
718-
// Can't be good.
724+
// Actually, this is explained now if we look at AtracCtx2, although this isn't really accurate.
725+
DEBUG_LOG(Log::Atrac, "Calling ConsumeFrame to skip the initial frame");
719726
ConsumeFrame();
720727
}
721728

722729
SeekToSample(currentSample_);
723730

724731
bool gotFrame = false;
725732
u32 off = track_.FileOffsetBySample(currentSample_ - skipSamples);
733+
734+
DEBUG_LOG(Log::Atrac, "Decode(%08x): nextFileOff: %d", outbufPtr, off);
735+
726736
if (off < first_.size) {
727737
uint8_t *indata = BufferStart() + off;
728738
int bytesConsumed = 0;
@@ -846,7 +856,7 @@ int Atrac::ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrit
846856
// Reuse the same calculation as before.
847857
AtracResetBufferInfo bufferInfo;
848858
bool ignored;
849-
GetResetBufferInfo(&bufferInfo, sample, &ignored);
859+
GetBufferInfoForResetting(&bufferInfo, sample, &ignored);
850860

851861
if ((u32)bytesWrittenFirstBuf < bufferInfo.first.minWriteBytes || (u32)bytesWrittenFirstBuf > bufferInfo.first.writableBytes) {
852862
return SCE_ERROR_ATRAC_BAD_FIRST_RESET_SIZE;
@@ -979,9 +989,9 @@ void Atrac::NotifyGetContextAddress() {
979989
context_ = kernelMemory.Alloc(contextSize, false, StringFromFormat("AtracCtx/%d", atracID_).c_str());
980990
if (context_.IsValid())
981991
Memory::Memset(context_.ptr, 0, contextSize, "AtracContextClear");
982-
WARN_LOG(Log::ME, "%08x=_sceAtracGetContextAddress(%i): allocated new context", context_.ptr, atracID_);
992+
WARN_LOG(Log::Atrac, "%08x=_sceAtracGetContextAddress(%i): allocated new context", context_.ptr, atracID_);
983993
} else {
984-
WARN_LOG(Log::ME, "%08x=_sceAtracGetContextAddress(%i)", context_.ptr, atracID_);
994+
WARN_LOG(Log::Atrac, "%08x=_sceAtracGetContextAddress(%i)", context_.ptr, atracID_);
985995
}
986996
WriteContextToPSPMem();
987997
}

Core/HLE/AtracCtx.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ class AtracBase {
124124
virtual int BytesPerFrame() const = 0;
125125
virtual int SamplesPerFrame() const = 0;
126126

127-
virtual void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) = 0;
127+
virtual void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) = 0; // This should be const, but the legacy impl stops it (it's wrong).
128128
virtual int AddStreamData(u32 bytesToAdd) = 0;
129129
virtual int ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf, bool *delay) = 0;
130-
virtual int GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) = 0;
130+
virtual int GetBufferInfoForResetting(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) = 0; // NOTE: Not const! This can cause SkipFrames!
131131
virtual int SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize, int outputChannels) = 0;
132132

133-
virtual int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) = 0;
133+
virtual int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) const = 0;
134134
virtual int SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) = 0;
135135
virtual u32 DecodeData(u8 *outbuf, u32 outbufPtr, int *SamplesNum, int *finish, int *remains) = 0;
136136
virtual int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) = 0;
137137

138-
virtual u32 GetNextSamples() = 0;
138+
virtual u32 GetNextSamples() = 0; // This should be const, but the legacy impl stops it (it's wrong).
139139
virtual void InitLowLevel(const Atrac3LowLevelParams &params, int codecType) = 0;
140140

141141
virtual void CheckForSas() = 0;
@@ -224,9 +224,9 @@ class Atrac : public AtracBase {
224224
// Notify the player that the user has written some new data.
225225
int AddStreamData(u32 bytesToAdd) override;
226226
int ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf, bool *delay) override;
227-
int GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) override;
227+
int GetBufferInfoForResetting(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) override; // NOTE: Not const! This can cause SkipFrames! (although only in the AtracCtx2)
228228
int SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize, int outputChannels) override;
229-
int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) override;
229+
int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) const override;
230230
int SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) override;
231231
u32 DecodeData(u8 *outbuf, u32 outbufPtr, int *SamplesNum, int *finish, int *remains) override;
232232
int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) override;

0 commit comments

Comments
 (0)