mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-04 16:06:13 +00:00
Remove decode function of SimpleAudioDec and use its class method.
This commit is contained in:
parent
6d447bffb4
commit
a576420547
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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<uint8_t *>(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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user