diff --git a/OpenUtau.Core/Util/TimeAxis.cs b/OpenUtau.Core/Util/TimeAxis.cs
index c7b528265..d7523ecd8 100644
--- a/OpenUtau.Core/Util/TimeAxis.cs
+++ b/OpenUtau.Core/Util/TimeAxis.cs
@@ -147,6 +147,18 @@ public double MsBetweenTickPos(double tickPos, double tickEnd) {
return TickPosToMsPos(tickEnd) - TickPosToMsPos(tickPos);
}
+ ///
+ /// Convert ms duration to tick at a given reference tick position
+ ///
+ /// Duration in ms, positive value means starting from refTickPos, negative value means ending at refTickPos
+ /// Reference tick position
+ /// Duration in ticks
+ public int MsToTickAt(double offsetMs, int refTickPos) {
+ return TicksBetweenMsPos(
+ TickPosToMsPos(refTickPos),
+ TickPosToMsPos(refTickPos) + offsetMs);
+ }
+
public void TickPosToBarBeat(int tick, out int bar, out int beat, out int remainingTicks) {
var segment = timeSigSegments.First(seg => seg.tickPos == tick || seg.tickEnd > tick); // TODO: optimize
bar = segment.barPos + (tick - segment.tickPos) / segment.ticksPerBar;
diff --git a/OpenUtau.Plugin.Builtin/ChineseCVVCPhonemizer.cs b/OpenUtau.Plugin.Builtin/ChineseCVVCPhonemizer.cs
index 3d8db1766..d207506e8 100644
--- a/OpenUtau.Plugin.Builtin/ChineseCVVCPhonemizer.cs
+++ b/OpenUtau.Plugin.Builtin/ChineseCVVCPhonemizer.cs
@@ -54,13 +54,14 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
return MakeSimpleResult(oto.Alias);
}
int vcLen = 120;
+ int endTick = notes[^1].position + notes[^1].duration;
if (singer.TryGetMappedOto(lyric, notes[0].tone + attr1.toneShift, attr1.voiceColor, out var cvOto)) {
- vcLen = MsToTick(cvOto.Preutter);
+ vcLen = -timeAxis.MsToTickAt(-cvOto.Preutter, endTick);
if (cvOto.Overlap == 0 && vcLen < 120) {
vcLen = Math.Min(120, vcLen * 2); // explosive consonant with short preutter.
}
if (cvOto.Overlap < 0) {
- vcLen = MsToTick(cvOto.Preutter - cvOto.Overlap);
+ vcLen = -timeAxis.MsToTickAt(-(cvOto.Preutter - cvOto.Overlap), endTick);
}
}