Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZH CVVC: Fix note timing after tempo change #1161

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading