Skip to content

Commit f7ba9a4

Browse files
Merge pull request #10 from oxygen-dioxide/diffsinger-nomidi-directml
tailMs and consonant duration limit
2 parents f4f458c + a0a7c18 commit f7ba9a4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

OpenUtau.Core/DiffSinger/DiffSingerMandarinPhonemizer.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
7171
//使用vogen的辅音时间
7272
Result VogenResult = base.Process(notes, prev, next, prevNeighbour, nextNeighbour, prevs);
7373
//辅音长度至少为1帧
74+
int consonantPos = Math.Min(VogenResult.phonemes[0].position, -frameTick);
75+
//辅音长度不能超过上一音符时长的2/3
76+
if (prevNeighbour != null) {
77+
consonantPos = Math.Max(consonantPos, -prevNeighbour.Value.duration * 2 / 3);
78+
}
7479
return new Result {
7580
phonemes = new Phoneme[] {
76-
new Phoneme {phoneme = phones.Item1,
77-
position = Math.Min(VogenResult.phonemes[0].position,-frameTick)},
81+
new Phoneme {phoneme = phones.Item1, position = consonantPos},
7882
new Phoneme {phoneme = phones.Item2, position = 0}
7983
},
8084
};

OpenUtau.Core/DiffSinger/DiffSingerRenderer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace OpenUtau.Core.DiffSinger {
1717
public class DiffSingerRenderer : IRenderer {
1818
const float headMs = 0;
19-
const float tailMs = 0;
19+
const float tailMs = 500;
2020

2121
static readonly HashSet<string> supportedExp = new HashSet<string>(){
2222
Format.Ustx.DYN,
@@ -109,10 +109,12 @@ float[] InvokeDiffsinger(RenderPhrase phrase,int speedup) {
109109
//speedup:加速倍数
110110
var tokens = phrase.phones
111111
.Select(p => p.phoneme)
112+
.Append("SP")
112113
.Select(x => (long)(singer.phonemes.IndexOf(x)))
113114
.ToList();
114115
var durations = phrase.phones
115116
.Select(p => (long)(p.endMs / frameMs) - (long)(p.positionMs / frameMs))//防止累计误差
117+
.Append(tailFrames)
116118
.ToList();
117119
var totalFrames = (int)(durations.Sum());
118120
var f0 = SampleCurve(phrase, phrase.pitches, 0, totalFrames, headFrames, tailFrames, x => MusicMath.ToneToFreq(x * 0.01));
@@ -167,8 +169,8 @@ double[] SampleCurve(RenderPhrase phrase, float[] curve, double defaultValue, in
167169
}
168170
}
169171
//填充头尾
170-
Array.Fill(result, defaultValue, 0, headFrames);
171-
Array.Fill(result, defaultValue, length - tailFrames, tailFrames);
172+
Array.Fill(result, convert(curve[0]), 0, headFrames);
173+
Array.Fill(result, convert(curve.Last()), length - tailFrames, tailFrames);
172174
return result;
173175
}
174176

0 commit comments

Comments
 (0)