SHA256
Refactor Audio Calculation
This commit is contained in:
5 files changed
+155
-86
No files matched your search
+19
-12
@@ -49,6 +49,9 @@ namespace ADOFAIRenderer.Core
|
||||
public double unscaledTimeBase;
|
||||
public double dspTimeBase;
|
||||
public int frameCountBase;
|
||||
|
||||
public OfflineAudioMixer? AudioMixer { get; private set; }
|
||||
public AudioSyncCalculator SyncCalculator { get; private set; } = null!;
|
||||
|
||||
private FrameReader? _frameReader;
|
||||
public bool renderCheck = true;
|
||||
@@ -432,9 +435,14 @@ namespace ADOFAIRenderer.Core
|
||||
{
|
||||
AudioSpectrumGenerator.Initialize(scrConductor.instance.song.clip);
|
||||
}
|
||||
|
||||
if (Configuration.RenderAudio)
|
||||
{
|
||||
OfflineAudioMixer.InitializeBGM(scrConductor.instance.song.clip, Configuration.AudioChannels, Configuration.AudioSampleRate);
|
||||
AudioMixer = new OfflineAudioMixer(Configuration.AudioChannels, Configuration.AudioSampleRate);
|
||||
AudioMixer.InitializeBGM(scrConductor.instance.song.clip);
|
||||
|
||||
var effectiveVideoFps = Math.Min(Configuration.VideoFPS, Configuration.RenderFPS);
|
||||
SyncCalculator = new AudioSyncCalculator(Configuration.AudioSampleRate, effectiveVideoFps);
|
||||
}
|
||||
|
||||
scrConductor.instance.song.clip = null;
|
||||
@@ -581,19 +589,17 @@ namespace ADOFAIRenderer.Core
|
||||
|
||||
if (Configuration.RenderAudio)
|
||||
{
|
||||
int frameIdx = (int)(passCount - 1);
|
||||
double effectiveVideoFps = Math.Min(Configuration.VideoFPS, Configuration.RenderFPS);
|
||||
double frameStartTime = frameIdx / effectiveVideoFps;
|
||||
double frameEndTime = (frameIdx + 1) / effectiveVideoFps;
|
||||
var frameIdx = (int)(passCount - 1);
|
||||
var effectiveVideoFps = Math.Min(Configuration.VideoFPS, Configuration.RenderFPS);
|
||||
var frameTime = frameIdx / effectiveVideoFps;
|
||||
|
||||
int sampleRate = Configuration.AudioSampleRate;
|
||||
int channels = Configuration.AudioChannels;
|
||||
int samplesNeeded = (int)(Math.Floor(frameEndTime * sampleRate) - Math.Floor(frameStartTime * sampleRate));
|
||||
var channels = Configuration.AudioChannels;
|
||||
var samplesNeeded = SyncCalculator.GetNextFrameSamples();
|
||||
|
||||
float[] audioBuffer = ArrayPool<float>.Shared.Rent(samplesNeeded * channels);
|
||||
var audioBuffer = ArrayPool<float>.Shared.Rent(samplesNeeded * channels);
|
||||
try
|
||||
{
|
||||
OfflineAudioMixer.GenerateAudioForFrame(audioBuffer, samplesNeeded, frameStartTime, dspTimeBase);
|
||||
AudioMixer?.GenerateAudioForFrame(audioBuffer, samplesNeeded, frameTime, dspTimeBase);
|
||||
videoFFmpeg.WriteAudioSamples(audioBuffer, samplesNeeded);
|
||||
}
|
||||
finally
|
||||
@@ -798,9 +804,10 @@ namespace ADOFAIRenderer.Core
|
||||
}
|
||||
|
||||
_frameReader?.Dispose();
|
||||
OfflineAudioMixer.Reset();
|
||||
ADOBase.loader.LoadSceneWithTransition(WipeDirection.StartsFromRight, "scnEditor");
|
||||
AudioMixer?.Reset(); AudioMixer = null;
|
||||
SyncCalculator.Reset();
|
||||
|
||||
ADOBase.loader.LoadSceneWithTransition(WipeDirection.StartsFromRight, "scnEditor");
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user