Have FFMS2 do the audio downmixing when possible

Aegisub's downmixer is terrible for anything with more than two channels
(averaging all the channels together is not even vaguely close to the
correct thing to do for 5.1), so libavresample should be far better.
This commit is contained in:
Thomas Goyne 2012-12-26 19:59:42 -08:00
parent 745b9ab2a9
commit 572a58cd90

View file

@ -173,6 +173,22 @@ void FFmpegSourceAudioProvider::LoadAudio(wxString filename) {
default:
throw agi::AudioProviderOpenError("unknown or unsupported sample format", 0);
}
#if FFMS_VERSION >= ((2 << 24) | (17 << 16) | (4 << 8) | 0)
if (channels > 1 || bytes_per_sample != 2) {
std::unique_ptr<FFMS_ResampleOptions, decltype(&FFMS_DestroyResampleOptions)>
opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions);
opt->ChannelLayout = FFMS_CH_FRONT_CENTER;
opt->SampleFormat = FFMS_FMT_S16;
// Might fail if FFMS2 wasn't built with libavresample
if (!FFMS_SetOutputFormatA(AudioSource, opt.get(), nullptr)) {
channels = 1;
bytes_per_sample = 2;
float_samples = false;
}
}
#endif
}
void FFmpegSourceAudioProvider::FillBuffer(void *Buf, int64_t Start, int64_t Count) const {