Skip to content

Commit

Permalink
Merge pull request #1161 from oxygen-dioxide/zhcvvc-tempo-change-timing
Browse files Browse the repository at this point in the history
ZH CVVC: Fix note timing after tempo change
  • Loading branch information
stakira authored Jun 9, 2024
2 parents e6ca55b + 1c5b8f4 commit 54659b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions OpenUtau.Core/Util/TimeAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ public double MsBetweenTickPos(double tickPos, double tickEnd) {
return TickPosToMsPos(tickEnd) - TickPosToMsPos(tickPos);
}

/// <summary>
/// Convert ms duration to tick at a given reference tick position
/// </summary>
/// <param name="durationMs">Duration in ms, positive value means starting from refTickPos, negative value means ending at refTickPos</param>
/// <param name="refTickPos">Reference tick position</param>
/// <returns>Duration in ticks</returns>
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;
Expand Down
5 changes: 3 additions & 2 deletions OpenUtau.Plugin.Builtin/ChineseCVVCPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 54659b5

Please sign in to comment.