From f227b3dececc191f82a17f7f16ba6cd30132030b Mon Sep 17 00:00:00 2001 From: rokujyushi Date: Thu, 4 Apr 2024 23:48:21 +0900 Subject: [PATCH] Pitch Experiment --- .../Voicevox/Phonemizers/VoicevoxPhonemizer.cs | 2 +- OpenUtau.Core/Voicevox/VoicevoxRenderer.cs | 12 +++++++++--- OpenUtau.Core/Voicevox/VoicevoxUtils.cs | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/OpenUtau.Core/Voicevox/Phonemizers/VoicevoxPhonemizer.cs b/OpenUtau.Core/Voicevox/Phonemizers/VoicevoxPhonemizer.cs index 2cd597251..a1b24523c 100644 --- a/OpenUtau.Core/Voicevox/Phonemizers/VoicevoxPhonemizer.cs +++ b/OpenUtau.Core/Voicevox/Phonemizers/VoicevoxPhonemizer.cs @@ -19,7 +19,7 @@ public override void SetSinger(USinger singer) { } } - public override void SetUp(Note[][] notes) { + public override void SetUp(Note[][] notes, UProject project, UTrack track) { partResult.Clear(); foreach(var lyric in notes) { lyric[0].lyric = lyric[0].lyric.Normalize(); diff --git a/OpenUtau.Core/Voicevox/VoicevoxRenderer.cs b/OpenUtau.Core/Voicevox/VoicevoxRenderer.cs index 180ad6c86..d6dad03f4 100644 --- a/OpenUtau.Core/Voicevox/VoicevoxRenderer.cs +++ b/OpenUtau.Core/Voicevox/VoicevoxRenderer.cs @@ -84,8 +84,14 @@ public Task Render(RenderPhrase phrase, Progress progress, int tra string baseSingerID = VoicevoxUtils.getBaseSingerID(singer); vvNotes = VoicevoxUtils.VoicevoxVoiceBase(qNotes, baseSingerID); - //Compatible with toneShift (key shift), for adjusting the range of tones when synthesizing - vvNotes.f0 = vvNotes.f0.Select(f0 => f0 = f0 * Math.Pow(2, ((phrase.phones[0].toneShift * -1) / 12d))).ToList(); + if (!phrase.phones[0].direct) { + double frameMs = 1 / 10d * VoicevoxUtils.fps; + vvNotes.f0 = VoicevoxUtils.SampleCurve(phrase, phrase.pitches, 0, frameMs, vvNotes.volume.Count(), 0, 0, x => MusicMath.ToneToFreq(x * 0.01)).ToList(); + } else { + //Compatible with toneShift (key shift), for adjusting the range of tones when synthesizing + vvNotes.f0 = vvNotes.f0.Select(f0 => f0 = f0 * Math.Pow(2, ((phrase.phones[0].toneShift * -1) / 12d))).ToList(); + } + //Volume parameter for synthesis. Scheduled to be revised vvNotes.volume = vvNotes.volume.Select(vol => vol = vol * phrase.phones[0].volume).ToList(); } else { @@ -201,7 +207,7 @@ static VoicevoxNote PhraseToVoicevoxNotes(RenderPhrase phrase) { int vvTotalFrames = -(headFrames + tailFrames); vnotes.phonemes.ForEach(x => vvTotalFrames += x.frame_length); - double frameMs = 1 / 1000d * VoicevoxUtils.fps; + double frameMs = VoicevoxUtils.fps;//1 / 1000d * int totalFrames = (int)(vvTotalFrames / VoicevoxUtils.fps * 1000d); int frameRatio = vvTotalFrames / totalFrames; const int pitchInterval = 5; diff --git a/OpenUtau.Core/Voicevox/VoicevoxUtils.cs b/OpenUtau.Core/Voicevox/VoicevoxUtils.cs index 17b7c56e4..efdd3b9fe 100644 --- a/OpenUtau.Core/Voicevox/VoicevoxUtils.cs +++ b/OpenUtau.Core/Voicevox/VoicevoxUtils.cs @@ -113,7 +113,7 @@ public static VoicevoxQueryMain NoteGroupsToVoicevox(Note[][] notes, TimeAxis ti } public static double[] SampleCurve(RenderPhrase phrase, float[] curve, double defaultValue, double frameMs, int length, int headFrames, int tailFrames, Func convert) { - const int interval = 5; + double interval = curve.Length / length; var result = new double[length]; if (curve == null) { Array.Fill(result, defaultValue); @@ -121,9 +121,9 @@ public static double[] SampleCurve(RenderPhrase phrase, float[] curve, double de } for (int i = 0; i < length; i++) { - double posMs = phrase.positionMs - phrase.leadingMs + i * frameMs; + double posMs = phrase.positionMs - phrase.leadingMs + (i * interval); int ticks = phrase.timeAxis.MsPosToTickPos(posMs) - (phrase.position - phrase.leading); - int index = Math.Max(0, (int)((double)ticks / interval)); + int index = Math.Max(0, (int)((double)ticks )); if (index < curve.Length) { result[i] = convert(curve[index]); }