mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-24 16:49:50 +00:00
Merge pull request #8472 from unknownbrackets/mpeg-mono
Mpeg: Correctly handle mono audio in videos
This commit is contained in:
commit
2abf848a80
@ -281,7 +281,7 @@ bool MediaEngine::openContext() {
|
||||
return false;
|
||||
|
||||
setVideoDim();
|
||||
m_audioContext = new SimpleAudio(m_audioType);
|
||||
m_audioContext = new SimpleAudio(m_audioType, 44100, 2);
|
||||
m_isVideoEnd = false;
|
||||
m_mpegheaderReadPos++;
|
||||
av_seek_frame(m_pFormatCtx, m_videoStream, 0, 0);
|
||||
@ -862,7 +862,13 @@ int MediaEngine::getAudioSamples(u32 bufferPtr) {
|
||||
}
|
||||
int outbytes = 0;
|
||||
|
||||
if (m_audioContext != NULL) {
|
||||
if (m_audioContext != nullptr) {
|
||||
if (headerCode1 == 0x24) {
|
||||
// This means mono audio - tell the decoder to expect it before the first frame.
|
||||
// Note that it will always send us back stereo audio.
|
||||
m_audioContext->SetChannels(1);
|
||||
}
|
||||
|
||||
if (!m_audioContext->Decode(audioFrame, frameSize, buffer, &outbytes)) {
|
||||
ERROR_LOG(ME, "Audio (%s) decode failed during video playback", GetCodecName(m_audioType));
|
||||
}
|
||||
@ -871,17 +877,6 @@ int MediaEngine::getAudioSamples(u32 bufferPtr) {
|
||||
#endif
|
||||
}
|
||||
|
||||
if (headerCode1 == 0x24) {
|
||||
// it a mono atrac3plus, convert it to stereo
|
||||
s16 *outbuf = (s16*)buffer;
|
||||
s16 *inbuf = (s16*)buffer;
|
||||
for (int i = 0x800 - 1; i >= 0; i--) {
|
||||
s16 sample = inbuf[i];
|
||||
outbuf[i * 2] = sample;
|
||||
outbuf[i * 2 + 1] = sample;
|
||||
}
|
||||
}
|
||||
|
||||
return 0x2000;
|
||||
}
|
||||
|
||||
|
@ -129,6 +129,21 @@ void SimpleAudio::SetExtraData(u8 *data, int size, int wav_bytes_per_packet) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimpleAudio::SetChannels(int channels) {
|
||||
if (channels_ == channels) {
|
||||
// Do nothing, already set.
|
||||
return;
|
||||
}
|
||||
|
||||
if (codecOpen_) {
|
||||
ERROR_LOG(ME, "Codec already open, cannot change channels");
|
||||
} else {
|
||||
channels_ = channels;
|
||||
codecCtx_->channels = channels_;
|
||||
codecCtx_->channel_layout = channels_ == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
|
||||
}
|
||||
}
|
||||
|
||||
SimpleAudio::~SimpleAudio() {
|
||||
#ifdef USE_FFMPEG
|
||||
swr_free(&swrCtx_);
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
// Not save stated, only used by UI. Used for ATRAC3 (non+) files.
|
||||
void SetExtraData(u8 *data, int size, int wav_bytes_per_packet);
|
||||
|
||||
void SetChannels(int channels);
|
||||
|
||||
// These two are only here because of save states.
|
||||
int GetAudioType() const { return audioType; }
|
||||
void SetResampleFrequency(int freq) { wanted_resample_freq = freq; }
|
||||
|
Loading…
Reference in New Issue
Block a user