From 8c36921d3c48ad92e7dfca962a2f3eb3938ad011 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 22 Jun 2014 18:33:09 +0200 Subject: [PATCH] Have SimpleAudio respect channels/samplerate passed in --- Core/HW/SimpleAudioDec.cpp | 12 ++++++------ Core/HW/SimpleAudioDec.h | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index 4cccac9dc0..158ba8ce44 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -60,8 +60,8 @@ bool SimpleAudio::GetAudioCodecID(int audioType) { #endif // USE_FFMPEG } -SimpleAudio::SimpleAudio(int audioType) -: codec_(0), codecCtx_(0), swrCtx_(0), ctxPtr(0xFFFFFFFF), audioType(audioType), outSamples(0), srcPos(0), wanted_resample_freq(44100) { +SimpleAudio::SimpleAudio(int audioType, int sample_rate, int channels) +: ctxPtr(0xFFFFFFFF), audioType(audioType), sample_rate_(sample_rate), channels_(channels), codec_(0), codecCtx_(0), swrCtx_(0), outSamples(0), srcPos(0), wanted_resample_freq(44100) { Init(); } @@ -91,9 +91,9 @@ void SimpleAudio::Init() { ERROR_LOG(ME, "Failed to allocate a codec context"); return; } - codecCtx_->channels = 2; - codecCtx_->channel_layout = AV_CH_LAYOUT_STEREO; - codecCtx_->sample_rate = 44100; + codecCtx_->channels = channels_; + codecCtx_->channel_layout = channels_ == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; + codecCtx_->sample_rate = sample_rate_; // Open codec AVDictionary *opts = 0; if (avcodec_open2(codecCtx_, codec_, &opts) < 0) { @@ -179,7 +179,7 @@ bool SimpleAudio::Decode(void* inbuf, int inbytes, uint8_t *outbuf, int *outbyte srcPos = 0; int len = avcodec_decode_audio4(codecCtx_, frame_, &got_frame, &packet); if (len < 0) { - ERROR_LOG(ME, "Error decoding Audio frame"); + ERROR_LOG(ME, "Error decoding Audio frame (%i bytes): %i (%08x)", inbytes, len, len); // TODO: cleanup return false; } diff --git a/Core/HW/SimpleAudioDec.h b/Core/HW/SimpleAudioDec.h index 34d3900c98..49ecd72cbd 100644 --- a/Core/HW/SimpleAudioDec.h +++ b/Core/HW/SimpleAudioDec.h @@ -43,7 +43,7 @@ enum { class SimpleAudio { public: - SimpleAudio(int audioType); + SimpleAudio(int audioType, int sample_rate = 44100, int channels = 2); ~SimpleAudio(); bool Decode(void* inbuf, int inbytes, uint8_t *outbuf, int *outbytes); @@ -67,6 +67,8 @@ private: u32 ctxPtr; int audioType; + int sample_rate_; + int channels_; int outSamples; // output samples per frame int srcPos; // bytes consumed in source during the last decoding int wanted_resample_freq; // wanted resampling rate/frequency