From b6443fcf1798c39e3d78964a99e85b811516e670 Mon Sep 17 00:00:00 2001 From: Squarebananas Date: Mon, 26 Aug 2024 22:06:03 +0100 Subject: [PATCH] Removes incorrect ADPCM encoder's block size requirement (to fix MonoGame issue #6701) --- build/BuildCommon.cs | 20 ++++++++++++++++++++ build/BuildLinuxTask.cs | 3 ++- build/BuildMacOSTask.cs | 3 ++- build/BuildWIndowsTask.cs | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 build/BuildCommon.cs diff --git a/build/BuildCommon.cs b/build/BuildCommon.cs new file mode 100644 index 0000000..6dc0aba --- /dev/null +++ b/build/BuildCommon.cs @@ -0,0 +1,20 @@ +namespace BuildScripts; + +static class BuildCommon +{ + // There is an issue with FFmpeg that causes incompatible reduced quality audio (MGCB medium & low settings) + // to be produced for XAudio2 playback. For reference a ticket has been opened at https://trac.ffmpeg.org/ticket/9397#ticket + // (samples per block should be a power of 2, however FFmpeg incorrectly forces this requirement on the block size + // instead). For now, we'll just patch out the encoder's power of 2 check. + public static void FFmpegApplyXAudio2Fix(BuildContext context) + { + string filePath = "./ffmpeg/libavcodec/adpcmenc.c"; + List lines = context.FileReadLines(filePath).ToList(); + int lineNumber = lines.FindIndex(x => x.Contains("av_log(avctx, AV_LOG_ERROR, \"block size must be power of 2\\n\");")); + if (lineNumber != -1) + { + lines.RemoveRange(lineNumber, 2); + context.FileWriteLines(filePath, lines.ToArray()); + } + } +} diff --git a/build/BuildLinuxTask.cs b/build/BuildLinuxTask.cs index 1d1808f..414f652 100644 --- a/build/BuildLinuxTask.cs +++ b/build/BuildLinuxTask.cs @@ -67,10 +67,11 @@ public override void Run(BuildContext context) processSettings.Arguments = $"-c \"make install\""; context.StartProcess(shellCommandPath, processSettings); - // Build ffmpeg + // Build ffmpeg (with XAudio2 fix) processSettings.WorkingDirectory = "./ffmpeg"; processSettings.Arguments = $"-c \"make distclean\""; context.StartProcess(shellCommandPath, processSettings); + BuildCommon.FFmpegApplyXAudio2Fix(context); processSettings.Arguments = $"-c \"./configure {binDirFlag} {configureFlags}\""; context.StartProcess(shellCommandPath, processSettings); processSettings.Arguments = $"-c \"make -j{Environment.ProcessorCount}\""; diff --git a/build/BuildMacOSTask.cs b/build/BuildMacOSTask.cs index 1f0d782..de3bb3e 100644 --- a/build/BuildMacOSTask.cs +++ b/build/BuildMacOSTask.cs @@ -108,10 +108,11 @@ private static void BuildArm64(BuildContext context) processSettings.Arguments = $"-c \"make install\""; context.StartProcess(shellCommandPath, processSettings); - // Build ffmpeg + // Build ffmpeg (with XAudio2 fix) processSettings.WorkingDirectory = "./ffmpeg"; processSettings.Arguments = $"-c \"make distclean\""; context.StartProcess(shellCommandPath, processSettings); + BuildCommon.FFmpegApplyXAudio2Fix(context); processSettings.Arguments = $"-c \"./configure {binDirFlag} {configureFlags} {progsSuffixFlag}\""; context.StartProcess(shellCommandPath, processSettings); processSettings.Arguments = $"-c \"make -j{Environment.ProcessorCount}\""; diff --git a/build/BuildWIndowsTask.cs b/build/BuildWIndowsTask.cs index 7b8f6d6..4aa53b2 100644 --- a/build/BuildWIndowsTask.cs +++ b/build/BuildWIndowsTask.cs @@ -82,10 +82,11 @@ public override void Run(BuildContext context) processSettings.Arguments = $"-c \"{exports} make install\""; context.StartProcess(shellCommandPath, processSettings); - // Build ffmpeg + // Build ffmpeg (with XAudio2 fix) processSettings.WorkingDirectory = "./ffmpeg"; processSettings.Arguments = $"-c \"{exports} make distclean\""; context.StartProcess(shellCommandPath, processSettings); + BuildCommon.FFmpegApplyXAudio2Fix(context); processSettings.Arguments = $"-c \"{exports} ./configure {binDirFlag} {configureFlags}\""; context.StartProcess(shellCommandPath, processSettings); processSettings.Arguments = $"-c \"{exports} make -j{Environment.ProcessorCount}\"";