From e7912b3be1fd885c65a48e9c76d1a90411246180 Mon Sep 17 00:00:00 2001 From: oxygen-dioxide <54425948+oxygen-dioxide@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:06:11 +0800 Subject: [PATCH] fix audio timing bug --- OpenUtau.Core/DiffSinger/DiffSingerRenderer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenUtau.Core/DiffSinger/DiffSingerRenderer.cs b/OpenUtau.Core/DiffSinger/DiffSingerRenderer.cs index 379d10536..5b216faa5 100644 --- a/OpenUtau.Core/DiffSinger/DiffSingerRenderer.cs +++ b/OpenUtau.Core/DiffSinger/DiffSingerRenderer.cs @@ -112,8 +112,8 @@ float[] InvokeDiffsinger(RenderPhrase phrase,int speedup) { var vocoder = singer.getVocoder(); var frameMs = vocoder.frameMs(); var frameSec = frameMs / 1000; - int headFrames = (int)(headMs / frameMs); - int tailFrames = (int)(tailMs / frameMs); + int headFrames = (int)Math.Round(headMs / frameMs); + int tailFrames = (int)Math.Round(tailMs / frameMs); var result = Layout(phrase); //acoustic //mel = session.run(['mel'], {'tokens': tokens, 'durations': durations, 'f0': f0, 'speedup': speedup})[0] @@ -128,11 +128,11 @@ float[] InvokeDiffsinger(RenderPhrase phrase,int speedup) { .Select(x => (long)(singer.phonemes.IndexOf(x))) .ToList(); var durations = phrase.phones - .Select(p => (int)(p.endMs / frameMs) - (int)(p.positionMs / frameMs))//prevent cumulative error + .Select(p => (int)Math.Round(p.endMs / frameMs) - (int)Math.Round(p.positionMs / frameMs))//prevent cumulative error .Prepend(headFrames) .Append(tailFrames) .ToList(); - var totalFrames = (int)(durations.Sum()); + int totalFrames = durations.Sum(); float[] f0 = DiffSingerUtils.SampleCurve(phrase, phrase.pitches, 0, frameMs, totalFrames, headFrames, tailFrames, x => MusicMath.ToneToFreq(x * 0.01)) .Select(f => (float)f).ToArray();