mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Mp3: Apply offset to stream read buffer.
Handle errors for sceMp3CheckStreamDataNeeded as well.
This commit is contained in:
parent
f9863c3be2
commit
e4d2712897
3 changed files with 24 additions and 14 deletions
|
@ -181,15 +181,16 @@ static int sceMp3ResetPlayPosition(u32 mp3) {
|
|||
}
|
||||
|
||||
static int sceMp3CheckStreamDataNeeded(u32 mp3) {
|
||||
DEBUG_LOG(ME, "sceMp3CheckStreamDataNeeded(%08x)", mp3);
|
||||
|
||||
AuCtx *ctx = getMp3Ctx(mp3);
|
||||
if (!ctx) {
|
||||
ERROR_LOG(ME, "%s: bad mp3 handle %08x", __FUNCTION__, mp3);
|
||||
return -1;
|
||||
if (mp3 >= MP3_MAX_HANDLES)
|
||||
return hleLogError(ME, ERROR_MP3_INVALID_HANDLE, "invalid handle");
|
||||
return hleLogError(ME, ERROR_MP3_UNRESERVED_HANDLE, "unreserved handle");
|
||||
} else if (ctx->AuBuf == 0) {
|
||||
return hleLogError(ME, ERROR_MP3_UNRESERVED_HANDLE, "incorrect handle type");
|
||||
}
|
||||
|
||||
return ctx->AuCheckStreamDataNeeded();
|
||||
return hleLogSuccessI(ME, ctx->AuCheckStreamDataNeeded());
|
||||
}
|
||||
|
||||
static u32 sceMp3ReserveMp3Handle(u32 mp3Addr) {
|
||||
|
@ -344,15 +345,17 @@ static int __CalculateMp3Bitrates(int bitval, int mp3version, int mp3layer) {
|
|||
}
|
||||
|
||||
static int __ParseMp3Header(AuCtx *ctx, bool *isID3) {
|
||||
int header = bswap32(Memory::Read_U32(ctx->AuBuf));
|
||||
u32 ptr = ctx->AuBuf + ctx->AuStreamWorkareaSize();
|
||||
int header = bswap32(Memory::Read_U32(ptr));
|
||||
// ID3 tag , can be seen in Hanayaka Nari Wa ga Ichizoku.
|
||||
static const int ID3 = 0x49443300;
|
||||
if ((header & 0xFFFFFF00) == ID3) {
|
||||
*isID3 = true;
|
||||
int size = bswap32(Memory::Read_U32(ctx->AuBuf + ctx->startPos + 6));
|
||||
// TODO: Can we count on startPos being read already? What if it's past the buffer size?
|
||||
int size = bswap32(Memory::Read_U32(ptr + ctx->startPos + 6));
|
||||
// Highest bit of each byte has to be ignored (format: 0x7F7F7F7F)
|
||||
size = (size & 0x7F) | ((size & 0x7F00) >> 1) | ((size & 0x7F0000) >> 2) | ((size & 0x7F000000) >> 3);
|
||||
header = bswap32(Memory::Read_U32(ctx->AuBuf + ctx->startPos + 10 + size));
|
||||
header = bswap32(Memory::Read_U32(ptr + ctx->startPos + 10 + size));
|
||||
}
|
||||
return header;
|
||||
}
|
||||
|
|
|
@ -397,7 +397,7 @@ int AuCtx::AuStreamBytesNeeded() {
|
|||
if (readPos >= endPos)
|
||||
return 0;
|
||||
// Account for the workarea.
|
||||
int offset = 0x05c0;
|
||||
int offset = AuStreamWorkareaSize();
|
||||
return (int)AuBufSize - AuBufAvailable - offset;
|
||||
}
|
||||
|
||||
|
@ -405,8 +405,17 @@ int AuCtx::AuStreamBytesNeeded() {
|
|||
return std::min((int)AuBufSize - AuBufAvailable, (int)endPos - readPos);
|
||||
}
|
||||
|
||||
int AuCtx::AuStreamWorkareaSize() {
|
||||
// Note that this is 31 bytes more than the max layer 3 frame size.
|
||||
if (audioType == PSP_CODEC_MP3)
|
||||
return 0x05c0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// check how many bytes we have read from source file
|
||||
u32 AuCtx::AuNotifyAddStreamData(int size) {
|
||||
int offset = AuStreamWorkareaSize();
|
||||
|
||||
if (askedReadSize != 0) {
|
||||
// Old save state, numbers already adjusted.
|
||||
int diffsize = size - askedReadSize;
|
||||
|
@ -422,7 +431,7 @@ u32 AuCtx::AuNotifyAddStreamData(int size) {
|
|||
}
|
||||
|
||||
if (Memory::IsValidRange(AuBuf, size)) {
|
||||
sourcebuff.append((const char *)Memory::GetPointer(AuBuf), size);
|
||||
sourcebuff.append((const char *)Memory::GetPointer(AuBuf + offset), size);
|
||||
}
|
||||
|
||||
if (readPos >= (int)endPos && LoopNum != 0) {
|
||||
|
@ -441,10 +450,7 @@ u32 AuCtx::AuNotifyAddStreamData(int size) {
|
|||
// buff, size and srcPos are all pointers
|
||||
u32 AuCtx::AuGetInfoToAddStreamData(u32 bufPtr, u32 sizePtr, u32 srcPosPtr) {
|
||||
int readsize = AuStreamBytesNeeded();
|
||||
int offset = 0;
|
||||
if (audioType == PSP_CODEC_MP3) {
|
||||
offset = 0x05c0;
|
||||
}
|
||||
int offset = AuStreamWorkareaSize();
|
||||
|
||||
// we can recharge AuBuf from its beginning
|
||||
if (readsize != 0) {
|
||||
|
|
|
@ -100,6 +100,7 @@ public:
|
|||
u32 AuNotifyAddStreamData(int size);
|
||||
int AuCheckStreamDataNeeded();
|
||||
int AuStreamBytesNeeded();
|
||||
int AuStreamWorkareaSize();
|
||||
u32 AuResetPlayPosition();
|
||||
u32 AuResetPlayPositionByFrame(int position);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue