2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
// This is pretty much a stub implementation. Doesn't actually do anything, just tries to return values
|
|
|
|
// to keep games happy anyway. So, no ATRAC3 music until someone has reverse engineered Atrac3+.
|
|
|
|
|
|
|
|
|
|
|
|
#include "HLE.h"
|
|
|
|
#include "../MIPS/MIPS.h"
|
2013-01-23 06:35:30 +00:00
|
|
|
#include "../CoreTiming.h"
|
2013-02-04 04:31:46 +00:00
|
|
|
#include "ChunkFile.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "sceKernel.h"
|
|
|
|
#include "sceUtility.h"
|
|
|
|
|
2013-05-12 09:00:21 +00:00
|
|
|
|
2013-03-11 15:36:47 +00:00
|
|
|
#define ATRAC_ERROR_API_FAIL 0x80630002
|
2013-05-04 08:00:00 +00:00
|
|
|
#define ATRAC_ERROR_NO_ATRACID 0x80630003
|
2013-05-12 09:00:21 +00:00
|
|
|
#define ATRAC_ERROR_INVALID_CODECTYPE 0x80630004
|
|
|
|
#define ATRAC_ERROR_BAD_ATRACID 0x80630005
|
|
|
|
#define ATRAC_ERROR_ALL_DATA_LOADED 0x80630009
|
|
|
|
#define ATRAC_ERROR_NO_DATA 0x80630010
|
|
|
|
#define ATRAC_ERROR_SECOND_BUFFER_NEEDED 0x80630012
|
|
|
|
#define ATRAC_ERROR_INCORRECT_READ_SIZE 0x80630013
|
2013-05-04 08:00:00 +00:00
|
|
|
#define ATRAC_ERROR_ADD_DATA_IS_TOO_BIG 0x80630018
|
2013-05-12 09:00:21 +00:00
|
|
|
#define ATRAC_ERROR_UNSET_PARAM 0x80630021
|
|
|
|
#define ATRAC_ERROR_SECOND_BUFFER_NOT_NEEDED 0x80630022
|
|
|
|
#define ATRAC_ERROR_BUFFER_IS_EMPTY 0x80630023
|
|
|
|
#define ATRAC_ERROR_ALL_DATA_DECODED 0x80630024
|
2013-04-12 16:49:22 +00:00
|
|
|
|
|
|
|
#define AT3_MAGIC 0x0270
|
2013-01-06 03:42:28 +00:00
|
|
|
#define AT3_PLUS_MAGIC 0xFFFE
|
|
|
|
#define PSP_MODE_AT_3_PLUS 0x00001000
|
|
|
|
#define PSP_MODE_AT_3 0x00001001
|
2012-12-23 05:23:17 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
const int FMT_CHUNK_MAGIC = 0x20746D66;
|
|
|
|
const int DATA_CHUNK_MAGIC = 0x61746164;
|
|
|
|
const int SMPL_CHUNK_MAGIC = 0x6C706D73;
|
|
|
|
const int FACT_CHUNK_MAGIC = 0x74636166;
|
|
|
|
|
|
|
|
const int PSP_ATRAC_ALLDATA_IS_ON_MEMORY = -1;
|
|
|
|
const int PSP_ATRAC_NONLOOP_STREAM_DATA_IS_ON_MEMORY = -2;
|
|
|
|
const int PSP_ATRAC_LOOP_STREAM_DATA_IS_ON_MEMORY = -3;
|
|
|
|
|
2013-02-02 05:16:59 +00:00
|
|
|
const u32 ATRAC_MAX_SAMPLES = 1024;
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
#ifdef USE_FFMPEG
|
2013-05-12 13:24:52 +00:00
|
|
|
|
|
|
|
// Urgh! Why is this needed?
|
|
|
|
#ifdef ANDROID
|
|
|
|
#ifndef UINT64_C
|
|
|
|
#define UINT64_C(c) (c ## ULL)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <libswresample/swresample.h>
|
|
|
|
#include <libavutil/samplefmt.h>
|
|
|
|
}
|
|
|
|
#endif // USE_FFMPEG
|
|
|
|
|
2013-02-02 10:36:24 +00:00
|
|
|
struct InputBuffer {
|
|
|
|
u32 addr;
|
|
|
|
u32 size;
|
|
|
|
u32 offset;
|
|
|
|
u32 writableBytes;
|
|
|
|
u32 neededBytes;
|
|
|
|
u32 filesize;
|
|
|
|
u32 fileoffset;
|
|
|
|
};
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
struct Atrac;
|
2013-05-04 16:28:11 +00:00
|
|
|
int __AtracSetContext(Atrac *atrac, u32 buffer, u32 bufferSize);
|
2013-05-04 08:00:00 +00:00
|
|
|
int _AtracSetData(Atrac *atrac, u32 buffer, u32 bufferSize);
|
|
|
|
|
2013-04-12 16:49:22 +00:00
|
|
|
struct AtracLoopInfo {
|
|
|
|
int cuePointID;
|
|
|
|
int type;
|
|
|
|
int startSample;
|
|
|
|
int endSample;
|
|
|
|
int fraction;
|
|
|
|
int playCount;
|
|
|
|
};
|
|
|
|
|
2013-01-05 17:10:13 +00:00
|
|
|
struct Atrac {
|
2013-05-06 22:08:57 +00:00
|
|
|
Atrac() : atracID(-1), data_buf(0), decodePos(0), decodeEnd(0), atracChannels(2), atracOutputChannels(2), loopNum(0),
|
|
|
|
atracBitrate(64), atracBytesPerFrame(0), atracBufSize(0),
|
|
|
|
currentSample(0), endSample(-1), firstSampleoffset(0), loopinfoNum(0) {
|
2013-02-02 10:36:24 +00:00
|
|
|
memset(&first, 0, sizeof(first));
|
|
|
|
memset(&second, 0, sizeof(second));
|
2013-05-04 08:00:00 +00:00
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
pFormatCtx = 0;
|
|
|
|
pAVIOCtx = 0;
|
|
|
|
pCodecCtx = 0;
|
|
|
|
pSwrCtx = 0;
|
|
|
|
pFrame = 0;
|
|
|
|
#endif // USE_FFMPEG
|
2013-02-02 10:36:24 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
~Atrac() {
|
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
ReleaseFFMPEGContext();
|
|
|
|
#endif // USE_FFMPEG
|
2013-05-04 16:28:11 +00:00
|
|
|
if (data_buf)
|
|
|
|
delete [] data_buf;
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 16:31:51 +00:00
|
|
|
void DoState(PointerWrap &p) {
|
2013-05-04 08:00:00 +00:00
|
|
|
p.Do(atracChannels);
|
|
|
|
p.Do(atracOutputChannels);
|
|
|
|
|
2013-05-04 16:28:11 +00:00
|
|
|
p.Do(atracID);
|
|
|
|
p.Do(first);
|
|
|
|
p.Do(atracBufSize);
|
|
|
|
p.Do(codeType);
|
|
|
|
u32 has_data_buf = data_buf != NULL;
|
|
|
|
p.Do(has_data_buf);
|
|
|
|
if (has_data_buf) {
|
|
|
|
if (p.mode == p.MODE_READ) {
|
2013-05-04 08:00:00 +00:00
|
|
|
data_buf = new u8[first.filesize];
|
|
|
|
}
|
2013-05-04 16:28:11 +00:00
|
|
|
p.DoArray(data_buf, first.filesize);
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
2013-05-04 16:28:11 +00:00
|
|
|
if (p.mode == p.MODE_READ && data_buf != NULL) {
|
|
|
|
__AtracSetContext(this, first.addr, atracBufSize);
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
|
|
|
p.Do(second);
|
|
|
|
|
2013-02-01 16:31:51 +00:00
|
|
|
p.Do(decodePos);
|
2013-02-03 18:44:20 +00:00
|
|
|
p.Do(decodeEnd);
|
2013-05-04 08:00:00 +00:00
|
|
|
|
2013-04-12 16:49:22 +00:00
|
|
|
p.Do(atracBitrate);
|
|
|
|
p.Do(atracBytesPerFrame);
|
2013-05-04 08:00:00 +00:00
|
|
|
|
2013-04-12 16:49:22 +00:00
|
|
|
p.Do(currentSample);
|
|
|
|
p.Do(endSample);
|
|
|
|
p.Do(firstSampleoffset);
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
p.Do(loopinfo);
|
|
|
|
p.Do(loopinfoNum);
|
|
|
|
|
|
|
|
p.Do(loopStartSample);
|
|
|
|
p.Do(loopEndSample);
|
|
|
|
p.Do(loopNum);
|
|
|
|
|
2013-02-01 16:31:51 +00:00
|
|
|
p.DoMarker("Atrac");
|
|
|
|
}
|
2013-01-05 17:10:13 +00:00
|
|
|
|
2013-02-04 00:54:52 +00:00
|
|
|
void Analyze();
|
2013-05-04 08:00:00 +00:00
|
|
|
u32 getDecodePosBySample(int sample) {
|
|
|
|
return (u32)(firstSampleoffset + sample / ATRAC_MAX_SAMPLES * atracBytesPerFrame );
|
|
|
|
}
|
2013-05-16 17:15:23 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
int getRemainFrames() {
|
2013-05-16 17:15:23 +00:00
|
|
|
// games would like to add atrac data when it wants.
|
|
|
|
// Do not try to guess when it want to add data.
|
|
|
|
// Just return current remainFrames.
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
int remainFrame;
|
2013-05-12 13:27:41 +00:00
|
|
|
if (first.fileoffset >= first.filesize || currentSample >= endSample)
|
|
|
|
remainFrame = PSP_ATRAC_ALLDATA_IS_ON_MEMORY;
|
2013-05-16 17:15:23 +00:00
|
|
|
else {
|
2013-05-05 20:02:16 +00:00
|
|
|
// guess the remain frames.
|
2013-05-16 17:15:23 +00:00
|
|
|
remainFrame = ((int)first.size - (int)decodePos) / atracBytesPerFrame;
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
|
|
|
return remainFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
int atracID;
|
|
|
|
u8* data_buf;
|
2013-02-04 00:54:52 +00:00
|
|
|
|
2013-02-01 16:31:51 +00:00
|
|
|
u32 decodePos;
|
2013-02-03 18:44:20 +00:00
|
|
|
u32 decodeEnd;
|
2013-05-04 08:00:00 +00:00
|
|
|
|
2013-04-12 16:49:22 +00:00
|
|
|
u16 atracChannels;
|
2013-05-04 08:00:00 +00:00
|
|
|
u16 atracOutputChannels;
|
2013-04-12 16:49:22 +00:00
|
|
|
u32 atracBitrate;
|
|
|
|
u16 atracBytesPerFrame;
|
2013-05-04 08:00:00 +00:00
|
|
|
u32 atracBufSize;
|
2013-04-12 16:49:22 +00:00
|
|
|
|
|
|
|
int currentSample;
|
|
|
|
int endSample;
|
2013-05-04 08:00:00 +00:00
|
|
|
// Offset of the first sample in the input buffer
|
2013-04-12 16:49:22 +00:00
|
|
|
int firstSampleoffset;
|
|
|
|
|
|
|
|
std::vector<AtracLoopInfo> loopinfo;
|
2013-05-04 08:00:00 +00:00
|
|
|
int loopinfoNum;
|
|
|
|
|
|
|
|
int loopStartSample;
|
|
|
|
int loopEndSample;
|
|
|
|
int loopNum;
|
|
|
|
|
|
|
|
u32 codeType;
|
2013-02-02 10:36:24 +00:00
|
|
|
|
|
|
|
InputBuffer first;
|
|
|
|
InputBuffer second;
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
AVFormatContext *pFormatCtx;
|
|
|
|
AVIOContext *pAVIOCtx;
|
|
|
|
AVCodecContext *pCodecCtx;
|
|
|
|
SwrContext *pSwrCtx;
|
|
|
|
AVFrame *pFrame;
|
|
|
|
int audio_stream_index;
|
|
|
|
void ReleaseFFMPEGContext() {
|
|
|
|
if (pFrame)
|
|
|
|
av_free(pFrame);
|
|
|
|
if (pAVIOCtx && pAVIOCtx->buffer)
|
|
|
|
av_free(pAVIOCtx->buffer);
|
|
|
|
if (pAVIOCtx)
|
|
|
|
av_free(pAVIOCtx);
|
|
|
|
if (pSwrCtx)
|
|
|
|
swr_free(&pSwrCtx);
|
|
|
|
if (pCodecCtx)
|
|
|
|
avcodec_close(pCodecCtx);
|
|
|
|
if (pFormatCtx)
|
|
|
|
avformat_close_input(&pFormatCtx);
|
|
|
|
pFormatCtx = 0;
|
|
|
|
pAVIOCtx = 0;
|
|
|
|
pCodecCtx = 0;
|
|
|
|
pSwrCtx = 0;
|
|
|
|
pFrame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeekToSample(int sample) {
|
|
|
|
s64 seek_pos = (s64)sample;
|
|
|
|
av_seek_frame(pFormatCtx, audio_stream_index, seek_pos, 0);
|
|
|
|
}
|
|
|
|
#endif // USE_FFMPEG
|
|
|
|
|
2013-01-05 17:10:13 +00:00
|
|
|
};
|
|
|
|
|
2013-02-01 16:31:51 +00:00
|
|
|
std::map<int, Atrac *> atracMap;
|
2013-03-22 15:21:02 +00:00
|
|
|
u8 nextAtracID;
|
2013-02-01 16:31:51 +00:00
|
|
|
|
2013-03-22 15:21:02 +00:00
|
|
|
void __AtracInit() {
|
|
|
|
nextAtracID = 0;
|
2013-05-04 08:00:00 +00:00
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
avcodec_register_all();
|
|
|
|
av_register_all();
|
|
|
|
#endif // USE_FFMPEG
|
2013-02-01 16:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __AtracDoState(PointerWrap &p) {
|
2013-02-04 09:31:02 +00:00
|
|
|
p.Do(atracMap);
|
2013-03-22 15:21:02 +00:00
|
|
|
p.Do(nextAtracID);
|
2013-02-01 16:31:51 +00:00
|
|
|
|
|
|
|
p.DoMarker("sceAtrac");
|
|
|
|
}
|
|
|
|
|
2013-03-22 15:21:02 +00:00
|
|
|
void __AtracShutdown() {
|
2013-02-01 16:31:51 +00:00
|
|
|
for (auto it = atracMap.begin(), end = atracMap.end(); it != end; ++it) {
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
atracMap.clear();
|
|
|
|
}
|
2013-01-05 17:10:13 +00:00
|
|
|
|
|
|
|
Atrac *getAtrac(int atracID) {
|
2013-02-01 16:31:51 +00:00
|
|
|
if (atracMap.find(atracID) == atracMap.end()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return atracMap[atracID];
|
|
|
|
}
|
|
|
|
|
|
|
|
int createAtrac(Atrac *atrac) {
|
2013-03-22 15:21:02 +00:00
|
|
|
int id = nextAtracID++;
|
2013-02-01 16:31:51 +00:00
|
|
|
atracMap[id] = atrac;
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->atracID = id;
|
2013-02-01 16:31:51 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteAtrac(int atracID) {
|
|
|
|
if (atracMap.find(atracID) != atracMap.end()) {
|
|
|
|
delete atracMap[atracID];
|
|
|
|
atracMap.erase(atracID);
|
2013-01-05 17:10:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
int getCodecType(int addr) {
|
|
|
|
int at3magic = Memory::Read_U16(addr+20);
|
2013-01-06 03:42:28 +00:00
|
|
|
if (at3magic == AT3_MAGIC) {
|
|
|
|
return PSP_MODE_AT_3;
|
|
|
|
} else if (at3magic == AT3_PLUS_MAGIC) {
|
|
|
|
return PSP_MODE_AT_3_PLUS;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-05 17:10:13 +00:00
|
|
|
|
2013-02-04 00:54:52 +00:00
|
|
|
void Atrac::Analyze()
|
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
// reset some values
|
2013-04-12 16:49:22 +00:00
|
|
|
currentSample = 0;
|
|
|
|
endSample = -1;
|
|
|
|
loopNum = 0;
|
|
|
|
loopinfoNum = 0;
|
2013-05-04 08:00:00 +00:00
|
|
|
loopinfo.clear();
|
2013-04-12 16:49:22 +00:00
|
|
|
loopStartSample = -1;
|
|
|
|
loopEndSample = -1;
|
|
|
|
decodePos = 0;
|
|
|
|
|
2013-05-12 09:00:21 +00:00
|
|
|
if (first.size < 0x100) {
|
2013-02-04 00:54:52 +00:00
|
|
|
ERROR_LOG(HLE, "Atrac buffer very small: %d", first.size);
|
|
|
|
return;
|
|
|
|
}
|
2013-05-12 09:00:21 +00:00
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(first.addr)) {
|
2013-03-14 05:59:07 +00:00
|
|
|
WARN_LOG(HLE, "Atrac buffer at invalid address: %08x-%08x", first.addr, first.size);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-04 00:54:52 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
// TODO: Validate stuff.
|
2013-02-04 00:54:52 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
// RIFF size excluding chunk header.
|
2013-02-04 00:54:52 +00:00
|
|
|
first.filesize = Memory::Read_U32(first.addr + 4) + 8;
|
|
|
|
|
|
|
|
u32 offset = 12;
|
2013-04-12 16:49:22 +00:00
|
|
|
int atracSampleoffset = 0;
|
2013-03-14 05:59:07 +00:00
|
|
|
|
2013-04-12 16:49:22 +00:00
|
|
|
this->decodeEnd = first.filesize;
|
|
|
|
bool bfoundData = false;
|
|
|
|
while ((first.filesize - offset) >= 8 && !bfoundData) {
|
|
|
|
int chunkMagic = Memory::Read_U32(first.addr + offset);
|
2013-05-13 08:20:04 +00:00
|
|
|
u32 chunkSize = Memory::Read_U32(first.addr + offset + 4);
|
2013-02-04 00:54:52 +00:00
|
|
|
offset += 8;
|
2013-04-12 16:49:22 +00:00
|
|
|
if (chunkSize > first.filesize - offset)
|
|
|
|
break;
|
|
|
|
switch (chunkMagic) {
|
2013-05-04 08:00:00 +00:00
|
|
|
case FMT_CHUNK_MAGIC:
|
|
|
|
{
|
|
|
|
if (chunkSize >= 16) {
|
|
|
|
int codeMagic = Memory::Read_U16(first.addr + offset);
|
|
|
|
if (codeMagic == AT3_MAGIC)
|
|
|
|
codeType = PSP_MODE_AT_3;
|
|
|
|
else if (codeMagic == AT3_PLUS_MAGIC)
|
|
|
|
codeType = PSP_MODE_AT_3_PLUS;
|
|
|
|
else
|
|
|
|
codeType = 0;
|
|
|
|
atracChannels = Memory::Read_U16(first.addr + offset + 2);
|
|
|
|
// int atracSamplerate = Memory::Read_U32(first.addr + offset + 4); ;Should always be 44100Hz
|
|
|
|
int avgBytesPerSec = Memory::Read_U32(first.addr + offset + 8);
|
|
|
|
atracBitrate = avgBytesPerSec * 8;
|
|
|
|
atracBytesPerFrame = Memory::Read_U16(first.addr + offset + 12);
|
2013-04-12 16:49:22 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FACT_CHUNK_MAGIC:
|
|
|
|
{
|
|
|
|
if (chunkSize >= 8) {
|
|
|
|
endSample = Memory::Read_U32(first.addr + offset);
|
|
|
|
atracSampleoffset = Memory::Read_U32(first.addr + offset + 4);
|
2013-04-12 16:49:22 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SMPL_CHUNK_MAGIC:
|
|
|
|
{
|
|
|
|
if (chunkSize < 36)
|
|
|
|
break;
|
|
|
|
int checkNumLoops = Memory::Read_U32(first.addr + offset + 28);
|
|
|
|
if (chunkSize >= 36 + checkNumLoops * 24) {
|
|
|
|
loopinfoNum = checkNumLoops;
|
|
|
|
loopinfo.resize(loopinfoNum);
|
|
|
|
u32 loopinfoAddr = first.addr + offset + 36;
|
|
|
|
for (int i = 0; i < loopinfoNum; i++, loopinfoAddr += 24) {
|
|
|
|
loopinfo[i].cuePointID = Memory::Read_U32(loopinfoAddr);
|
|
|
|
loopinfo[i].type = Memory::Read_U32(loopinfoAddr + 4);
|
|
|
|
loopinfo[i].startSample = Memory::Read_U32(loopinfoAddr + 8) - atracSampleoffset;
|
|
|
|
loopinfo[i].endSample = Memory::Read_U32(loopinfoAddr + 12) - atracSampleoffset;
|
|
|
|
loopinfo[i].fraction = Memory::Read_U32(loopinfoAddr + 16);
|
|
|
|
loopinfo[i].playCount = Memory::Read_U32(loopinfoAddr + 20);
|
|
|
|
|
|
|
|
if (loopinfo[i].endSample > endSample)
|
|
|
|
loopinfo[i].endSample = endSample;
|
|
|
|
}
|
2013-04-12 16:49:22 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DATA_CHUNK_MAGIC:
|
|
|
|
{
|
|
|
|
bfoundData = true;
|
|
|
|
firstSampleoffset = offset;
|
|
|
|
}
|
|
|
|
break;
|
2013-02-04 00:54:52 +00:00
|
|
|
}
|
2013-04-12 16:49:22 +00:00
|
|
|
offset += chunkSize;
|
2013-02-04 00:54:52 +00:00
|
|
|
}
|
2013-04-12 16:49:22 +00:00
|
|
|
|
|
|
|
// set the loopStartSample and loopEndSample by loopinfo
|
|
|
|
if (loopinfoNum > 0) {
|
|
|
|
loopStartSample = loopinfo[0].startSample;
|
|
|
|
loopEndSample = loopinfo[0].endSample;
|
|
|
|
} else {
|
|
|
|
loopStartSample = loopEndSample = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is no correct endsample, try to guess it
|
|
|
|
if (endSample < 0)
|
|
|
|
endSample = (first.filesize / atracBytesPerFrame) * ATRAC_MAX_SAMPLES;
|
2013-02-04 00:54:52 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 17:10:13 +00:00
|
|
|
u32 sceAtracGetAtracID(int codecType)
|
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracGetAtracID(%i)", codecType);
|
|
|
|
if (codecType < 0x1000 || codecType > 0x1001)
|
2013-05-12 09:00:21 +00:00
|
|
|
return ATRAC_ERROR_INVALID_CODECTYPE;
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
int atracID = createAtrac(new Atrac);
|
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac)
|
|
|
|
return ATRAC_ERROR_NO_ATRACID;
|
|
|
|
atrac->codeType = codecType;
|
|
|
|
return atracID;
|
2013-01-05 17:10:13 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
|
2013-05-12 13:14:41 +00:00
|
|
|
// PSP allow games to add stream data to a temp buf, the buf size is given by "atracBufSize "here.
|
|
|
|
// "first.offset" means how many bytes the temp buf has been written,
|
|
|
|
// and "first.writableBytes" means how many bytes the temp buf is allowed to write
|
|
|
|
// (We always have "first.offset + first.writableBytes = atracBufSize").
|
|
|
|
// We only reset the temp buf when games call sceAtracGetStreamDataInfo,
|
|
|
|
// because that function would tell games how to add the left stream data.
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracAddStreamData(int atracID, u32 bytesToAdd)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracAddStreamData(%i, %08x)", atracID, bytesToAdd);
|
2013-01-05 17:10:13 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-05-04 08:00:00 +00:00
|
|
|
return 0;
|
2013-05-12 09:00:21 +00:00
|
|
|
} else {
|
|
|
|
// TODO
|
|
|
|
if (bytesToAdd > atrac->first.writableBytes)
|
|
|
|
return ATRAC_ERROR_ADD_DATA_IS_TOO_BIG;
|
2013-05-04 08:00:00 +00:00
|
|
|
|
2013-05-12 09:00:21 +00:00
|
|
|
if (atrac->data_buf && (bytesToAdd > 0)) {
|
|
|
|
int addbytes = std::min(bytesToAdd, atrac->first.filesize - atrac->first.fileoffset);
|
2013-05-12 12:04:50 +00:00
|
|
|
Memory::Memcpy(atrac->data_buf + atrac->first.fileoffset, atrac->first.addr + atrac->first.offset, addbytes);
|
2013-05-12 09:00:21 +00:00
|
|
|
}
|
|
|
|
atrac->first.size += bytesToAdd;
|
|
|
|
if (atrac->first.size > atrac->first.filesize)
|
|
|
|
atrac->first.size = atrac->first.filesize;
|
|
|
|
atrac->first.fileoffset = atrac->first.size;
|
2013-05-12 12:04:50 +00:00
|
|
|
atrac->first.writableBytes -= bytesToAdd;
|
|
|
|
atrac->first.offset += bytesToAdd;
|
2013-05-04 08:00:00 +00:00
|
|
|
}
|
2012-11-27 12:05:51 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishFlagAddr, u32 remainAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracDecodeData(%i, %08x, %08x, %08x, %08x)", atracID, outAddr, numSamplesAddr, finishFlagAddr, remainAddr);
|
2013-02-01 16:40:36 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
|
2013-02-02 05:16:59 +00:00
|
|
|
u32 ret = 0;
|
2013-02-01 16:40:36 +00:00
|
|
|
if (atrac != NULL) {
|
2013-02-02 05:16:59 +00:00
|
|
|
// We already passed the end - return an error (many games check for this.)
|
2013-05-04 08:00:00 +00:00
|
|
|
if (atrac->currentSample >= atrac->endSample && atrac->loopNum == 0) {
|
2013-02-02 05:16:59 +00:00
|
|
|
Memory::Write_U32(0, numSamplesAddr);
|
|
|
|
Memory::Write_U32(1, finishFlagAddr);
|
|
|
|
Memory::Write_U32(0, remainAddr);
|
|
|
|
ret = ATRAC_ERROR_ALL_DATA_DECODED;
|
|
|
|
} else {
|
|
|
|
// TODO: This isn't at all right, but at least it makes the music "last" some time.
|
2013-05-04 08:00:00 +00:00
|
|
|
u32 numSamples = 0;
|
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
if (atrac->codeType == PSP_MODE_AT_3 && atrac->pCodecCtx) {
|
|
|
|
int forceseekSample = atrac->currentSample * 2 > atrac->endSample ? 0 : atrac->endSample;
|
|
|
|
atrac->SeekToSample(forceseekSample);
|
|
|
|
atrac->SeekToSample(atrac->currentSample);
|
|
|
|
AVPacket packet;
|
|
|
|
int got_frame, ret;
|
|
|
|
while (av_read_frame(atrac->pFormatCtx, &packet) >= 0) {
|
|
|
|
if (packet.stream_index == atrac->audio_stream_index) {
|
|
|
|
got_frame = 0;
|
|
|
|
ret = avcodec_decode_audio4(atrac->pCodecCtx, atrac->pFrame, &got_frame, &packet);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR_LOG(HLE, "avcodec_decode_audio4: Error decoding audio %d", ret);
|
|
|
|
av_free_packet(&packet);
|
|
|
|
break;
|
|
|
|
}
|
2013-02-02 05:16:59 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
if (got_frame) {
|
|
|
|
// got a frame
|
|
|
|
int decoded = av_samples_get_buffer_size(NULL, atrac->pFrame->channels,
|
|
|
|
atrac->pFrame->nb_samples, (AVSampleFormat)atrac->pFrame->format, 1);
|
|
|
|
u8* out = Memory::GetPointer(outAddr);
|
|
|
|
numSamples = atrac->pFrame->nb_samples;
|
|
|
|
ret = swr_convert(atrac->pSwrCtx, &out, atrac->pFrame->nb_samples,
|
|
|
|
(const u8**)atrac->pFrame->extended_data, atrac->pFrame->nb_samples);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR_LOG(HLE, "swr_convert: Error while converting %d", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
av_free_packet(&packet);
|
|
|
|
if (got_frame)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else
|
|
|
|
#endif // USE_FFMPEG
|
|
|
|
{
|
|
|
|
numSamples = atrac->endSample - atrac->currentSample;
|
|
|
|
if (atrac->currentSample >= atrac->endSample) {
|
|
|
|
numSamples = 0;
|
|
|
|
} else if (numSamples > ATRAC_MAX_SAMPLES) {
|
|
|
|
numSamples = ATRAC_MAX_SAMPLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numSamples == 0 && (atrac->loopNum != 0)) {
|
|
|
|
numSamples = ATRAC_MAX_SAMPLES;
|
|
|
|
}
|
|
|
|
Memory::Memset(outAddr, 0, numSamples * sizeof(s16) * atrac->atracOutputChannels);
|
2013-02-02 05:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Memory::Write_U32(numSamples, numSamplesAddr);
|
2013-05-04 08:00:00 +00:00
|
|
|
// update current sample and decodePos
|
|
|
|
atrac->currentSample += numSamples;
|
|
|
|
atrac->decodePos = atrac->getDecodePosBySample(atrac->currentSample);
|
|
|
|
|
|
|
|
int finishFlag = 0;
|
2013-05-16 17:17:58 +00:00
|
|
|
if (atrac->loopNum != 0 && (atrac->currentSample >= atrac->loopEndSample ||
|
|
|
|
(numSamples == 0 && atrac->first.size >= atrac->first.filesize))) {
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->currentSample = atrac->loopStartSample;
|
|
|
|
if (atrac->loopNum > 0)
|
|
|
|
atrac->loopNum --;
|
2013-05-16 17:17:58 +00:00
|
|
|
} else if (atrac->currentSample >= atrac->endSample ||
|
|
|
|
(numSamples == 0 && atrac->first.size >= atrac->first.filesize))
|
2013-05-04 08:00:00 +00:00
|
|
|
finishFlag = 1;
|
2013-02-02 05:16:59 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
Memory::Write_U32(finishFlag, finishFlagAddr);
|
|
|
|
int remains = atrac->getRemainFrames();
|
|
|
|
Memory::Write_U32(remains, remainAddr);
|
2013-02-02 05:16:59 +00:00
|
|
|
}
|
|
|
|
// TODO: Can probably remove this after we validate no wrong ids?
|
|
|
|
} else {
|
|
|
|
Memory::Write_U16(0, outAddr); // Write a single 16-bit stereo
|
|
|
|
Memory::Write_U16(0, outAddr + 2);
|
|
|
|
|
|
|
|
Memory::Write_U32(1, numSamplesAddr);
|
|
|
|
Memory::Write_U32(1, finishFlagAddr); // Lie that decoding is finished
|
|
|
|
Memory::Write_U32(-1, remainAddr); // Lie that decoding is finished
|
2013-02-01 16:40:36 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 05:16:59 +00:00
|
|
|
return ret;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracEndEntry()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-12 09:00:21 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracEndEntry()");
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetBufferInfoForReseting(int atracID, int sample, u32 bufferInfoAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracGetBufferInfoForReseting(%i, %i, %08x)",atracID, sample, bufferInfoAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-02-01 16:59:23 +00:00
|
|
|
// TODO: Write the right stuff instead.
|
|
|
|
Memory::Memset(bufferInfoAddr, 0, 32);
|
2013-01-07 02:04:10 +00:00
|
|
|
//return -1;
|
2013-02-01 16:59:23 +00:00
|
|
|
} else {
|
2013-05-04 08:00:00 +00:00
|
|
|
int Sampleoffset = atrac->getDecodePosBySample(sample);
|
2013-02-02 10:36:24 +00:00
|
|
|
Memory::Write_U32(atrac->first.addr, bufferInfoAddr);
|
|
|
|
Memory::Write_U32(atrac->first.writableBytes, bufferInfoAddr + 4);
|
|
|
|
Memory::Write_U32(atrac->first.neededBytes, bufferInfoAddr + 8);
|
2013-05-04 08:00:00 +00:00
|
|
|
Memory::Write_U32(Sampleoffset, bufferInfoAddr + 12);
|
2013-02-02 10:36:24 +00:00
|
|
|
Memory::Write_U32(atrac->second.addr, bufferInfoAddr + 16);
|
|
|
|
Memory::Write_U32(atrac->second.writableBytes, bufferInfoAddr + 20);
|
|
|
|
Memory::Write_U32(atrac->second.neededBytes, bufferInfoAddr + 24);
|
|
|
|
Memory::Write_U32(atrac->second.fileoffset, bufferInfoAddr + 28);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetBitrate(int atracID, u32 outBitrateAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetBitrate(%i, %08x)", atracID, outBitrateAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-05-04 08:00:00 +00:00
|
|
|
return -1;
|
2013-05-12 09:00:21 +00:00
|
|
|
} else {
|
|
|
|
atrac->atracBitrate = ( atrac->atracBytesPerFrame * 352800 ) / 1000;
|
|
|
|
if (atrac->codeType == PSP_MODE_AT_3_PLUS)
|
|
|
|
atrac->atracBitrate = ((atrac->atracBitrate >> 11) + 8) & 0xFFFFFFF0;
|
|
|
|
else
|
|
|
|
atrac->atracBitrate = (atrac->atracBitrate + 511) >> 10;
|
|
|
|
if (Memory::IsValidAddress(outBitrateAddr))
|
|
|
|
Memory::Write_U32(atrac->atracBitrate, outBitrateAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-11-27 12:05:51 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetChannel(int atracID, u32 channelAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetChannel(%i, %08x)", atracID, channelAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-04-29 18:01:17 +00:00
|
|
|
return -1;
|
2013-05-12 09:00:21 +00:00
|
|
|
} else {
|
|
|
|
if (Memory::IsValidAddress(channelAddr))
|
|
|
|
Memory::Write_U32(atrac->atracChannels, channelAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 18:34:13 +00:00
|
|
|
u32 sceAtracGetLoopStatus(int atracID, u32 loopNumAddr, u32 statusAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetLoopStatus(%i, %08x, %08x)", atracID, loopNumAddr, statusAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-02-03 18:34:13 +00:00
|
|
|
} else {
|
|
|
|
if (Memory::IsValidAddress(loopNumAddr))
|
|
|
|
Memory::Write_U32(atrac->loopNum, loopNumAddr);
|
2013-05-04 08:00:00 +00:00
|
|
|
// return audio's loopinfo in at3 file
|
2013-04-12 16:49:22 +00:00
|
|
|
if (Memory::IsValidAddress(statusAddr)) {
|
|
|
|
if (atrac->loopinfoNum > 0)
|
|
|
|
Memory::Write_U32(1, statusAddr);
|
|
|
|
else
|
|
|
|
Memory::Write_U32(0, statusAddr);
|
|
|
|
}
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetInternalErrorInfo(int atracID, u32 errorAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracGetInternalErrorInfo(%i, %08x)", atracID, errorAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-05-12 09:00:21 +00:00
|
|
|
} else {
|
|
|
|
if (Memory::IsValidAddress(errorAddr))
|
|
|
|
Memory::Write_U32(0, errorAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetMaxSample(int atracID, u32 maxSamplesAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetMaxSample(%i, %08x)", atracID, maxSamplesAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-05-12 09:00:21 +00:00
|
|
|
} else {
|
|
|
|
if (Memory::IsValidAddress(maxSamplesAddr))
|
|
|
|
Memory::Write_U32(ATRAC_MAX_SAMPLES, maxSamplesAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetNextDecodePosition(int atracID, u32 outposAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetNextDecodePosition(%i, %08x)", atracID, outposAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-05-04 08:00:00 +00:00
|
|
|
return -1;
|
2013-05-12 09:00:21 +00:00
|
|
|
} else {
|
|
|
|
if (atrac->currentSample >= atrac->endSample)
|
|
|
|
return ATRAC_ERROR_ALL_DATA_DECODED;
|
|
|
|
if (Memory::IsValidAddress(outposAddr))
|
|
|
|
Memory::Write_U32(atrac->currentSample, outposAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetNextSample(int atracID, u32 outNAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetNextSample(%i, %08x)", atracID, outNAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-02-02 05:16:59 +00:00
|
|
|
Memory::Write_U32(1, outNAddr);
|
|
|
|
} else {
|
2013-04-12 16:49:22 +00:00
|
|
|
if (atrac->currentSample >= atrac->endSample) {
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(outNAddr))
|
|
|
|
Memory::Write_U32(0, outNAddr);
|
2013-02-02 05:16:59 +00:00
|
|
|
} else {
|
2013-04-12 16:49:22 +00:00
|
|
|
u32 numSamples = atrac->endSample - atrac->currentSample;
|
2013-02-03 18:37:47 +00:00
|
|
|
if (numSamples > ATRAC_MAX_SAMPLES)
|
|
|
|
numSamples = ATRAC_MAX_SAMPLES;
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(outNAddr))
|
|
|
|
Memory::Write_U32(numSamples, outNAddr);
|
2013-02-02 05:16:59 +00:00
|
|
|
}
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-11-27 12:05:51 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 05:16:59 +00:00
|
|
|
u32 sceAtracGetRemainFrame(int atracID, u32 remainAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetRemainFrame(%i, %08x)", atracID, remainAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(remainAddr))
|
|
|
|
Memory::Write_U32(12, remainAddr);
|
2013-02-02 05:16:59 +00:00
|
|
|
} else {
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(remainAddr))
|
|
|
|
Memory::Write_U32(atrac->getRemainFrames(), remainAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-11-27 12:05:51 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetSecondBufferInfo(int atracID, u32 outposAddr, u32 outBytesAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "sceAtracGetSecondBufferInfo(%i, %08x, %08x)", atracID, outposAddr, outBytesAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-05-04 08:00:00 +00:00
|
|
|
//return -1;
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(outposAddr))
|
2013-05-13 13:15:02 +00:00
|
|
|
Memory::Write_U32(atrac->second.fileoffset, outposAddr);
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(outBytesAddr))
|
2013-05-13 13:15:02 +00:00
|
|
|
Memory::Write_U32(atrac->second.writableBytes, outBytesAddr);
|
2013-05-04 08:00:00 +00:00
|
|
|
// TODO: Maybe don't write the above?
|
2013-04-28 19:43:17 +00:00
|
|
|
return ATRAC_ERROR_SECOND_BUFFER_NOT_NEEDED;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracGetSoundSample(int atracID, u32 outEndSampleAddr, u32 outLoopStartSampleAddr, u32 outLoopEndSampleAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetSoundSample(%i, %08x, %08x, %08x)", atracID, outEndSampleAddr, outLoopStartSampleAddr, outLoopEndSampleAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-05-12 09:00:21 +00:00
|
|
|
} else {
|
|
|
|
if (Memory::IsValidAddress(outEndSampleAddr))
|
|
|
|
Memory::Write_U32(atrac->endSample, outEndSampleAddr); // outEndSample
|
|
|
|
if (Memory::IsValidAddress(outLoopStartSampleAddr))
|
|
|
|
Memory::Write_U32(atrac->loopStartSample, outLoopStartSampleAddr); // outLoopStartSample
|
|
|
|
if (Memory::IsValidAddress(outLoopEndSampleAddr))
|
|
|
|
Memory::Write_U32(atrac->loopEndSample, outLoopEndSampleAddr); // outLoopEndSample
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-11-27 12:05:51 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 13:14:41 +00:00
|
|
|
// Games call this function to get some info for add more stream data,
|
|
|
|
// such as where the data read from, where the data add to,
|
|
|
|
// and how many bytes are allowed to add.
|
2013-02-02 10:36:24 +00:00
|
|
|
u32 sceAtracGetStreamDataInfo(int atracID, u32 writeAddr, u32 writableBytesAddr, u32 readOffsetAddr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetStreamDataInfo(%i, %08x, %08x, %08x)", atracID, writeAddr, writableBytesAddr, readOffsetAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-02-24 18:23:31 +00:00
|
|
|
} else {
|
2013-05-12 13:14:41 +00:00
|
|
|
// reset the temp buf for adding more stream data
|
2013-05-10 11:56:53 +00:00
|
|
|
atrac->first.writableBytes = std::min(atrac->first.filesize - atrac->first.size, atrac->atracBufSize);
|
2013-05-12 12:04:50 +00:00
|
|
|
atrac->first.offset = 0;
|
2013-05-12 13:14:41 +00:00
|
|
|
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(writeAddr))
|
2013-02-24 18:23:31 +00:00
|
|
|
Memory::Write_U32(atrac->first.addr, writeAddr);
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(writableBytesAddr))
|
2013-02-24 18:23:31 +00:00
|
|
|
Memory::Write_U32(atrac->first.writableBytes, writableBytesAddr);
|
2013-05-12 09:00:21 +00:00
|
|
|
if (Memory::IsValidAddress(readOffsetAddr))
|
2013-02-24 18:23:31 +00:00
|
|
|
Memory::Write_U32(atrac->first.fileoffset, readOffsetAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-11-27 12:05:51 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracReleaseAtracID(int atracID)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracReleaseAtracID(%i)", atracID);
|
2013-02-01 16:31:51 +00:00
|
|
|
deleteAtrac(atracID);
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracResetPlayPosition(int atracID, int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracResetPlayPosition(%i, %i, %i, %i)", atracID, sample, bytesWrittenFirstBuf, bytesWrittenSecondBuf);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-02-02 07:16:18 +00:00
|
|
|
} else {
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->currentSample = sample;
|
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
if (atrac->codeType == PSP_MODE_AT_3 && atrac->pCodecCtx) {
|
|
|
|
atrac->SeekToSample(sample);
|
|
|
|
} else
|
|
|
|
#endif // USE_FFMPEG
|
|
|
|
{
|
|
|
|
atrac->decodePos = atrac->getDecodePosBySample(sample);
|
|
|
|
}
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
int _AtracReadbuffer(void *opaque, uint8_t *buf, int buf_size)
|
|
|
|
{
|
|
|
|
Atrac *atrac = (Atrac*)opaque;
|
|
|
|
int size = std::min((int)atrac->atracBufSize, buf_size);
|
|
|
|
size = std::max(std::min(((int)atrac->first.size - (int)atrac->decodePos), size), 0);
|
|
|
|
if (size > 0)
|
|
|
|
memcpy(buf, atrac->data_buf + atrac->decodePos, size);
|
|
|
|
atrac->decodePos += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t _AtracSeekbuffer(void *opaque, int64_t offset, int whence)
|
|
|
|
{
|
|
|
|
Atrac *atrac = (Atrac*)opaque;
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
|
|
|
atrac->decodePos = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
atrac->decodePos += offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
atrac->decodePos = atrac->first.filesize - offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_FFMPEG
|
|
|
|
|
2013-05-04 16:28:11 +00:00
|
|
|
int __AtracSetContext(Atrac *atrac, u32 buffer, u32 bufferSize)
|
|
|
|
{
|
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
u8* tempbuf = (u8*)av_malloc(atrac->atracBufSize);
|
|
|
|
|
|
|
|
atrac->pFormatCtx = avformat_alloc_context();
|
|
|
|
atrac->pAVIOCtx = avio_alloc_context(tempbuf, atrac->atracBufSize, 0, (void*)atrac, _AtracReadbuffer, NULL, _AtracSeekbuffer);
|
|
|
|
atrac->pFormatCtx->pb = atrac->pAVIOCtx;
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
// Load audio buffer
|
|
|
|
if((ret = avformat_open_input((AVFormatContext**)&atrac->pFormatCtx, NULL, NULL, NULL)) != 0) {
|
|
|
|
ERROR_LOG(HLE, "avformat_open_input: Cannot open input %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ret = avformat_find_stream_info(atrac->pFormatCtx, NULL)) < 0) {
|
|
|
|
ERROR_LOG(HLE, "avformat_find_stream_info: Cannot find stream information %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AVCodec *pCodec;
|
|
|
|
// select the audio stream
|
|
|
|
ret = av_find_best_stream(atrac->pFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, &pCodec, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR_LOG(HLE, "av_find_best_stream: Cannot find a audio stream in the input file %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
atrac->audio_stream_index = ret;
|
|
|
|
atrac->pCodecCtx = atrac->pFormatCtx->streams[atrac->audio_stream_index]->codec;
|
|
|
|
|
|
|
|
// open codec
|
|
|
|
if ((ret = avcodec_open2(atrac->pCodecCtx, pCodec, NULL)) < 0) {
|
|
|
|
ERROR_LOG(HLE, "avcodec_open2: Cannot open audio decoder %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wanted_channels = atrac->atracOutputChannels;
|
2013-05-13 08:20:04 +00:00
|
|
|
int64_t wanted_channel_layout = av_get_default_channel_layout(wanted_channels);
|
|
|
|
int64_t dec_channel_layout = av_get_default_channel_layout(atrac->atracChannels);
|
2013-05-04 16:28:11 +00:00
|
|
|
|
|
|
|
atrac->pSwrCtx =
|
|
|
|
swr_alloc_set_opts
|
|
|
|
(
|
|
|
|
NULL,
|
|
|
|
wanted_channel_layout,
|
|
|
|
AV_SAMPLE_FMT_S16,
|
|
|
|
atrac->pCodecCtx->sample_rate,
|
|
|
|
dec_channel_layout,
|
|
|
|
atrac->pCodecCtx->sample_fmt,
|
|
|
|
atrac->pCodecCtx->sample_rate,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (!atrac->pSwrCtx) {
|
|
|
|
ERROR_LOG(HLE, "swr_alloc_set_opts: Could not allocate resampler context %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((ret = swr_init(atrac->pSwrCtx)) < 0) {
|
|
|
|
ERROR_LOG(HLE, "swr_init: Failed to initialize the resampling context %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// alloc audio frame
|
|
|
|
atrac->pFrame = avcodec_alloc_frame();
|
2013-05-16 17:15:23 +00:00
|
|
|
// reinit decodePos, because ffmpeg had changed it.
|
|
|
|
atrac->decodePos = 0;
|
2013-05-04 16:28:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
int _AtracSetData(Atrac *atrac, u32 buffer, u32 bufferSize)
|
|
|
|
{
|
|
|
|
if (atrac->first.size > atrac->first.filesize)
|
|
|
|
atrac->first.size = atrac->first.filesize;
|
|
|
|
atrac->first.fileoffset = atrac->first.size;
|
2013-05-12 13:14:41 +00:00
|
|
|
|
|
|
|
// got the size of temp buf, and calculate writableBytes and offset
|
|
|
|
atrac->atracBufSize = bufferSize;
|
2013-05-12 12:04:50 +00:00
|
|
|
atrac->first.writableBytes = (u32)std::max((int)bufferSize - (int)atrac->first.size, 0);
|
|
|
|
atrac->first.offset = atrac->first.size;
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
#ifdef USE_FFMPEG
|
|
|
|
if (atrac->codeType == PSP_MODE_AT_3) {
|
2013-05-10 15:47:05 +00:00
|
|
|
WARN_LOG(HLE, "This is an atrac3 audio");
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
// some games may reuse an atracID for playing sound
|
|
|
|
atrac->ReleaseFFMPEGContext();
|
|
|
|
|
|
|
|
if (atrac->data_buf)
|
|
|
|
delete [] atrac->data_buf;
|
|
|
|
|
|
|
|
atrac->data_buf = new u8[atrac->first.filesize];
|
|
|
|
Memory::Memcpy(atrac->data_buf, buffer, std::min(bufferSize, atrac->first.filesize));
|
|
|
|
|
2013-05-04 16:28:11 +00:00
|
|
|
return __AtracSetContext(atrac, buffer, bufferSize);
|
2013-05-10 15:42:10 +00:00
|
|
|
} else if (atrac->codeType == PSP_MODE_AT_3_PLUS)
|
2013-05-10 15:47:05 +00:00
|
|
|
WARN_LOG(HLE, "This is an atrac3+ audio");
|
2013-05-12 09:00:21 +00:00
|
|
|
#endif // USE_FFMPEG
|
2013-05-04 08:00:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int _AtracSetData(int atracID, u32 buffer, u32 bufferSize)
|
|
|
|
{
|
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac)
|
|
|
|
return -1;
|
|
|
|
return _AtracSetData(atrac, buffer, bufferSize);
|
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracSetHalfwayBuffer(int atracID, u32 halfBuffer, u32 readSize, u32 halfBufferSize)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracSetHalfwayBuffer(%i, %08x, %8x, %8x)", atracID, halfBuffer, readSize, halfBufferSize);
|
2013-04-13 16:24:55 +00:00
|
|
|
if (readSize > halfBufferSize)
|
|
|
|
return ATRAC_ERROR_INCORRECT_READ_SIZE;
|
|
|
|
|
|
|
|
Atrac *atrac = getAtrac(atracID);
|
2013-05-04 08:00:00 +00:00
|
|
|
int ret = 0;
|
|
|
|
if (atrac != NULL) {
|
2013-04-13 16:24:55 +00:00
|
|
|
atrac->first.addr = halfBuffer;
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->first.size = readSize;
|
2013-04-13 16:24:55 +00:00
|
|
|
atrac->Analyze();
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->atracOutputChannels = 2;
|
|
|
|
ret = _AtracSetData(atracID, halfBuffer, halfBufferSize);
|
2013-04-13 16:24:55 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
return ret;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracSetSecondBuffer(int atracID, u32 secondBuffer, u32 secondBufferSize)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-12-23 05:23:17 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracSetSecondBuffer(%i, %08x, %8x)", atracID, secondBuffer, secondBufferSize);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracSetData(int atracID, u32 buffer, u32 bufferSize)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracSetData(%i, %08x, %08x)", atracID, buffer, bufferSize);
|
2013-02-01 16:59:23 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
2013-05-04 08:00:00 +00:00
|
|
|
int ret = 0;
|
2013-02-01 16:59:23 +00:00
|
|
|
if (atrac != NULL) {
|
2013-02-02 10:36:24 +00:00
|
|
|
atrac->first.addr = buffer;
|
|
|
|
atrac->first.size = bufferSize;
|
2013-02-04 00:54:52 +00:00
|
|
|
atrac->Analyze();
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->atracOutputChannels = 2;
|
|
|
|
ret = _AtracSetData(atracID, buffer, bufferSize);
|
2013-02-01 16:59:23 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
return ret;
|
2012-12-23 05:23:17 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
int sceAtracSetDataAndGetID(u32 buffer, u32 bufferSize)
|
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracSetDataAndGetID(%08x, %08x)", buffer, bufferSize);
|
2013-01-06 03:42:28 +00:00
|
|
|
int codecType = getCodecType(buffer);
|
2013-02-01 16:59:23 +00:00
|
|
|
|
|
|
|
Atrac *atrac = new Atrac();
|
2013-02-02 10:36:24 +00:00
|
|
|
atrac->first.addr = buffer;
|
|
|
|
atrac->first.size = bufferSize;
|
2013-02-04 00:54:52 +00:00
|
|
|
atrac->Analyze();
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->atracOutputChannels = 2;
|
|
|
|
int atracID = createAtrac(atrac);
|
|
|
|
int ret = _AtracSetData(atracID, buffer, bufferSize);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return atracID;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 15:22:01 +00:00
|
|
|
int sceAtracSetHalfwayBufferAndGetID(u32 halfBuffer, u32 readSize, u32 halfBufferSize)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracSetHalfwayBufferAndGetID(%08x, %08x, %08x)", halfBuffer, readSize, halfBufferSize);
|
2013-04-12 01:54:10 +00:00
|
|
|
if (readSize > halfBufferSize)
|
|
|
|
return ATRAC_ERROR_INCORRECT_READ_SIZE;
|
2013-04-12 16:49:22 +00:00
|
|
|
int codecType = getCodecType(halfBuffer);
|
2013-05-04 08:00:00 +00:00
|
|
|
|
2013-02-01 16:59:23 +00:00
|
|
|
Atrac *atrac = new Atrac();
|
2013-02-02 10:36:24 +00:00
|
|
|
atrac->first.addr = halfBuffer;
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->first.size = readSize;
|
2013-02-04 00:54:52 +00:00
|
|
|
atrac->Analyze();
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->atracOutputChannels = 2;
|
|
|
|
int atracID = createAtrac(atrac);
|
|
|
|
int ret = _AtracSetData(atracID, halfBuffer, halfBufferSize);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return atracID;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracStartEntry()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracStartEntry(.)");
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 05:23:17 +00:00
|
|
|
u32 sceAtracSetLoopNum(int atracID, int loopNum)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracSetLoopNum(%i, %i)", atracID, loopNum);
|
2013-02-02 05:16:59 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (atrac) {
|
2013-05-04 08:00:00 +00:00
|
|
|
if (atrac->loopinfoNum == 0)
|
|
|
|
return ATRAC_ERROR_UNSET_PARAM;
|
2013-02-02 05:16:59 +00:00
|
|
|
atrac->loopNum = loopNum;
|
2013-04-12 16:49:22 +00:00
|
|
|
if (loopNum != 0 && atrac->loopinfoNum == 0) {
|
2013-05-04 08:00:00 +00:00
|
|
|
// Just loop the whole audio
|
2013-04-12 16:49:22 +00:00
|
|
|
atrac->loopStartSample = 0;
|
|
|
|
atrac->loopEndSample = atrac->endSample;
|
|
|
|
}
|
2013-02-02 05:16:59 +00:00
|
|
|
}
|
2012-12-23 05:23:17 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-10 01:56:21 +00:00
|
|
|
int sceAtracReinit()
|
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracReinit(..)");
|
2012-12-10 01:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-26 21:36:10 +00:00
|
|
|
int sceAtracGetOutputChannel(int atracID, u32 outputChanPtr)
|
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "sceAtracGetOutputChannel(%i, %08x)", atracID, outputChanPtr);
|
2013-04-12 16:49:22 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
2012-12-26 21:36:10 +00:00
|
|
|
if (Memory::IsValidAddress(outputChanPtr))
|
2013-05-04 08:00:00 +00:00
|
|
|
Memory::Write_U32(atrac ? atrac->atracOutputChannels : 2, outputChanPtr);
|
2012-12-26 21:36:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceAtracIsSecondBufferNeeded(int atracID)
|
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracIsSecondBufferNeeded(%i)", atracID);
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-01-06 15:27:50 +00:00
|
|
|
//return -1;
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
int sceAtracSetMOutHalfwayBuffer(int atracID, u32 MOutHalfBuffer, u32 readSize, u32 MOutHalfBufferSize)
|
2013-01-06 03:42:28 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracSetMOutHalfwayBuffer(%i, %08x, %08x, %08x)", atracID, MOutHalfBuffer, readSize, MOutHalfBufferSize);
|
2013-04-16 06:03:24 +00:00
|
|
|
if (readSize > MOutHalfBufferSize)
|
|
|
|
return ATRAC_ERROR_INCORRECT_READ_SIZE;
|
2013-05-04 08:00:00 +00:00
|
|
|
|
2013-01-06 03:42:28 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
2013-05-04 08:00:00 +00:00
|
|
|
int ret = 0;
|
|
|
|
if (atrac != NULL) {
|
|
|
|
atrac->first.addr = MOutHalfBuffer;
|
|
|
|
atrac->first.size = readSize;
|
|
|
|
atrac->Analyze();
|
|
|
|
atrac->atracOutputChannels = 1;
|
|
|
|
ret = _AtracSetData(atracID, MOutHalfBuffer, MOutHalfBufferSize);
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
2013-05-04 08:00:00 +00:00
|
|
|
return ret;
|
2013-01-06 03:42:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
u32 sceAtracSetMOutData(int atracID, u32 buffer, u32 bufferSize)
|
2013-04-16 06:03:24 +00:00
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
INFO_LOG(HLE, "sceAtracSetMOutData(%i, %08x, %08x)", atracID, buffer, bufferSize);
|
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
int ret = 0;
|
|
|
|
if (atrac != NULL) {
|
|
|
|
atrac->first.addr = buffer;
|
|
|
|
atrac->first.size = bufferSize;
|
|
|
|
atrac->Analyze();
|
|
|
|
atrac->atracOutputChannels = 1;
|
|
|
|
ret = _AtracSetData(atracID, buffer, bufferSize);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2013-04-16 06:03:24 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
int sceAtracSetMOutDataAndGetID(u32 buffer, u32 bufferSize)
|
|
|
|
{
|
|
|
|
INFO_LOG(HLE, "sceAtracSetMOutDataAndGetID(%08x, %08x)", buffer, bufferSize);
|
|
|
|
int codecType = getCodecType(buffer);
|
2013-04-16 06:03:24 +00:00
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
Atrac *atrac = new Atrac();
|
|
|
|
atrac->first.addr = buffer;
|
|
|
|
atrac->first.size = bufferSize;
|
|
|
|
atrac->Analyze();
|
|
|
|
atrac->atracOutputChannels = 1;
|
|
|
|
int atracID = createAtrac(atrac);
|
|
|
|
int ret = _AtracSetData(atracID, buffer, bufferSize);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return atracID;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceAtracSetMOutHalfwayBufferAndGetID(u32 halfBuffer, u32 readSize, u32 halfBufferSize)
|
|
|
|
{
|
|
|
|
INFO_LOG(HLE, "sceAtracSetMOutHalfwayBufferAndGetID(%08x, %08x, %08x)", halfBuffer, readSize, halfBufferSize);
|
|
|
|
if (readSize > halfBufferSize)
|
|
|
|
return ATRAC_ERROR_INCORRECT_READ_SIZE;
|
2013-04-16 06:03:24 +00:00
|
|
|
int codecType = getCodecType(halfBuffer);
|
2013-05-04 08:00:00 +00:00
|
|
|
|
2013-04-16 06:03:24 +00:00
|
|
|
Atrac *atrac = new Atrac();
|
|
|
|
atrac->first.addr = halfBuffer;
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->first.size = readSize;
|
2013-04-16 06:03:24 +00:00
|
|
|
atrac->Analyze();
|
2013-05-04 08:00:00 +00:00
|
|
|
atrac->atracOutputChannels = 1;
|
|
|
|
int atracID = createAtrac(atrac);
|
|
|
|
int ret = _AtracSetData(atracID, halfBuffer, halfBufferSize);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return atracID;
|
2013-04-16 06:03:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 03:42:28 +00:00
|
|
|
int sceAtracSetAA3DataAndGetID(u32 buffer, int bufferSize, int fileSize, u32 metadataSizeAddr)
|
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracSetAA3DataAndGetID(%08x, %i, %i, %08x)", buffer, bufferSize, fileSize, metadataSizeAddr);
|
2013-01-06 03:42:28 +00:00
|
|
|
int codecType = getCodecType(buffer);
|
2013-02-01 16:59:23 +00:00
|
|
|
|
|
|
|
Atrac *atrac = new Atrac();
|
2013-02-02 10:36:24 +00:00
|
|
|
atrac->first.addr = buffer;
|
|
|
|
atrac->first.size = bufferSize;
|
2013-02-04 00:54:52 +00:00
|
|
|
atrac->Analyze();
|
2013-02-01 16:59:23 +00:00
|
|
|
return createAtrac(atrac);
|
2012-12-26 21:36:10 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-03 00:07:43 +00:00
|
|
|
int _sceAtracGetContextAddress(int atracID)
|
|
|
|
{
|
2013-02-03 08:48:27 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL _sceAtracGetContextAddress(%i)", atracID);
|
2013-02-03 00:07:43 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (!atrac) {
|
2013-05-12 09:00:21 +00:00
|
|
|
// Sol Trigger requires return -1 otherwise hangup .
|
|
|
|
return -1;
|
2013-02-03 00:07:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-03 18:53:38 +00:00
|
|
|
int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr)
|
|
|
|
{
|
2013-02-03 21:25:12 +00:00
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracLowLevelInitDecoder(%i, %08x)", atracID, paramsAddr);
|
2013-05-04 08:00:00 +00:00
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
if (atrac && Memory::IsValidAddress(paramsAddr)) {
|
|
|
|
atrac->atracChannels = Memory::Read_U32(paramsAddr);
|
|
|
|
atrac->atracOutputChannels = Memory::Read_U32(paramsAddr + 4);
|
|
|
|
atrac->atracBufSize = Memory::Read_U32(paramsAddr + 8);
|
|
|
|
}
|
2013-02-03 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceAtracLowLevelDecode(int atracID, u32 sourceAddr, u32 sourceBytesConsumedAddr, u32 samplesAddr, u32 sampleBytesAddr)
|
|
|
|
{
|
2013-05-04 08:00:00 +00:00
|
|
|
DEBUG_LOG(HLE, "UNIMPL sceAtracLowLevelDecode(%i, %08x, %08x, %08x, %08x)", atracID, sourceAddr, sourceBytesConsumedAddr, samplesAddr, sampleBytesAddr);
|
|
|
|
Atrac *atrac = getAtrac(atracID);
|
|
|
|
/*if (Memory::IsValidAddress(sourceBytesConsumedAddr))
|
|
|
|
Memory::Write_U32(0, sourceBytesConsumedAddr);
|
|
|
|
if (Memory::IsValidAddress(samplesAddr) && Memory::IsValidAddress(sampleBytesAddr)) {
|
|
|
|
Memory::Write_U32(ATRAC_MAX_SAMPLES, sampleBytesAddr);
|
|
|
|
int outputChannels = atrac ? atrac->atracOutputChannels : 2;
|
|
|
|
Memory::Memset(samplesAddr, 0, ATRAC_MAX_SAMPLES * sizeof(s16) * outputChannels);
|
|
|
|
}*/
|
|
|
|
Memory::Write_U32(0, sampleBytesAddr);
|
2013-02-03 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-04 08:00:00 +00:00
|
|
|
int sceAtracSetAA3HalfwayBufferAndGetID(u32 halfBuffer, u32 readSize, u32 halfBufferSize)
|
|
|
|
{
|
|
|
|
ERROR_LOG(HLE, "UNIMPL sceAtracSetAA3HalfwayBufferAndGetID(%08x, %08x, %08x)", halfBuffer, readSize, halfBufferSize);
|
|
|
|
if (readSize > halfBufferSize)
|
|
|
|
return ATRAC_ERROR_INCORRECT_READ_SIZE;
|
|
|
|
|
|
|
|
if (readSize < 0 || halfBufferSize < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int codecType = getCodecType(halfBuffer);
|
|
|
|
Atrac *atrac = new Atrac();
|
|
|
|
atrac->first.addr = halfBuffer;
|
|
|
|
atrac->first.size = halfBufferSize;
|
|
|
|
atrac->Analyze();
|
|
|
|
return createAtrac(atrac);
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
const HLEFunction sceAtrac3plus[] =
|
|
|
|
{
|
2012-12-23 05:23:17 +00:00
|
|
|
{0x7db31251,WrapU_IU<sceAtracAddStreamData>,"sceAtracAddStreamData"},
|
|
|
|
{0x6a8c3cd5,WrapU_IUUUU<sceAtracDecodeData>,"sceAtracDecodeData"},
|
|
|
|
{0xd5c28cc0,WrapU_V<sceAtracEndEntry>,"sceAtracEndEntry"},
|
|
|
|
{0x780f88d1,WrapU_I<sceAtracGetAtracID>,"sceAtracGetAtracID"},
|
|
|
|
{0xca3ca3d2,WrapU_IIU<sceAtracGetBufferInfoForReseting>,"sceAtracGetBufferInfoForReseting"},
|
|
|
|
{0xa554a158,WrapU_IU<sceAtracGetBitrate>,"sceAtracGetBitrate"},
|
|
|
|
{0x31668baa,WrapU_IU<sceAtracGetChannel>,"sceAtracGetChannel"},
|
|
|
|
{0xfaa4f89b,WrapU_IUU<sceAtracGetLoopStatus>,"sceAtracGetLoopStatus"},
|
|
|
|
{0xe88f759b,WrapU_IU<sceAtracGetInternalErrorInfo>,"sceAtracGetInternalErrorInfo"},
|
|
|
|
{0xd6a5f2f7,WrapU_IU<sceAtracGetMaxSample>,"sceAtracGetMaxSample"},
|
|
|
|
{0xe23e3a35,WrapU_IU<sceAtracGetNextDecodePosition>,"sceAtracGetNextDecodePosition"},
|
|
|
|
{0x36faabfb,WrapU_IU<sceAtracGetNextSample>,"sceAtracGetNextSample"},
|
|
|
|
{0x9ae849a7,WrapU_IU<sceAtracGetRemainFrame>,"sceAtracGetRemainFrame"},
|
|
|
|
{0x83e85ea0,WrapU_IUU<sceAtracGetSecondBufferInfo>,"sceAtracGetSecondBufferInfo"},
|
|
|
|
{0xa2bba8be,WrapU_IUUU<sceAtracGetSoundSample>,"sceAtracGetSoundSample"},
|
|
|
|
{0x5d268707,WrapU_IUUU<sceAtracGetStreamDataInfo>,"sceAtracGetStreamDataInfo"},
|
|
|
|
{0x61eb33f5,WrapU_I<sceAtracReleaseAtracID>,"sceAtracReleaseAtracID"},
|
|
|
|
{0x644e5607,WrapU_IIII<sceAtracResetPlayPosition>,"sceAtracResetPlayPosition"},
|
|
|
|
{0x3f6e26b5,WrapU_IUUU<sceAtracSetHalfwayBuffer>,"sceAtracSetHalfwayBuffer"},
|
|
|
|
{0x83bf7afd,WrapU_IUU<sceAtracSetSecondBuffer>,"sceAtracSetSecondBuffer"},
|
|
|
|
{0x0E2A73AB,WrapU_IUU<sceAtracSetData>,"sceAtracSetData"}, //?
|
|
|
|
{0x7a20e7af,WrapI_UU<sceAtracSetDataAndGetID>,"sceAtracSetDataAndGetID"},
|
|
|
|
{0xd1f59fdb,WrapU_V<sceAtracStartEntry>,"sceAtracStartEntry"},
|
|
|
|
{0x868120b5,WrapU_II<sceAtracSetLoopNum>,"sceAtracSetLoopNum"},
|
2012-12-10 01:56:21 +00:00
|
|
|
{0x132f1eca,WrapI_V<sceAtracReinit>,"sceAtracReinit"},
|
2012-12-26 21:36:10 +00:00
|
|
|
{0xeca32a99,WrapI_I<sceAtracIsSecondBufferNeeded>,"sceAtracIsSecondBufferNeeded"},
|
2013-04-09 15:22:01 +00:00
|
|
|
{0x0fae370e,WrapI_UUU<sceAtracSetHalfwayBufferAndGetID>,"sceAtracSetHalfwayBufferAndGetID"},
|
2013-01-05 17:10:13 +00:00
|
|
|
{0x2DD3E298,WrapU_IIU<sceAtracGetBufferInfoForReseting>,"sceAtracGetBufferInfoForResetting"},
|
2013-05-04 08:00:00 +00:00
|
|
|
{0x5CF9D852,WrapI_IUUU<sceAtracSetMOutHalfwayBuffer>,"sceAtracSetMOutHalfwayBuffer"},
|
|
|
|
{0xF6837A1A,WrapU_IUU<sceAtracSetMOutData>,"sceAtracSetMOutData"},
|
|
|
|
{0x472E3825,WrapI_UU<sceAtracSetMOutDataAndGetID>,"sceAtracSetMOutDataAndGetID"},
|
|
|
|
{0x9CD7DE03,WrapI_UUU<sceAtracSetMOutHalfwayBufferAndGetID>,"sceAtracSetMOutHalfwayBufferAndGetID"},
|
2012-12-26 21:36:10 +00:00
|
|
|
{0xB3B5D042,WrapI_IU<sceAtracGetOutputChannel>,"sceAtracGetOutputChannel"},
|
2013-01-06 03:42:28 +00:00
|
|
|
{0x5622B7C1,WrapI_UIIU<sceAtracSetAA3DataAndGetID>,"sceAtracSetAA3DataAndGetID"},
|
2013-04-16 06:03:24 +00:00
|
|
|
{0x5DD66588,WrapI_UUU<sceAtracSetAA3HalfwayBufferAndGetID>,"sceAtracSetAA3HalfwayBufferAndGetID"},
|
2013-02-03 00:07:43 +00:00
|
|
|
{0x231FC6B7,WrapI_I<_sceAtracGetContextAddress>,"_sceAtracGetContextAddress"},
|
2013-02-03 18:53:38 +00:00
|
|
|
{0x1575D64B,WrapI_IU<sceAtracLowLevelInitDecoder>,"sceAtracLowLevelInitDecoder"},
|
|
|
|
{0x0C116E1B,WrapI_IUUUU<sceAtracLowLevelDecode>,"sceAtracLowLevelDecode"},
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void Register_sceAtrac3plus()
|
|
|
|
{
|
|
|
|
// Two names
|
|
|
|
RegisterModule("sceATRAC3plus_Library", ARRAY_SIZE(sceAtrac3plus), sceAtrac3plus);
|
|
|
|
RegisterModule("sceAtrac3plus", ARRAY_SIZE(sceAtrac3plus), sceAtrac3plus);
|
|
|
|
}
|