SHA256
Refactor Audio Calculation
This commit is contained in:
5 files changed
+155
-86
No files matched your search
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using ADOFAIRenderer.Core;
|
||||
using ADOFAIRenderer.Util;
|
||||
using ADOFAIRenderer.Util.Audio;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
@@ -17,7 +15,7 @@ namespace ADOFAIRenderer.Patch.Engine
|
||||
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);
|
||||
RenderManager.Instance.AudioMixer?.CacheClip(snd);
|
||||
}
|
||||
return true; // Let the original method execute to prevent NullReferenceException
|
||||
}
|
||||
@@ -31,7 +29,7 @@ namespace ADOFAIRenderer.Patch.Engine
|
||||
double relativeStartTime = time - RenderManager.Instance.dspTimeBase;
|
||||
|
||||
// Register event to the offline mixer (default pitch = 1.0f) and map it to the AudioSource
|
||||
OfflineAudioMixer.RegisterSoundEvent(__result, snd, relativeStartTime, -1.0, volume, 1.0f);
|
||||
RenderManager.Instance.AudioMixer?.RegisterSoundEvent(__result, snd, relativeStartTime, -1.0, volume, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,15 +42,19 @@ namespace ADOFAIRenderer.Patch.Engine
|
||||
{
|
||||
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);
|
||||
var mixer = RenderManager.Instance.AudioMixer;
|
||||
if (mixer != null)
|
||||
{
|
||||
// Cache the clip on the main thread
|
||||
mixer.CacheClip(snd);
|
||||
|
||||
// Convert absolute DSP times to relative times in seconds from render start
|
||||
double relativeStartTime = time - RenderManager.Instance.dspTimeBase;
|
||||
double relativeEndTime = endTime - RenderManager.Instance.dspTimeBase;
|
||||
// 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);
|
||||
// Register looping sound event to the offline mixer (default pitch = 1.0f)
|
||||
mixer.RegisterSoundEvent(snd, relativeStartTime, relativeEndTime, volume, 1.0f);
|
||||
}
|
||||
}
|
||||
return true; // Let the original method execute
|
||||
}
|
||||
@@ -62,11 +64,13 @@ namespace ADOFAIRenderer.Patch.Engine
|
||||
public static class AudioSourcePitchPatch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static void Postfix(AudioSource __instance, float value)
|
||||
{
|
||||
if (RenderManager.IsCapturingActive && RenderManager.Instance.Configuration.RenderAudio)
|
||||
{
|
||||
if (OfflineAudioMixer.TryGetSoundEvent(__instance, out var soundEvent))
|
||||
var mixer = RenderManager.Instance.AudioMixer;
|
||||
if (mixer != null && mixer.TryGetSoundEvent(__instance, out var soundEvent))
|
||||
{
|
||||
soundEvent.Pitch = value;
|
||||
}
|
||||
@@ -84,7 +88,8 @@ namespace ADOFAIRenderer.Patch.Engine
|
||||
{
|
||||
if (RenderManager.IsCapturingActive && RenderManager.Instance.Configuration.RenderAudio)
|
||||
{
|
||||
if (OfflineAudioMixer.TryGetSoundEvent(__instance, out var soundEvent))
|
||||
var mixer = RenderManager.Instance.AudioMixer;
|
||||
if (mixer != null && mixer.TryGetSoundEvent(__instance, out var soundEvent))
|
||||
{
|
||||
soundEvent.EndTime = time - RenderManager.Instance.dspTimeBase;
|
||||
}
|
||||
@@ -100,7 +105,7 @@ namespace ADOFAIRenderer.Patch.Engine
|
||||
{
|
||||
if (RenderManager.IsCapturingActive && RenderManager.Instance.Configuration.RenderAudio)
|
||||
{
|
||||
OfflineAudioMixer.RemoveSourceMapping(__instance);
|
||||
RenderManager.Instance.AudioMixer?.RemoveSourceMapping(__instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user