Skip to content

Commit

Permalink
Adjust VC and starting C to tempo
Browse files Browse the repository at this point in the history
  • Loading branch information
lottev1991 committed May 29, 2024
1 parent 9bce80d commit 3dfdab0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions OpenUtau.Plugin.Builtin/JapanesePresampPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
&& !presamp.Priorities.Contains(phoneme.Consonant)) {
if (checkOtoUntilHit(new List<string> { $"-{vcvpad}{phoneme.Consonant}" }, note, 2, out var cOto, out var color)
&& checkOtoUntilHit(new List<string> { currentLyric }, note, out var oto)) {

int endTick = notes[^1].position + notes[^1].duration;
var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;
var cLength = Math.Max(30, MsToTick(oto.Preutter) * (attr.consonantStretchRatio ?? 1));
var cLength = Math.Max(30, -MsToTickAt(-oto.Preutter, endTick) * (attr.consonantStretchRatio ?? 1));

if (prevNeighbour != null) {
cLength = Math.Min(prevNeighbour.Value.duration / 2, cLength);
Expand Down Expand Up @@ -327,13 +327,14 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
}
if (!string.IsNullOrEmpty(vcPhoneme)) {
int vcLength = 120;
int endTick = notes[^1].position + notes[^1].duration;
var nextAttr = nextNeighbour.Value.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;
if (singer.TryGetMappedOto(nextLyric, nextNeighbour.Value.tone + nextAttr.toneShift, nextAttr.voiceColor, out var nextOto)) {
// If overlap is a negative value, vcLength is longer than Preutter
if (nextOto.Overlap < 0) {
vcLength = MsToTick(nextOto.Preutter - nextOto.Overlap);
vcLength = -MsToTickAt(-(nextOto.Preutter - nextOto.Overlap), endTick);
} else {
vcLength = MsToTick(nextOto.Preutter);
vcLength = -MsToTickAt(-nextOto.Preutter, endTick);
}
}
// Minimam is 30 tick, maximum is half of note
Expand Down Expand Up @@ -412,5 +413,17 @@ private bool checkOtoUntilHit(List<string> input, Note note, int index, out UOto
}
return false;
}

/// <summary>
/// Convert ms to tick at a given reference tick position
/// </summary>
/// <param name="offsetMs">Duration in ms</param>
/// <param name="refTick">Reference tick position</param>
/// <returns>Duration in ticks</returns>
public int MsToTickAt(double offsetMs, int refTick) {
return timeAxis.TicksBetweenMsPos(
timeAxis.TickPosToMsPos(refTick),
timeAxis.TickPosToMsPos(refTick) + offsetMs);
}
}
}

0 comments on commit 3dfdab0

Please sign in to comment.