Mp3: Cleanup AuCtx constructor.

This commit is contained in:
Unknown W. Brackets 2019-05-04 06:40:43 -07:00
parent 49a17e9ab8
commit 4903e14aae
4 changed files with 29 additions and 45 deletions

View File

@ -141,9 +141,7 @@ void __Mp3DoState(PointerWrap &p) {
mp3->SumDecodedSamples = mp3_old->mp3SumDecodedSamples;
mp3->Version = mp3_old->mp3Version;
mp3->MaxOutputSample = mp3_old->mp3MaxSamples;
mp3->readPos = mp3_old->readPosition;
mp3->AuBufAvailable = 0; // reset to read from file
mp3->askedReadSize = 0;
mp3->SetReadPos(mp3_old->readPosition);
mp3->audioType = PSP_CODEC_MP3;
mp3->decoder = new SimpleAudio(mp3->audioType);
@ -249,12 +247,8 @@ static u32 sceMp3ReserveMp3Handle(u32 mp3Addr) {
Au->PCMBufSize = 0;
}
Au->SumDecodedSamples = 0;
Au->LoopNum = -1;
Au->AuBufAvailable = 0;
Au->readPos = Au->startPos;
Au->audioType = PSP_CODEC_MP3;
Au->SetReadPos(Au->startPos);
Au->decoder = new SimpleAudio(Au->audioType);
int handle = (int)mp3Map.size();
@ -422,7 +416,7 @@ static int sceMp3Init(u32 mp3) {
// Before we allow init, newer SDK versions next require at least 156 bytes.
// That happens to be the size of the first frame header for VBR.
if (sdkver >= 0x06000000 && ctx->readPos < 156) {
if (sdkver >= 0x06000000 && ctx->ReadPos() < 156) {
return hleDelayResult(hleLogError(ME, SCE_KERNEL_ERROR_INVALID_VALUE, "insufficient mp3 data for init"), "mp3 init", PARSE_DELAY_MS);
}
@ -647,7 +641,7 @@ static u32 sceMp3ResetPlayPositionByFrame(u32 mp3, u32 frame) {
return hleLogError(ME, ERROR_MP3_NOT_YET_INIT_HANDLE, "not yet init");
}
if ((int)frame >= ctx->AuGetFrameNum()) {
if (frame >= (u32)ctx->AuGetFrameNum()) {
return hleLogError(ME, ERROR_MP3_BAD_RESET_FRAME, "bad frame position");
}

View File

@ -252,7 +252,7 @@ static u32 sceAacInit(u32 id)
aac->Channels = 2;
aac->MaxOutputSample = aac->PCMBufSize / 4;
aac->readPos = aac->startPos;
aac->SetReadPos(aac->startPos);
aac->audioType = PSP_CODEC_AAC;
// create aac decoder

View File

@ -313,27 +313,14 @@ bool IsValidCodec(int codec){
// sceAu module starts from here
AuCtx::AuCtx() {
decoder = NULL;
startPos = 0;
endPos = 0;
LoopNum = -1;
AuBuf = 0;
AuBufSize = 2048;
PCMBuf = 0;
PCMBufSize = 2048;
AuBufAvailable = 0;
SumDecodedSamples = 0;
askedReadSize = 0;
audioType = 0;
FrameNum = 0;
};
}
AuCtx::~AuCtx(){
if (decoder){
AuCtx::~AuCtx() {
if (decoder) {
AudioClose(&decoder);
decoder = NULL;
decoder = nullptr;
}
};
}
size_t AuCtx::FindNextMp3Sync() {
if (audioType != PSP_CODEC_MP3) {

View File

@ -115,6 +115,9 @@ public:
int AuGetVersion() const { return Version; }
int AuGetFrameNum() const { return FrameNum; }
void SetReadPos(int pos) { readPos = pos; }
int ReadPos() { return readPos; }
void DoState(PointerWrap &p);
void EatSourceBuff(int amount) {
@ -126,12 +129,12 @@ public:
AuBufAvailable -= amount;
}
// Au source information. Written to from for example sceAacInit so public for now.
u64 startPos;
u64 endPos;
u32 AuBuf;
u32 AuBufSize;
u32 PCMBuf;
u32 PCMBufSize;
u64 startPos = 0;
u64 endPos = 0;
u32 AuBuf = 0;
u32 AuBufSize = 0;
u32 PCMBuf = 0;
u32 PCMBufSize = 0;
int freq = -1;
int BitRate = 0;
int SamplingRate = -1;
@ -139,26 +142,26 @@ public:
int Version = -1;
// State variables. These should be relatively easy to move into private.
u32 SumDecodedSamples;
int LoopNum;
u32 SumDecodedSamples = 0;
int LoopNum = -1;
u32 MaxOutputSample = 0;
int FrameNum; // number of decoded frame
int FrameNum = 0;
// Au decoder
SimpleAudio *decoder;
SimpleAudio *decoder = nullptr;
// Au type
int audioType;
// buffers informations
int AuBufAvailable; // the available buffer of AuBuf to be able to recharge data
int readPos; // read position in audio source file
int askedReadSize; // the size of data requied to be read from file by the game
int audioType = 0;
private:
size_t FindNextMp3Sync();
std::vector<u8> sourcebuff; // source buffer
// buffers informations
int AuBufAvailable = 0; // the available buffer of AuBuf to be able to recharge data
int readPos; // read position in audio source file
int askedReadSize = 0; // the size of data requied to be read from file by the game
};