mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
Minor code cleanups
This commit is contained in:
parent
88eb2c2e0b
commit
32ca7ab59a
@ -124,6 +124,7 @@ void __KernelInit()
|
||||
__IoInit();
|
||||
__JpegInit();
|
||||
__AudioInit();
|
||||
__Mp3Init();
|
||||
__SasInit();
|
||||
__AtracInit();
|
||||
__CccInit();
|
||||
|
@ -157,6 +157,10 @@ static AuCtx *getMp3Ctx(u32 mp3) {
|
||||
return mp3Map[mp3];
|
||||
}
|
||||
|
||||
void __Mp3Init() {
|
||||
resourceInited = false;
|
||||
}
|
||||
|
||||
void __Mp3Shutdown() {
|
||||
for (auto it = mp3Map.begin(), end = mp3Map.end(); it != end; ++it) {
|
||||
delete it->second;
|
||||
@ -194,8 +198,7 @@ void __Mp3DoState(PointerWrap &p) {
|
||||
mp3->MaxOutputSample = mp3_old->mp3MaxSamples;
|
||||
mp3->SetReadPos(mp3_old->readPosition);
|
||||
|
||||
mp3->audioType = PSP_CODEC_MP3;
|
||||
mp3->decoder = new SimpleAudio(mp3->audioType);
|
||||
mp3->decoder = new SimpleAudio(PSP_CODEC_MP3);
|
||||
mp3Map[id] = mp3;
|
||||
}
|
||||
}
|
||||
@ -300,9 +303,8 @@ static u32 sceMp3ReserveMp3Handle(u32 mp3Addr) {
|
||||
Au->PCMBufSize = 0;
|
||||
}
|
||||
|
||||
Au->audioType = PSP_CODEC_MP3;
|
||||
Au->SetReadPos(Au->startPos);
|
||||
Au->decoder = new SimpleAudio(Au->audioType);
|
||||
Au->decoder = new SimpleAudio(PSP_CODEC_MP3);
|
||||
|
||||
int handle = (int)mp3Map.size();
|
||||
mp3Map[handle] = Au;
|
||||
@ -701,9 +703,8 @@ static u32 sceMp3ResetPlayPositionByFrame(u32 mp3, u32 frame) {
|
||||
static u32 sceMp3LowLevelInit(u32 mp3, u32 unk) {
|
||||
auto ctx = new AuCtx;
|
||||
|
||||
ctx->audioType = PSP_CODEC_MP3;
|
||||
// create mp3 decoder
|
||||
ctx->decoder = new SimpleAudio(ctx->audioType);
|
||||
ctx->decoder = new SimpleAudio(PSP_CODEC_MP3);
|
||||
|
||||
// close the audio if mp3 already exists.
|
||||
if (mp3Map.find(mp3) != mp3Map.end()) {
|
||||
|
@ -21,5 +21,6 @@ class PointerWrap;
|
||||
|
||||
void Register_sceMp3();
|
||||
|
||||
void __Mp3Init();
|
||||
void __Mp3Shutdown();
|
||||
void __Mp3DoState(PointerWrap &p);
|
||||
void __Mp3DoState(PointerWrap &p);
|
||||
|
@ -253,10 +253,9 @@ static u32 sceAacInit(u32 id)
|
||||
aac->Channels = 2;
|
||||
aac->MaxOutputSample = aac->PCMBufSize / 4;
|
||||
aac->SetReadPos((int)aac->startPos);
|
||||
aac->audioType = PSP_CODEC_AAC;
|
||||
|
||||
// create aac decoder
|
||||
aac->decoder = new SimpleAudio(aac->audioType);
|
||||
aac->decoder = new SimpleAudio(PSP_CODEC_AAC);
|
||||
|
||||
// close the audio if id already exist.
|
||||
if (aacMap.find(id) != aacMap.end()) {
|
||||
|
@ -37,6 +37,11 @@ extern "C" {
|
||||
|
||||
#endif // USE_FFMPEG
|
||||
|
||||
// TODO: This should also be able to create other types of decoders.
|
||||
SimpleAudio *CreateAudioDecoder(int audioType) {
|
||||
return new SimpleAudio(audioType);
|
||||
}
|
||||
|
||||
int SimpleAudio::GetAudioCodecID(int audioType) {
|
||||
#ifdef USE_FFMPEG
|
||||
switch (audioType) {
|
||||
@ -57,13 +62,11 @@ int SimpleAudio::GetAudioCodecID(int audioType) {
|
||||
}
|
||||
|
||||
SimpleAudio::SimpleAudio(int audioType, int sample_rate, int channels)
|
||||
: ctxPtr(0xFFFFFFFF), audioType(audioType), sample_rate_(sample_rate), channels_(channels),
|
||||
outSamples(0), srcPos(0), frame_(0), codec_(0), codecCtx_(0), swrCtx_(0),
|
||||
codecOpen_(false) {
|
||||
Init();
|
||||
}
|
||||
: ctxPtr(0xFFFFFFFF), audioType(audioType), sample_rate_(sample_rate), channels_(channels),
|
||||
outSamples(0), srcPos(0),
|
||||
frame_(0), codec_(0), codecCtx_(0), swrCtx_(0),
|
||||
codecOpen_(false) {
|
||||
|
||||
void SimpleAudio::Init() {
|
||||
#ifdef USE_FFMPEG
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 18, 100)
|
||||
avcodec_register_all();
|
||||
@ -179,6 +182,7 @@ bool SimpleAudio::IsOK() const {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Decodes a single input frame.
|
||||
bool SimpleAudio::Decode(const uint8_t *inbuf, int inbytes, uint8_t *outbuf, int *outbytes) {
|
||||
#ifdef USE_FFMPEG
|
||||
if (!codecOpen_) {
|
||||
@ -286,6 +290,12 @@ void AudioClose(AudioDecoder **ctx) {
|
||||
#endif // USE_FFMPEG
|
||||
}
|
||||
|
||||
void AudioClose(SimpleAudio **ctx) {
|
||||
#ifdef USE_FFMPEG
|
||||
delete *ctx;
|
||||
*ctx = 0;
|
||||
#endif // USE_FFMPEG
|
||||
}
|
||||
|
||||
static const char *const codecNames[4] = {
|
||||
"AT3+", "AT3", "MP3", "AAC",
|
||||
@ -320,7 +330,7 @@ AuCtx::~AuCtx() {
|
||||
}
|
||||
|
||||
size_t AuCtx::FindNextMp3Sync() {
|
||||
if (audioType != PSP_CODEC_MP3) {
|
||||
if (decoder->GetAudioType() != PSP_CODEC_MP3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -413,7 +423,7 @@ int AuCtx::AuCheckStreamDataNeeded() {
|
||||
}
|
||||
|
||||
int AuCtx::AuStreamBytesNeeded() {
|
||||
if (audioType == PSP_CODEC_MP3) {
|
||||
if (decoder->GetAudioType() == PSP_CODEC_MP3) {
|
||||
// The endPos and readPos are not considered, except when you've read to the end.
|
||||
if (readPos >= endPos)
|
||||
return 0;
|
||||
@ -428,7 +438,7 @@ int AuCtx::AuStreamBytesNeeded() {
|
||||
|
||||
int AuCtx::AuStreamWorkareaSize() {
|
||||
// Note that this is 31 bytes more than the max layer 3 frame size.
|
||||
if (audioType == PSP_CODEC_MP3)
|
||||
if (decoder->GetAudioType() == PSP_CODEC_MP3)
|
||||
return 0x05c0;
|
||||
return 0;
|
||||
}
|
||||
@ -525,6 +535,7 @@ void AuCtx::DoState(PointerWrap &p) {
|
||||
Do(p, Channels);
|
||||
Do(p, MaxOutputSample);
|
||||
Do(p, readPos);
|
||||
int audioType = decoder->GetAudioType();
|
||||
Do(p, audioType);
|
||||
Do(p, BitRate);
|
||||
Do(p, SamplingRate);
|
||||
@ -544,6 +555,6 @@ void AuCtx::DoState(PointerWrap &p) {
|
||||
}
|
||||
|
||||
if (p.mode == p.MODE_READ) {
|
||||
decoder = new SimpleAudio(audioType);
|
||||
decoder = CreateAudioDecoder(audioType);
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
|
||||
virtual int GetOutSamples() const = 0;
|
||||
virtual int GetSourcePos() const = 0;
|
||||
virtual int GetAudioType() const = 0;
|
||||
};
|
||||
|
||||
// FFMPEG-based decoder
|
||||
@ -90,7 +91,6 @@ public:
|
||||
u32 GetCtxPtr() const { return ctxPtr; }
|
||||
|
||||
private:
|
||||
void Init();
|
||||
bool OpenCodec(int block_align);
|
||||
|
||||
u32 ctxPtr;
|
||||
@ -111,6 +111,7 @@ private:
|
||||
bool codecOpen_;
|
||||
};
|
||||
|
||||
void AudioClose(SimpleAudio **ctx);
|
||||
void AudioClose(AudioDecoder **ctx);
|
||||
const char *GetCodecName(int codec); // audioType
|
||||
bool IsValidCodec(int codec);
|
||||
@ -170,9 +171,6 @@ public:
|
||||
// Au decoder
|
||||
AudioDecoder *decoder = nullptr;
|
||||
|
||||
// Au type
|
||||
int audioType = 0;
|
||||
|
||||
private:
|
||||
size_t FindNextMp3Sync();
|
||||
|
||||
@ -180,7 +178,7 @@ private:
|
||||
|
||||
// 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 readPos = 0; // read position in audio source file
|
||||
int askedReadSize = 0; // the size of data requied to be read from file by the game
|
||||
int nextOutputHalf = 0;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user