diff --git a/Core/HLE/sceAudiocodec.cpp b/Core/HLE/sceAudiocodec.cpp index 296b5bf90e..0b1e32c52e 100644 --- a/Core/HLE/sceAudiocodec.cpp +++ b/Core/HLE/sceAudiocodec.cpp @@ -77,29 +77,31 @@ void __AudioCodecShutdown() { } static int sceAudiocodecInit(u32 ctxPtr, int codec) { - if (IsValidCodec(codec)) { + PSPAudioType audioType = (PSPAudioType)codec; + if (IsValidCodec(audioType)) { // Create audio decoder for given audio codec and push it into AudioList if (removeDecoder(ctxPtr)) { WARN_LOG_REPORT(HLE, "sceAudiocodecInit(%08x, %d): replacing existing context", ctxPtr, codec); } - auto decoder = new SimpleAudio(codec); + auto decoder = CreateAudioDecoder(audioType); decoder->SetCtxPtr(ctxPtr); audioList[ctxPtr] = decoder; - INFO_LOG(ME, "sceAudiocodecInit(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); + INFO_LOG(ME, "sceAudiocodecInit(%08x, %i (%s))", ctxPtr, codec, GetCodecName(audioType)); DEBUG_LOG(ME, "Number of playing sceAudioCodec audios : %d", (int)audioList.size()); return 0; } - ERROR_LOG_REPORT(ME, "sceAudiocodecInit(%08x, %i (%s)): Unknown audio codec %i", ctxPtr, codec, GetCodecName(codec), codec); + ERROR_LOG_REPORT(ME, "sceAudiocodecInit(%08x, %i (%s)): Unknown audio codec %i", ctxPtr, codec, GetCodecName(audioType), codec); return 0; } static int sceAudiocodecDecode(u32 ctxPtr, int codec) { + PSPAudioType audioType = (PSPAudioType)codec; if (!ctxPtr){ - ERROR_LOG_REPORT(ME, "sceAudiocodecDecode(%08x, %i (%s)) got NULL pointer", ctxPtr, codec, GetCodecName(codec)); + ERROR_LOG_REPORT(ME, "sceAudiocodecDecode(%08x, %i (%s)) got NULL pointer", ctxPtr, codec, GetCodecName(audioType)); return -1; } - if (IsValidCodec(codec)){ + if (IsValidCodec(audioType)){ int outbytes = 0; // find a decoder in audioList auto decoder = findDecoder(ctxPtr); @@ -107,7 +109,7 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) { if (!decoder && oldStateLoaded) { // We must have loaded an old state that did not have sceAudiocodec information. // Fake it by creating the desired context. - decoder = new SimpleAudio(codec); + decoder = CreateAudioDecoder(audioType); decoder->SetCtxPtr(ctxPtr); audioList[ctxPtr] = decoder; } @@ -194,7 +196,7 @@ void __sceAudiocodecDoState(PointerWrap &p){ DoArray(p, codec_, s >= 2 ? count : (int)ARRAY_SIZE(codec_)); DoArray(p, ctxPtr_, s >= 2 ? count : (int)ARRAY_SIZE(ctxPtr_)); for (int i = 0; i < count; i++) { - auto decoder = new SimpleAudio(codec_[i]); + auto decoder = CreateAudioDecoder((PSPAudioType)codec_[i]); decoder->SetCtxPtr(ctxPtr_[i]); audioList[ctxPtr_[i]] = decoder; } diff --git a/Core/HLE/sceMp3.cpp b/Core/HLE/sceMp3.cpp index 2d824bae5b..6e21291c64 100644 --- a/Core/HLE/sceMp3.cpp +++ b/Core/HLE/sceMp3.cpp @@ -198,7 +198,7 @@ void __Mp3DoState(PointerWrap &p) { mp3->MaxOutputSample = mp3_old->mp3MaxSamples; mp3->SetReadPos(mp3_old->readPosition); - mp3->decoder = new SimpleAudio(PSP_CODEC_MP3); + mp3->decoder = CreateAudioDecoder(PSP_CODEC_MP3); mp3Map[id] = mp3; } } @@ -304,7 +304,7 @@ static u32 sceMp3ReserveMp3Handle(u32 mp3Addr) { } Au->SetReadPos(Au->startPos); - Au->decoder = new SimpleAudio(PSP_CODEC_MP3); + Au->decoder = CreateAudioDecoder(PSP_CODEC_MP3); int handle = (int)mp3Map.size(); mp3Map[handle] = Au; @@ -701,10 +701,10 @@ static u32 sceMp3ResetPlayPositionByFrame(u32 mp3, u32 frame) { } static u32 sceMp3LowLevelInit(u32 mp3, u32 unk) { - auto ctx = new AuCtx; + auto ctx = new AuCtx(); // create mp3 decoder - ctx->decoder = new SimpleAudio(PSP_CODEC_MP3); + ctx->decoder = CreateAudioDecoder(PSP_CODEC_MP3); // close the audio if mp3 already exists. if (mp3Map.find(mp3) != mp3Map.end()) { diff --git a/Core/HLE/sceMp4.cpp b/Core/HLE/sceMp4.cpp index e1c555e8a3..c804013641 100644 --- a/Core/HLE/sceMp4.cpp +++ b/Core/HLE/sceMp4.cpp @@ -255,7 +255,7 @@ static u32 sceAacInit(u32 id) aac->SetReadPos((int)aac->startPos); // create aac decoder - aac->decoder = new SimpleAudio(PSP_CODEC_AAC); + aac->decoder = CreateAudioDecoder(PSP_CODEC_AAC); // close the audio if id already exist. if (aacMap.find(id) != aacMap.end()) { diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 7e8b37d4dc..c1e23612ab 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -340,7 +340,7 @@ bool MediaEngine::openContext(bool keepReadPos) { return false; setVideoDim(); - m_audioContext = new SimpleAudio(m_audioType, 44100, 2); + m_audioContext = CreateAudioDecoder((PSPAudioType)m_audioType); m_isVideoEnd = false; #endif // USE_FFMPEG return true; diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index 4ee43a3d96..d850058ddd 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -38,8 +38,8 @@ 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); +SimpleAudio *CreateAudioDecoder(PSPAudioType audioType, int sampleRateHz, int channels) { + return new SimpleAudio(audioType, sampleRateHz, channels); } int SimpleAudio::GetAudioCodecID(int audioType) { @@ -61,8 +61,8 @@ int SimpleAudio::GetAudioCodecID(int audioType) { #endif // USE_FFMPEG } -SimpleAudio::SimpleAudio(int audioType, int sample_rate, int channels) - : ctxPtr(0xFFFFFFFF), audioType(audioType), sample_rate_(sample_rate), channels_(channels), +SimpleAudio::SimpleAudio(PSPAudioType audioType, int sampleRateHz, int channels) + : ctxPtr(0xFFFFFFFF), audioType(audioType), sample_rate_(sampleRateHz), channels_(channels), outSamples(0), srcPos(0), frame_(0), codec_(0), codecCtx_(0), swrCtx_(0), codecOpen_(false) { @@ -309,7 +309,7 @@ const char *GetCodecName(int codec) { } }; -bool IsValidCodec(int codec){ +bool IsValidCodec(PSPAudioType codec){ if (codec >= PSP_CODEC_AT3PLUS && codec <= PSP_CODEC_AAC) { return true; } @@ -535,7 +535,7 @@ void AuCtx::DoState(PointerWrap &p) { Do(p, Channels); Do(p, MaxOutputSample); Do(p, readPos); - int audioType = decoder->GetAudioType(); + int audioType = (int)decoder->GetAudioType(); Do(p, audioType); Do(p, BitRate); Do(p, SamplingRate); @@ -555,6 +555,6 @@ void AuCtx::DoState(PointerWrap &p) { } if (p.mode == p.MODE_READ) { - decoder = CreateAudioDecoder(audioType); + decoder = CreateAudioDecoder((PSPAudioType)audioType); } } diff --git a/Core/HW/SimpleAudioDec.h b/Core/HW/SimpleAudioDec.h index 02ba8db3b8..5433b4166e 100644 --- a/Core/HW/SimpleAudioDec.h +++ b/Core/HW/SimpleAudioDec.h @@ -41,7 +41,7 @@ extern "C" { // Based on http://ffmpeg.org/doxygen/trunk/doc_2examples_2decoding_encoding_8c-example.html#_a13 // audioType -enum { +enum PSPAudioType { PSP_CODEC_AT3PLUS = 0x00001000, PSP_CODEC_AT3 = 0x00001001, PSP_CODEC_MP3 = 0x00001002, @@ -57,13 +57,13 @@ public: virtual int GetOutSamples() const = 0; virtual int GetSourcePos() const = 0; - virtual int GetAudioType() const = 0; + virtual PSPAudioType GetAudioType() const = 0; }; // FFMPEG-based decoder class SimpleAudio : public AudioDecoder { public: - SimpleAudio(int audioType, int sample_rate = 44100, int channels = 2); + SimpleAudio(PSPAudioType audioType, int sampleRateHz = 44100, int channels = 2); ~SimpleAudio(); bool Decode(const uint8_t* inbuf, int inbytes, uint8_t *outbuf, int *outbytes) override; @@ -84,7 +84,7 @@ public: void SetChannels(int channels); // These two are only here because of save states. - int GetAudioType() const { return audioType; } + PSPAudioType GetAudioType() const { return audioType; } // Just metadata. void SetCtxPtr(u32 ptr) { ctxPtr = ptr; } @@ -94,7 +94,7 @@ private: bool OpenCodec(int block_align); u32 ctxPtr; - int audioType; + PSPAudioType audioType; int sample_rate_; int channels_; int outSamples; // output samples per frame @@ -114,7 +114,8 @@ private: void AudioClose(SimpleAudio **ctx); void AudioClose(AudioDecoder **ctx); const char *GetCodecName(int codec); // audioType -bool IsValidCodec(int codec); +bool IsValidCodec(PSPAudioType codec); +SimpleAudio *CreateAudioDecoder(PSPAudioType audioType, int sampleRateHz = 44100, int channels = 2); class AuCtx { public: diff --git a/UI/BackgroundAudio.cpp b/UI/BackgroundAudio.cpp index 32cbefc0a0..d7bacd6814 100644 --- a/UI/BackgroundAudio.cpp +++ b/UI/BackgroundAudio.cpp @@ -189,7 +189,7 @@ public: wave_.Read(file_); - decoder_ = new SimpleAudio(wave_.codec, wave_.sample_rate, wave_.num_channels); + decoder_ = CreateAudioDecoder((PSPAudioType)wave_.codec, wave_.sample_rate, wave_.num_channels); if (wave_.codec == PSP_CODEC_AT3) { decoder_->SetExtraData(&wave_.at3_extradata[2], 14, wave_.raw_bytes_per_frame); }