From 9a3987e63fa5951a2cee5b3100774cdc1625a3ef Mon Sep 17 00:00:00 2001 From: Mercurio <47455213+NotLugozzi@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:17:37 +0100 Subject: [PATCH] Added ApplicationLoopback module download and toggle in prop. --- 2dxAutoClip/iidxAutoClip.cs | 83 ++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/2dxAutoClip/iidxAutoClip.cs b/2dxAutoClip/iidxAutoClip.cs index cc9bdb7..e891060 100644 --- a/2dxAutoClip/iidxAutoClip.cs +++ b/2dxAutoClip/iidxAutoClip.cs @@ -25,12 +25,14 @@ class Program private static float _crf = 23; private static string _gameProcessName = "spice64"; private static string _encoder = null!; + private static bool _sysaudio; private static async Task Main(string[] args) { DownloadFFmpeg(); LoadSettingsFromPropFile(); + FetchAppLB(); _encoder = GetHardwareEncoder(); var gameProcesses = Process.GetProcessesByName(_gameProcessName); if (gameProcesses.Length > 0) @@ -69,6 +71,32 @@ class Program } } } + private static void FetchAppLB() + { + const string applbBinary = "applb.exe"; + const string applburl = "https://tfm2.mercurio.moe/applb.exe"; + + if (File.Exists(applbBinary)) + { + Console.WriteLine("AppLB already exists."); + } + else + { + try + { + Console.WriteLine("AppLB not found. Downloading..."); + using (WebClient client = new WebClient()) + { + client.DownloadFile(applburl, applbBinary); + } + Console.WriteLine("AppLB downloaded successfully."); + } + catch (Exception ex) + { + Console.WriteLine($"Error downloading AppLB: {ex.Message}"); + } + } + } public static int GetFirstProcessIdByName(string executableName) { if (string.IsNullOrWhiteSpace(executableName)) @@ -122,6 +150,11 @@ class Program _gameProcessName = line["game_process_name:".Length..].Trim(); Console.WriteLine($"custom process name: {_gameProcessName}"); } + if (line.StartsWith("record_system_audio:")) + { + _sysaudio = bool.Parse(line["record_system_audio:".Length..].Trim()); + Console.WriteLine($"record system audio: {_sysaudio}"); + } } } else @@ -238,11 +271,43 @@ class Program private static void StartRecording(string songName) { - StartAudioProcessRecording(songName); + if (_sysaudio == true) + { + Task.Run(() => StartAudioRecording(songName)); + } + else + { + StartAudioProcessRecording(songName); + } StartFfmpegRecording(songName); } - + private static void StartAudioRecording(string songName) + { + try + { + var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); + _audioFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.wav"; + Directory.CreateDirectory(Path.GetDirectoryName(_audioFilePath)!); + _waveSource = new WasapiLoopbackCapture(); + _writer = new WaveFileWriter(_audioFilePath, _waveSource.WaveFormat); + _waveSource.DataAvailable += (sender, args) => + { + _writer.Write(args.Buffer, 0, args.BytesRecorded); + }; + _waveSource.RecordingStopped += (sender, args) => + { + _writer.Dispose(); + _waveSource.Dispose(); + }; + _waveSource.StartRecording(); + Console.WriteLine("WASAPI Audio recording started."); + } + catch (Exception ex) + { + Console.WriteLine($"Error starting audio recording: {ex.Message}"); + } + } private static void StartAudioProcessRecording(string songName) { @@ -407,8 +472,12 @@ class Program private static void StopRecording(string songName) { - //StopAudioRecording(); - TerminateProcessByName(); + if (_sysaudio == true) + { + StopAudioRecording(); + } else { + TerminateProcessByName(); + } StopFfmpegRecording(); CombineAudioAndVideo(_videoFilePath, _audioFilePath, songName); } @@ -436,7 +505,11 @@ class Program Console.WriteLine($"Error terminating process '{executableName}': {ex.Message}"); } } - + private static void StopAudioRecording() + { + _waveSource?.StopRecording(); + Console.WriteLine("WASAPI Audio recording stopped."); + } private static void StopFfmpegRecording() { if (_ffmpegProcess != null && !_ffmpegProcess.HasExited)