From a5764205479da24e64d8143fdf65253d20fc6f85 Mon Sep 17 00:00:00 2001 From: kaienfr Date: Tue, 8 Apr 2014 01:09:28 +0200 Subject: [PATCH] Remove decode function of SimpleAudioDec and use its class method. --- Core/HLE/sceAudiocodec.cpp | 2 +- Core/HW/MediaEngine.cpp | 2 +- Core/HW/SimpleAudioDec.cpp | 37 ++++++++++++++----------------------- Core/HW/SimpleAudioDec.h | 1 - 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/Core/HLE/sceAudiocodec.cpp b/Core/HLE/sceAudiocodec.cpp index 19a7c8bfba..ae19fd005d 100644 --- a/Core/HLE/sceAudiocodec.cpp +++ b/Core/HLE/sceAudiocodec.cpp @@ -109,7 +109,7 @@ int sceAudiocodecDecode(u32 ctxPtr, int codec) { if (decoder != NULL){ // Decode audio - AudioDecode(decoder, Memory::GetPointer(ctx.inDataPtr), ctx.inDataSize, &outbytes, Memory::GetPointer(ctx.outDataPtr)); + decoder->Decode(Memory::GetPointer(ctx.inDataPtr), ctx.inDataSize, Memory::GetPointer(ctx.outDataPtr), &outbytes); DEBUG_LOG(ME, "sceAudiocodecDec(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); } return 0; diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 133a2d5982..95f5848b9c 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -742,7 +742,7 @@ int MediaEngine::getAudioSamples(u32 bufferPtr) { int outbytes = 0; if (m_audioContext != NULL) { - if (!AudioDecode(m_audioContext, audioFrame, frameSize, &outbytes, buffer)) { + if (!m_audioContext->Decode(audioFrame, frameSize, buffer, &outbytes)) { ERROR_LOG(ME, "Audio (%s) decode failed during video playback", GetCodecName(m_audioType)); } } diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index f8681087f0..a0e686c7dc 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -155,18 +155,17 @@ SimpleAudio::~SimpleAudio() { #endif // USE_FFMPEG } -void SaveAudio(uint8_t *outbuf, int size){ +void SaveAudio(const char filename[], uint8_t *outbuf, int size){ FILE * pf; - pf = fopen("dump.pcm", "ab+"); + pf = fopen(filename, "ab+"); fwrite(outbuf, size, 1, pf); fclose(pf); } -// Input is a single Audio packet. bool SimpleAudio::Decode(void* inbuf, int inbytes, uint8_t *outbuf, int *outbytes) { #ifdef USE_FFMPEG - AVPacket packet = { 0 }; + AVPacket packet; av_init_packet(&packet); packet.data = static_cast(inbuf); packet.size = inbytes; @@ -189,7 +188,7 @@ bool SimpleAudio::Decode(void* inbuf, int inbytes, uint8_t *outbuf, int *outbyte swrCtx_, wanted_channel_layout, AV_SAMPLE_FMT_S16, - codecCtx_->sample_rate, + 44100, dec_channel_layout, codecCtx_->sample_fmt, codecCtx_->sample_rate, @@ -202,23 +201,24 @@ bool SimpleAudio::Decode(void* inbuf, int inbytes, uint8_t *outbuf, int *outbyte codec_ = 0; return false; } - // convert audio to AV_SAMPLE_FMT_S16 int swrRet = swr_convert(swrCtx_, &outbuf, frame_->nb_samples, (const u8 **)frame_->extended_data, frame_->nb_samples); if (swrRet < 0) { ERROR_LOG(ME, "swr_convert: Error while converting %d", swrRet); return false; } - // each sample occupies 2 bytes, and the stereo mode has 2 channels - *outbytes = swrRet * 2 * 2; + swr_free(&swrCtx_); + // output samples per frame, we should *2 since we have two channels + int outSamples = swrRet * 2; + + // each sample occupies 2 bytes + *outbytes = outSamples * 2; // We always convert to stereo. __AdjustBGMVolume((s16 *)outbuf, frame_->nb_samples * 2); - - // Save outbuf into pcm audio, you can uncomment this line to save and check the decoded audio into pcm file. - //SaveAudio(outbuf, *outbytes); - //INFO_LOG(ME, "size of audio frame %d, size of output pcm %d", inbytes, *outbytes); - } + // Save outbuf into pcm audio, you can uncomment this line to save and check the decoded audio into pcm file. + // SaveAudio("dump.pcm", outbuf, *outbytes); + } return true; #else // Zero bytes output. No need to memset. @@ -227,16 +227,6 @@ bool SimpleAudio::Decode(void* inbuf, int inbytes, uint8_t *outbuf, int *outbyte #endif // USE_FFMPEG } - -bool AudioDecode(SimpleAudio *ctx, void* inbuf, int inbytes, int *outbytes, uint8_t *outbuf) { -#ifdef USE_FFMPEG - return ctx->Decode(inbuf, inbytes, outbuf, outbytes); -#else - *outbytes = 0; - return true; -#endif // USE_FFMPEG -} - void AudioClose(SimpleAudio **ctx) { #ifdef USE_FFMPEG delete *ctx; @@ -250,3 +240,4 @@ bool isValidCodec(int codec){ } return false; } + diff --git a/Core/HW/SimpleAudioDec.h b/Core/HW/SimpleAudioDec.h index 0a9c6503aa..1e1aec07c1 100644 --- a/Core/HW/SimpleAudioDec.h +++ b/Core/HW/SimpleAudioDec.h @@ -79,7 +79,6 @@ static const char *const codecNames[4] = { "AT3+", "AT3", "MP3", "AAC", }; -bool AudioDecode(SimpleAudio *ctx, void* inbuf, int inbytes, int *outbytes, uint8_t* outbuf); void AudioClose(SimpleAudio **ctx); static const char *GetCodecName(int codec) { if (codec >= PSP_CODEC_AT3PLUS && codec <= PSP_CODEC_AAC) {