SHA256
Add First Prototype of Audio Render Feature
This commit is contained in:
4 files changed
+493
-8
No files matched your search
@@ -0,0 +1,50 @@
|
||||
using ADOFAIRenderer.Core;
|
||||
using ADOFAIRenderer.Util;
|
||||
using HarmonyLib;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace ADOFAIRenderer.Patch.Engine
|
||||
{
|
||||
[HarmonyPatch(typeof(AudioManager), "_Play")]
|
||||
public static class AudioManagerPlayPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(string snd, double time, AudioMixerGroup group, float volume, int priority)
|
||||
{
|
||||
if (RenderManager.IsCapturingActive && RenderManager.Instance.Configuration.RenderAudio)
|
||||
{
|
||||
// Cache the clip on the main thread
|
||||
AudioClipCache.GetOrCache(snd, RenderManager.Instance.Configuration.AudioChannels, RenderManager.Instance.Configuration.AudioSampleRate, allowLoad: true);
|
||||
|
||||
// Convert absolute DSP time to relative time in seconds from render start
|
||||
double relativeStartTime = time - RenderManager.Instance.dspTimeBase;
|
||||
|
||||
// Register event to the offline mixer (default pitch = 1.0f)
|
||||
OfflineAudioMixer.RegisterSoundEvent(snd, relativeStartTime, -1.0, volume, 1.0f);
|
||||
}
|
||||
return true; // Let the original method execute to prevent NullReferenceException
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(scrConductor), "PlayWithEndTime")]
|
||||
public static class PlayWithEndTimePatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(string snd, double time, double endTime, float volume, int priority)
|
||||
{
|
||||
if (RenderManager.IsCapturingActive && RenderManager.Instance.Configuration.RenderAudio)
|
||||
{
|
||||
// Cache the clip on the main thread
|
||||
AudioClipCache.GetOrCache(snd, RenderManager.Instance.Configuration.AudioChannels, RenderManager.Instance.Configuration.AudioSampleRate, allowLoad: true);
|
||||
|
||||
// Convert absolute DSP times to relative times in seconds from render start
|
||||
double relativeStartTime = time - RenderManager.Instance.dspTimeBase;
|
||||
double relativeEndTime = endTime - RenderManager.Instance.dspTimeBase;
|
||||
|
||||
// Register looping sound event to the offline mixer (default pitch = 1.0f)
|
||||
OfflineAudioMixer.RegisterSoundEvent(snd, relativeStartTime, relativeEndTime, volume, 1.0f);
|
||||
}
|
||||
return true; // Let the original method execute
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user