Add option to downmix FFMS audio

When enabled, restore FFMS to old behavior, downmixing auduo to S16 mono. This can reduce cache usage.

Fix wangqr/Aegisub#31
This commit is contained in:
wangqr 2019-12-26 17:31:59 -05:00 committed by arch1t3cht
parent d0efa0494a
commit dabd9f699f
4 changed files with 16 additions and 11 deletions

View File

@ -165,7 +165,8 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {
throw agi::AudioProviderError("unknown or unsupported sample format"); throw agi::AudioProviderError("unknown or unsupported sample format");
} }
if (channels > 1 || bytes_per_sample != 2) { if (OPT_GET("Provider/Audio/FFmpegSource/Downmix")->GetBool()) {
if (channels > 1 || bytes_per_sample != 2 || float_samples) {
std::unique_ptr<FFMS_ResampleOptions, decltype(&FFMS_DestroyResampleOptions)> std::unique_ptr<FFMS_ResampleOptions, decltype(&FFMS_DestroyResampleOptions)>
opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions); opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions);
opt->ChannelLayout = FFMS_CH_FRONT_CENTER; opt->ChannelLayout = FFMS_CH_FRONT_CENTER;
@ -179,6 +180,7 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {
} }
} }
} }
}
} }

View File

@ -331,7 +331,8 @@
"Sample Rate" : 0 "Sample Rate" : 0
}, },
"FFmpegSource" : { "FFmpegSource" : {
"Decode Error Handling" : "ignore" "Decode Error Handling" : "ignore",
"Downmix" : false
} }
}, },
"Avisynth" : { "Avisynth" : {

View File

@ -401,6 +401,7 @@ void Advanced_Audio(wxTreebook *book, Preferences *parent) {
p->OptionChoice(ffms, _("Audio indexing error handling mode"), error_modes_choice, "Provider/Audio/FFmpegSource/Decode Error Handling"); p->OptionChoice(ffms, _("Audio indexing error handling mode"), error_modes_choice, "Provider/Audio/FFmpegSource/Decode Error Handling");
p->OptionAdd(ffms, _("Always index all audio tracks"), "Provider/FFmpegSource/Index All Tracks"); p->OptionAdd(ffms, _("Always index all audio tracks"), "Provider/FFmpegSource/Index All Tracks");
p->OptionAdd(ffms, _("Downmix to 16bit mono audio"), "Provider/Audio/FFmpegSource/Downmix");
#endif #endif
#ifdef WITH_PORTAUDIO #ifdef WITH_PORTAUDIO

View File

@ -53,6 +53,7 @@ Project::Project(agi::Context *c) : context(c) {
OPT_SUB("Audio/Cache/Type", &Project::ReloadAudio, this); OPT_SUB("Audio/Cache/Type", &Project::ReloadAudio, this);
OPT_SUB("Audio/Provider", &Project::ReloadAudio, this); OPT_SUB("Audio/Provider", &Project::ReloadAudio, this);
OPT_SUB("Provider/Audio/FFmpegSource/Decode Error Handling", &Project::ReloadAudio, this); OPT_SUB("Provider/Audio/FFmpegSource/Decode Error Handling", &Project::ReloadAudio, this);
OPT_SUB("Provider/Audio/FFmpegSource/Downmix", &Project::ReloadAudio, this);
OPT_SUB("Provider/Avisynth/Allow Ancient", &Project::ReloadVideo, this); OPT_SUB("Provider/Avisynth/Allow Ancient", &Project::ReloadVideo, this);
OPT_SUB("Provider/Avisynth/Memory Max", &Project::ReloadVideo, this); OPT_SUB("Provider/Avisynth/Memory Max", &Project::ReloadVideo, this);
OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", &Project::ReloadVideo, this); OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", &Project::ReloadVideo, this);