Skip to content

Commit

Permalink
Pitch Experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
rokujyushi committed Apr 4, 2024
1 parent a57e59e commit f227b3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion OpenUtau.Core/Voicevox/Phonemizers/VoicevoxPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 9 additions & 3 deletions OpenUtau.Core/Voicevox/VoicevoxRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ public Task<RenderResult> 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 {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions OpenUtau.Core/Voicevox/VoicevoxUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ 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<double, double> convert) {
const int interval = 5;
double interval = curve.Length / length;
var result = new double[length];
if (curve == null) {
Array.Fill(result, defaultValue);
return result;
}

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]);
}
Expand Down

0 comments on commit f227b3d

Please sign in to comment.