mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-03 03:03:50 +01:00
Play AT3 files in background audio too.
Fixes 3rd Birthday and PQ2, at least.
This commit is contained in:
1 parent
122fa17d74
commit
47ad97617e
3 files changed
+49
-14
No files matched your search
+32
-13
@@ -61,7 +61,7 @@ bool SimpleAudio::GetAudioCodecID(int audioType) {
|
||||
}
|
||||
|
||||
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) {
|
||||
: ctxPtr(0xFFFFFFFF), audioType(audioType), sample_rate_(sample_rate), channels_(channels), codec_(0), codecCtx_(0), swrCtx_(0), outSamples(0), srcPos(0), wanted_resample_freq(44100), extradata_(0) {
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -94,16 +94,21 @@ void SimpleAudio::Init() {
|
||||
codecCtx_->channels = channels_;
|
||||
codecCtx_->channel_layout = channels_ == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
|
||||
codecCtx_->sample_rate = sample_rate_;
|
||||
// Open codec
|
||||
OpenCodec();
|
||||
#endif // USE_FFMPEG
|
||||
}
|
||||
|
||||
bool SimpleAudio::OpenCodec() {
|
||||
#ifdef USE_FFMPEG
|
||||
AVDictionary *opts = 0;
|
||||
bool result = true;
|
||||
if (avcodec_open2(codecCtx_, codec_, &opts) < 0) {
|
||||
ERROR_LOG(ME, "Failed to open codec");
|
||||
av_dict_free(&opts);
|
||||
return;
|
||||
result = false;
|
||||
}
|
||||
|
||||
av_dict_free(&opts);
|
||||
#endif // USE_FFMPEG
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SimpleAudio::ResetCodecCtx(int channels, int samplerate){
|
||||
@@ -122,19 +127,31 @@ bool SimpleAudio::ResetCodecCtx(int channels, int samplerate){
|
||||
codecCtx_->channels = channels;
|
||||
codecCtx_->channel_layout = channels==2?AV_CH_LAYOUT_STEREO:AV_CH_LAYOUT_MONO;
|
||||
codecCtx_->sample_rate = samplerate;
|
||||
// Open codec
|
||||
AVDictionary *opts = 0;
|
||||
if (avcodec_open2(codecCtx_, codec_, &opts) < 0) {
|
||||
ERROR_LOG(ME, "Failed to open codec");
|
||||
av_dict_free(&opts);
|
||||
return false;
|
||||
}
|
||||
av_dict_free(&opts);
|
||||
OpenCodec();
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void SimpleAudio::SetExtraData(u8 *data, int size, int wav_bytes_per_packet) {
|
||||
delete [] extradata_;
|
||||
extradata_ = 0;
|
||||
|
||||
if (data != 0) {
|
||||
extradata_ = new u8[size];
|
||||
memcpy(extradata_, data, size);
|
||||
}
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
if (codecCtx_) {
|
||||
codecCtx_->extradata = extradata_;
|
||||
codecCtx_->extradata_size = size;
|
||||
codecCtx_->block_align = wav_bytes_per_packet;
|
||||
OpenCodec();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SimpleAudio::~SimpleAudio() {
|
||||
#ifdef USE_FFMPEG
|
||||
if (swrCtx_)
|
||||
@@ -147,6 +164,8 @@ SimpleAudio::~SimpleAudio() {
|
||||
codecCtx_ = 0;
|
||||
codec_ = 0;
|
||||
#endif // USE_FFMPEG
|
||||
delete [] extradata_;
|
||||
extradata_ = 0;
|
||||
}
|
||||
|
||||
bool SimpleAudio::IsOK() const {
|
||||
|
||||
Reference in new issue
Block a user