SHA256
Switch Render Audio To Voice Mixer
This commit is contained in:
1 parent
3d2ffe9dfe
commit
cb0fd1bd96
8 files changed
+351
-541
No files matched your search
+18
-8
@@ -146,6 +146,9 @@ internal class RenderManager : MonoBehaviour
|
||||
public int frameCountBase;
|
||||
|
||||
public OfflineAudioMixer? AudioMixer { get; private set; }
|
||||
|
||||
/// <summary>Render time of the current frame in seconds (frameCount / RenderFPS), the time base of audio commands.</summary>
|
||||
public double AudioTime => frameCount / Configuration.RenderFPS;
|
||||
private AudioSyncCalculator? SyncCalculator { get; set; }
|
||||
|
||||
private FrameReader? _frameReader;
|
||||
@@ -412,7 +415,16 @@ internal class RenderManager : MonoBehaviour
|
||||
// ReSharper disable once Unity.IncorrectMethodSignature
|
||||
public void OnPostFrame(RenderTexture? texture)
|
||||
{
|
||||
if (Instance.stage < RenderStage.Render || !texture) return;
|
||||
if (Instance.stage < RenderStage.Render) return;
|
||||
|
||||
// Audio commands of this frame are queued: update the song voice and let the render thread mix up to the next frame.
|
||||
if (AudioMixer != null)
|
||||
{
|
||||
AudioMixer.UpdateBGM(AudioTime, dspTimeBase);
|
||||
AudioMixer.Commit((frameCount + 1) / Configuration.RenderFPS);
|
||||
}
|
||||
|
||||
if (!texture) return;
|
||||
|
||||
// [Backpressure Throttling]
|
||||
isThrottling = false;
|
||||
@@ -682,7 +694,7 @@ internal class RenderManager : MonoBehaviour
|
||||
throw;
|
||||
}
|
||||
|
||||
var encoder = videoFFmpeg!;
|
||||
var encoder = videoFFmpeg;
|
||||
RenderThread = new Thread(() => RunRenderThread(encoder))
|
||||
{
|
||||
IsBackground = true,
|
||||
@@ -816,17 +828,13 @@ internal class RenderManager : MonoBehaviour
|
||||
{
|
||||
if (!Configuration.AudioConfig.RenderAudio || SyncCalculator is not { } syncCalculator) return;
|
||||
|
||||
var frameIdx = (int)(passCount - 1);
|
||||
var effectiveVideoFps = Math.Min(Configuration.VideoFPS, Configuration.RenderFPS);
|
||||
var frameTime = frameIdx / effectiveVideoFps;
|
||||
|
||||
var channels = Configuration.AudioConfig.AudioChannels;
|
||||
var samplesNeeded = syncCalculator.GetNextFrameSamples();
|
||||
|
||||
var audioBuffer = ArrayPool<float>.Shared.Rent(samplesNeeded * channels);
|
||||
try
|
||||
{
|
||||
AudioMixer?.GenerateAudioForFrame(audioBuffer, samplesNeeded, frameTime, dspTimeBase);
|
||||
AudioMixer?.GenerateAudioForFrame(audioBuffer, samplesNeeded);
|
||||
videoFFmpeg.WriteAudioSamples(audioBuffer, samplesNeeded);
|
||||
}
|
||||
finally
|
||||
@@ -865,6 +873,8 @@ internal class RenderManager : MonoBehaviour
|
||||
private void StopFFmpeg(bool success)
|
||||
{
|
||||
endRequested = true;
|
||||
if (success) AudioMixer?.Complete();
|
||||
else AudioMixer?.Cancel();
|
||||
if (!success)
|
||||
{
|
||||
MarkCancelled();
|
||||
@@ -1011,7 +1021,7 @@ internal class RenderManager : MonoBehaviour
|
||||
|
||||
_frameReader?.Dispose();
|
||||
ResetFrameHookState();
|
||||
AudioMixer?.Reset(); AudioMixer = null;
|
||||
AudioMixer?.Dispose(); AudioMixer = null;
|
||||
SyncCalculator = null;
|
||||
|
||||
AudioSpectrumGenerator.Clear();
|
||||
|
||||
Reference in new issue
Block a user