20 コミット
作成者 SHA1 メッセージ 日付
routersys 1824f9faaf バージョンをv1.6.2へ合わせる
リリース / build-and-release (workflow_dispatch) Actions がタグ v1.6.2 のコミットから作成しました
2026-08-22 19:42:23 +09:00
routersys 41b813e2bb 音程の伸ばしを句の切れ目で決める 2026-08-22 19:29:49 +09:00
routersys e1fa384f83 音程曲線の先頭の伸ばしと1点の制御点を直す 2026-08-22 19:12:16 +09:00
routersys d455ed4659 音程を句全体の曲線として組み立てる 2026-08-22 18:37:08 +09:00
routersys eb90cfd9c6 バージョンをv1.6.1へ合わせる
リリース / build-and-release (workflow_dispatch) Actions がタグ v1.6.1 のコミットから作成しました
2026-08-22 13:40:45 +09:00
github-actions[bot] eaaebb43fe バージョンをv1.6.0へ合わせる 2026-08-22 04:36:14 +00:00
routersys 2baedff12c 先行発声を縮めた分だけ音源を読み飛ばす
リリース / build-and-release (workflow_dispatch) Actions がタグ v1.6.0 のコミットから作成しました
2026-08-22 13:16:15 +09:00
routersys 9e114cc414 子音部を縮めず原音の速さで鳴らす 2026-08-22 12:48:35 +09:00
routersys 316b4fe1b6 音符ごとに峰値を揃える自動利得を加える 2026-08-22 12:18:36 +09:00
routersys 0a2a9a2bf6 重ね合わせの重みを振幅として掛ける 2026-08-22 11:49:53 +09:00
routersys fa1758de0d 先行発声の制限規則を規則ごとに試験する 2026-08-22 11:23:56 +09:00
routersys fe5801cefe 子音速度を先行発声と重なりへ反映する 2026-08-22 10:57:02 +09:00
routersys 63198039dc 音符の繋ぎの先行発声をUTAUの制限規則へ合わせる 2026-08-22 10:51:04 +09:00
routersys ba001e1d23 USTの短すぎる音符で拍の誤差が積み重なるのを直す 2026-08-22 10:00:25 +09:00
routersys 26d3f2007e USTの長すぎる音符で以降の拍がずれるのを直す 2026-08-22 09:56:48 +09:00
routersys 5328d1efe3 USTのDeltaとDurationの判定を1つへ揃える 2026-08-22 09:47:56 +09:00
routersys 6dc3b7f4f7 サムネイル画像の追加 2026-08-21 14:25:21 +09:00
routersys 36169bc285 説明書の見出しを内容へ合わせる 2026-08-21 14:14:40 +09:00
routersys b997849ece 訂正コミットの文言が欠けるのを直す 2026-08-21 11:03:04 +09:00
github-actions[bot] fbf5745ff7 バージョンを 2026-08-21 02:00:21 +00:00
17個のファイルの変更、560行の追加、66行の削除

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -1,5 +1,5 @@
========================================
UTAU for YMM4 v1.4.1
UTAU for YMM4 v1.6.2
========================================
YukkuriMovieMaker4(YMM4)上で動作する、UTAU 音源から歌声を合成する
音声合成プラグインです。
+1 -1
ファイルの表示
@@ -122,7 +122,7 @@ jobs:
git add -A
$pending = git diff --cached --name-only
if ($pending) {
git commit -m "バージョンを$tagへ合わせる" --quiet
git commit -m "バージョンを${tag}へ合わせる" --quiet
git push origin HEAD:main
Write-Host "main へ訂正を反映しました"
} else {
+4 -2
ファイルの表示
@@ -11,6 +11,8 @@ YukkuriMovieMaker4(YMM4)上で動作する、UTAU 音源から歌声を合
単独音・連続音・CVVC のいずれの音源にも対応し、UST ファイルの読み込みにも対応します。
セリフのかなから組み立てたノートは、ピアノロールのノートエディターで編集できます。
![Image](https://github.com/routersys/YMM4-UTAU/blob/main/docs/UTAU.png)
---
## 目次
@@ -24,7 +26,7 @@ YukkuriMovieMaker4(YMM4)上で動作する、UTAU 音源から歌声を合
- [3. UST ファイルの読み込み](#3-ust-ファイルの読み込み)
- [4. ノートエディター](#4-ノートエディター)
- [5. WORLD による合成](#5-world-による合成)
- [6. 解析キャッシュ](#6-解析キャッシュ)
- [6. 解析と合成の再利用](#6-解析と合成の再利用)
5. [音程記法](#音程記法)
6. [パラメータ一覧](#パラメータ一覧)
7. [ノートの項目一覧](#ノートの項目一覧)
@@ -135,7 +137,7 @@ YukkuriMovieMaker4(YMM4)上で動作する、UTAU 音源から歌声を合
出力は 16 ビットのモノラル WAV です。ノートの母音から口パクに使う情報も作ります。
### 6. 解析キャッシュ
### 6. 解析と合成の再利用
分析結果は、音声ファイルの場所と更新日時と読み込む範囲と推定方法を鍵にしてメモリへ保持します。2 回目以降の合成では分析をやり直しません。上限は既定で 512MB で、64MB から 4096MB まで設定できます。上限を超えると古い物から捨てます。設定画面から破棄することもできます。複数の音声ファイルの分析は複数のコアで並列に行います。
+79 -2
ファイルの表示
@@ -475,10 +475,66 @@ public sealed class UnitTimingBuilderTests
public void PreutteranceIsScaledDownWhenThePreviousNoteIsTooShort()
{
var timings = UnitTimingBuilder.Build([CreateUnit(0.0, 20.0, 0.0, 0.0), CreateUnit(20.0, 200.0, 80.0, 40.0)]);
Assert.Equal(-20.0, timings[1].AudioStartMilliseconds, 9);
Assert.Equal(20.0, timings[1].FadeInMilliseconds, 9);
Assert.Equal(5.0, timings[1].AudioStartMilliseconds, 9);
Assert.Equal(7.5, timings[1].FadeInMilliseconds, 9);
}
[Fact]
public void APlosiveKeepsOneTenthOfThePreviousNote()
{
var timings = UnitTimingBuilder.Build([CreateUnit(0.0, 100.0, 0.0, 0.0), CreateUnit(100.0, 200.0, 200.0, -10.0)]);
Assert.Equal(10.0, timings[1].AudioStartMilliseconds, 9);
Assert.Equal(UTAUNote.DefaultFadeInMilliseconds, timings[1].FadeInMilliseconds, 9);
}
[Fact]
public void ARestLimitsThePreutteranceToTheGap()
{
var rest = new PhonemeUnit(new UTAUNote { Lyric = UTAUNote.RestLyric }, null, "R", 100.0, 30.0, 100.0, 30.0, 60);
var timings = UnitTimingBuilder.Build([CreateUnit(0.0, 100.0, 0.0, 0.0), rest, CreateUnit(130.0, 200.0, 80.0, 40.0)]);
Assert.Equal(100.0, timings[1].AudioStartMilliseconds, 9);
}
[Fact]
public void ANegativeOverlapLeavesAGapBeforeTheNextUnit()
{
var timings = UnitTimingBuilder.Build([CreateUnit(0.0, 200.0, 0.0, 0.0), CreateUnit(200.0, 200.0, 60.0, -10.0)]);
Assert.Equal(130.0, timings[0].AudioEndMilliseconds, 9);
Assert.Equal(140.0, timings[1].AudioStartMilliseconds, 9);
}
[Fact]
public void ANegativeOverlapIsLimitedByTheDefaultRelease()
{
var timings = UnitTimingBuilder.Build([CreateUnit(0.0, 100.0, 0.0, 0.0), CreateUnit(100.0, 200.0, 20.0, -60.0)]);
Assert.Equal(35.0, timings[0].AudioEndMilliseconds, 9);
Assert.Equal(80.0, timings[1].AudioStartMilliseconds, 9);
}
[Fact]
public void ThePreutteranceNeverExceedsThePreviousNote()
{
var timings = UnitTimingBuilder.Build([CreateUnit(0.0, 30.0, 10.0, 0.0), CreateUnit(30.0, 200.0, 100.0, 80.0)]);
Assert.Equal(0.0, timings[1].AudioStartMilliseconds, 9);
Assert.Equal(24.0, timings[1].FadeInMilliseconds, 9);
}
[Fact]
public void ALimitedPreutteranceSkipsIntoTheSample()
{
var timings = UnitTimingBuilder.Build([CreateUnit(0.0, 20.0, 0.0, 0.0), CreateUnit(20.0, 200.0, 80.0, 40.0)]);
var timing = timings[1];
var map = TimeMap.Create(0.0, 200.0, 400.0, timing.RenderLengthMilliseconds + timing.SkipMilliseconds, 100.0, StretchMode.Stretch);
var atNoteStart = timing.Unit.StartMilliseconds - timing.AudioStartMilliseconds + timing.SkipMilliseconds;
Assert.Equal(65.0, timing.SkipMilliseconds, 9);
Assert.Equal(80.0, map.Map(atNoteStart), 9);
}
[Fact]
public void AnUnlimitedPreutteranceSkipsNothing()
=> Assert.Equal(0.0, Assert.Single(UnitTimingBuilder.Build([CreateUnit(100.0, 200.0, 40.0, 20.0)])).SkipMilliseconds, 9);
[Fact]
public void SilentUnitsAreNotRendered()
{
@@ -537,6 +593,27 @@ public sealed class UnitTimingBuilderTests
Assert.Equal(60.0, Assert.Single(UnitTimingBuilder.Build([unit])).AudioStartMilliseconds, 9);
}
[Fact]
public void TheConsonantVelocityScalesThePreutterance()
{
var unit = CreateUnit(100.0, 200.0, 40.0, 20.0);
unit.Note.Velocity = 200.0;
var timing = Assert.Single(UnitTimingBuilder.Build([unit]));
Assert.Equal(80.0, timing.AudioStartMilliseconds, 9);
}
[Fact]
public void AnOverriddenPreutteranceIgnoresTheConsonantVelocity()
{
var unit = CreateUnit(100.0, 200.0, 40.0, 20.0);
unit.Note.PreutteranceOverride = 10.0;
unit.Note.Velocity = 200.0;
var timing = Assert.Single(UnitTimingBuilder.Build([unit]));
Assert.Equal(90.0, timing.AudioStartMilliseconds, 9);
}
[Fact]
public void EmptyInputProducesNoTimings()
=> Assert.Empty(UnitTimingBuilder.Build([]));
+22
ファイルの表示
@@ -124,6 +124,28 @@ public sealed class UtauRendererTests : IDisposable
static double Peak(double[] samples) => samples.Length == 0 ? 0.0 : samples.Max(Math.Abs);
VoiceBank BankAtLevel(string name, double level)
{
var path = Path.Combine(directory, name);
Directory.CreateDirectory(path);
TestVoiceBank.WriteText(path, VoiceBankLoader.CharacterFileName, "name=試験音源\r\n");
TestVoiceBank.WriteText(path, VoiceBankLoader.OtoFileName, "a.wav=あ,50,80,-500,100,40");
TestVoiceBank.WriteSample(path, "a.wav", [.. TestVoiceBank.CreateVowel().Select(x => x * level)]);
return VoiceBankLoader.Load(name, path);
}
const double QuietLevel = 0.25;
const double PeakCompression = 0.86;
[Fact]
public void AQuietSampleIsLiftedTowardTheSamePeak()
{
var loud = Peak(Render(BankAtLevel("loud", 1.0), "<!C4:1/4>あ").Samples);
var quiet = Peak(Render(BankAtLevel("quiet", QuietLevel), "<!C4:1/4>あ").Samples);
Assert.Equal(Math.Pow(QuietLevel, 1.0 - PeakCompression), quiet / loud, 2);
}
static double MeasureFundamental(RenderResult result)
{
using var arena = new WorldArena();
+95 -6
ファイルの表示
@@ -60,19 +60,26 @@ public sealed class TimeMapTests
}
[Fact]
public void StretchModeAlsoCompresses()
public void StretchModeNeverRunsFasterThanTheSource()
{
var map = TimeMap.Create(0.0, 0.0, 400.0, 100.0, 100.0, StretchMode.Stretch);
Assert.Equal(200.0, map.Map(50.0), 9);
Assert.Equal(400.0, map.Map(100.0), 9);
Assert.Equal(50.0, map.Map(50.0), 9);
Assert.Equal(100.0, map.Map(100.0), 9);
}
[Fact]
public void ConsonantIsCompressedWhenTheOutputIsShorterThanTheConsonant()
public void ConsonantKeepsItsSpeedWhenTheOutputIsShorter()
{
var map = TimeMap.Create(0.0, 200.0, 400.0, 50.0, 100.0, StretchMode.Loop);
Assert.Equal(50.0, map.ConsonantOutputLength, 9);
Assert.Equal(200.0, map.Map(50.0), 9);
Assert.Equal(200.0, map.ConsonantOutputLength, 9);
Assert.Equal(50.0, map.Map(50.0), 9);
}
[Fact]
public void TheConsonantVelocityScalesTheConsonantOutput()
{
Assert.Equal(100.0, TimeMap.Create(0.0, 200.0, 400.0, 1000.0, 200.0, StretchMode.Loop).ConsonantOutputLength, 9);
Assert.Equal(400.0, TimeMap.Create(0.0, 200.0, 400.0, 1000.0, 0.0, StretchMode.Loop).ConsonantOutputLength, 9);
}
[Fact]
@@ -89,6 +96,24 @@ public sealed class TimeMapTests
public sealed class SpectrumTransformTests
{
[Fact]
public void AMixingWeightAndAGainScaleThePowerAlike()
{
var scaled = SpectrumTransform.ToPower(0.25 * SpectrumTransform.ToAmplitude(4.0));
var gained = new[] { 4.0 };
SpectrumTransform.ApplyGain(gained, 0.25);
Assert.Equal(gained[0], scaled, 12);
}
[Fact]
public void MixingWeightsThatSumToOneKeepTheLevel()
{
var sum = 0.4 * SpectrumTransform.ToAmplitude(9.0) + 0.6 * SpectrumTransform.ToAmplitude(9.0);
Assert.Equal(9.0, SpectrumTransform.ToPower(sum), 12);
}
static double[] CreatePeak(int size, int index)
{
var spectrum = new double[size];
@@ -469,3 +494,67 @@ public sealed class AnalysisCacheTests
Assert.Equal(0, cache.UsedBytes);
}
}
public sealed class PitchTrackTests
{
static PhonemeUnit Unit(double start, double length, int tone, double preutterance, double overlap)
=> new(
new UTAUNote { Lyric = "a", Tone = tone },
new OtoEntry(@"C:ank", "a.wav", "a", 0.0, 0.0, 0.0, preutterance, overlap),
"a",
start,
length,
start,
length,
tone);
static PitchTrack Track(params PhonemeUnit[] units)
=> PitchTrack.Create(UnitTimingBuilder.Build(units), 0.0, 5.0, 80);
[Fact]
public void ThePitchStepsAtTheNoteBoundary()
{
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), Unit(200.0, 200.0, 72, 80.0, 40.0));
Assert.Equal(6000.0, track.CentsAt(39), 9);
Assert.Equal(7200.0, track.CentsAt(40), 9);
for (var frame = 0; frame < 80; frame++)
Assert.True(track.CentsAt(frame) is 6000.0 or 7200.0);
}
[Fact]
public void TheOverlapKeepsThePitchOfThePreviousNote()
{
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), Unit(200.0, 200.0, 72, 80.0, 40.0));
Assert.Equal(6000.0, track.CentsAt(24), 9);
}
[Fact]
public void APhraseOpeningNoteExtendsItsFirstPointBackToItsAudioStart()
{
var second = Unit(300.0, 200.0, 72, 80.0, 40.0);
second.Note.LengthTicks = 240;
second.Note.PitchPoints.Add(new PitchPoint(-50, 500.0));
second.Note.PitchPoints.Add(new PitchPoint(0, 0.0));
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), second);
Assert.Equal(7200.0, track.CentsAt(43), 9);
Assert.Equal(7700.0, track.CentsAt(44), 9);
Assert.Equal(7200.0, track.CentsAt(60), 9);
}
[Fact]
public void APortamentoReachesAcrossThePreviousNote()
{
var second = Unit(200.0, 200.0, 72, 80.0, 40.0);
second.Note.LengthTicks = 240;
second.Note.PitchPoints.Add(new PitchPoint(-120, -1200.0));
second.Note.PitchPoints.Add(new PitchPoint(0, 0.0));
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), second);
Assert.Equal(6000.0, track.CentsAt(20), 9);
Assert.Equal(6600.0, track.CentsAt(30), 9);
Assert.Equal(7200.0, track.CentsAt(40), 9);
}
}
+47
ファイルの表示
@@ -388,6 +388,53 @@ public sealed class UstTests
Assert.Equal(79520, rests.Sum(x => x.LengthTicks));
}
[Fact]
public void ANoteLongerThanTheNoteLimitKeepsTheTimeline()
{
var result = Import(Document(
"Tempo=120.00",
["Length=32640", "Lyric=a", "NoteNum=60"],
["Length=480", "Lyric=i", "NoteNum=62"]));
Assert.Equal([30720, 1920, 480], result.Notes.Select(x => x.LengthTicks).ToArray());
}
[Fact]
public void ARestLongerThanTheNoteLimitKeepsTheTimeline()
{
var result = Import(Document(
"Tempo=120.00",
Sung(),
["Length=32640", "Lyric=R", "NoteNum=60"],
Sung("Lyric=i")));
Assert.Equal([480, 30720, 1920, 480], result.Notes.Select(x => x.LengthTicks).ToArray());
}
[Fact]
public void ARestShorterThanTheNoteLimitDoesNotPileUpDelay()
{
var result = Import(Document(
"Tempo=120.00",
Sung(),
["Length=10", "Lyric=R", "NoteNum=60"],
Sung("Lyric=i"),
["Length=10", "Lyric=R", "NoteNum=60"],
Sung("Lyric=u")));
Assert.Equal([480, 15, 475, 15, 475], result.Notes.Select(x => x.LengthTicks).ToArray());
}
[Fact]
public void ADurationWithoutADeltaFollowsTheScoreLength()
{
var text = "[#SETTING]\r\nTempo=120.00\r\n"
+ "[#0000]\r\nDuration=240\r\nLength=480\r\nLyric=a\r\nNoteNum=60\r\n";
var result = Import(text);
Assert.Equal(480, Assert.Single(result.Notes).LengthTicks);
}
[Fact]
public void TheSettingTempoIsUsed()
{
+25 -8
ファイルの表示
@@ -36,6 +36,7 @@ internal sealed record UstImportResult(
internal static class UstImporter
{
public const double MaximumDeclaredTempo = 1000.0;
public const int MaximumSectionTicks = TimeBase.TicksPerWholeNote * 1024;
public const double CentsPerPitchUnit = 10.0;
public const int EnvelopeFieldCount = 7;
const double TempoEpsilon = 1e-9;
@@ -52,6 +53,7 @@ internal static class UstImporter
var legacyPitchNoteCount = 0;
var position = 0;
var end = 0;
var emitted = 0;
foreach (var section in document.NoteSections)
{
@@ -59,16 +61,15 @@ internal static class UstImporter
var duration = ParseInteger(section.Find(UstKeys.Duration));
var delta = ParseInteger(section.Find(UstKeys.Delta));
var noteLength = duration ?? length ?? 0;
var hasSpacing = delta is not null && duration is not null && length is not null;
var noteLength = Math.Min((hasSpacing ? duration : length) ?? 0, MaximumSectionTicks);
if (noteLength <= 0)
continue;
var start = delta is not null && duration is not null && length is not null
? Math.Max(position + delta.Value, end)
: end;
var start = hasSpacing ? Math.Max(position + delta!.Value, end) : end;
var previousTone = notes.Count == 0 ? MusicalTone.MiddleC.NoteNumber : notes[^1].Tone;
AddRest(notes, start - end, previousTone);
emitted += AddRest(notes, start - emitted, previousTone);
var sectionTempo = ParseNumber(section.Find(UstKeys.Tempo));
var isTempoChange = IsUsableTempo(sectionTempo)
@@ -76,12 +77,14 @@ internal static class UstImporter
if (isTempoChange)
currentTempo = ClampTempo(sectionTempo!.Value);
var note = CreateNote(section, noteLength, new TimeBase(currentTempo, 1.0));
var note = CreateNote(section, HeadLengthTicks(start + noteLength - emitted), new TimeBase(currentTempo, 1.0));
if (isTempoChange)
note.TempoOverride = currentTempo;
if (note.PitchPoints.Count == 0 && HasLegacyPitch(section))
legacyPitchNoteCount++;
notes.Add(note);
emitted += note.LengthTicks;
emitted += AddRest(notes, start + noteLength - emitted, note.Tone);
position = start;
end = start + noteLength;
@@ -245,11 +248,12 @@ internal static class UstImporter
|| section.Find(UstKeys.LegacyPitches) is not null
|| section.Find(UstKeys.LegacyPitchesTypo) is not null;
static void AddRest(List<UTAUNote> notes, int lengthTicks, int tone)
static int AddRest(List<UTAUNote> notes, int lengthTicks, int tone)
{
var emitted = 0;
while (lengthTicks >= UTAUNote.MinimumLengthTicks)
{
var chunk = Math.Min(lengthTicks, UTAUNote.MaximumLengthTicks);
var chunk = HeadLengthTicks(lengthTicks);
notes.Add(new UTAUNote
{
Lyric = UTAUNote.RestLyric,
@@ -257,7 +261,20 @@ internal static class UstImporter
LengthTicks = chunk,
});
lengthTicks -= chunk;
emitted += chunk;
}
return emitted;
}
static int HeadLengthTicks(int lengthTicks)
{
if (lengthTicks <= UTAUNote.MaximumLengthTicks)
return lengthTicks;
var remainder = lengthTicks - UTAUNote.MaximumLengthTicks;
return remainder >= UTAUNote.MinimumLengthTicks
? UTAUNote.MaximumLengthTicks
: UTAUNote.MaximumLengthTicks - (UTAUNote.MinimumLengthTicks - remainder);
}
static (int Leading, int Total) TrimSurroundingRests(List<UTAUNote> notes)
+6 -2
ファイルの表示
@@ -19,11 +19,15 @@ internal sealed record PhonemeUnit(
public double EndMilliseconds => StartMilliseconds + LengthMilliseconds;
public double Preutterance => Note.PreutteranceOverride > UTAUNote.FollowOtoValue
public bool HasPreutteranceOverride => Note.PreutteranceOverride > UTAUNote.FollowOtoValue;
public bool HasOverlapOverride => Note.OverlapOverride > UTAUNote.FollowOtoValue;
public double Preutterance => HasPreutteranceOverride
? Note.PreutteranceOverride
: Entry?.Preutterance ?? 0.0;
public double Overlap => Note.OverlapOverride > UTAUNote.FollowOtoValue
public double Overlap => HasOverlapOverride
? Note.OverlapOverride
: Entry?.Overlap ?? 0.0;
}
+142
ファイルの表示
@@ -0,0 +1,142 @@
using UTAU.Notes;
namespace UTAU.Synthesis;
internal sealed class PitchTrack
{
readonly record struct TrackNote(UTAUNote Note, double StartMilliseconds, double LengthMilliseconds, int Tone, double AudioStartMilliseconds)
{
public double EndMilliseconds => StartMilliseconds + LengthMilliseconds;
public double Cents => Tone * 100.0;
}
readonly double[] cents;
PitchTrack(double[] cents) => this.cents = cents;
public static PitchTrack Create(IReadOnlyList<UnitTiming> timings, double startMilliseconds, double framePeriod, int frameCount)
{
ArgumentNullException.ThrowIfNull(timings);
var cents = new double[Math.Max(frameCount, 0)];
var notes = CollectNotes(timings);
if (cents.Length == 0 || notes.Count == 0)
return new PitchTrack(cents);
FillTones(cents, notes, startMilliseconds, framePeriod);
ApplyVibrato(cents, notes, startMilliseconds, framePeriod);
ApplyPortamento(cents, notes, startMilliseconds, framePeriod);
return new PitchTrack(cents);
}
public double CentsAt(int frame)
=> cents.Length == 0 ? 0.0 : cents[Math.Clamp(frame, 0, cents.Length - 1)];
static List<TrackNote> CollectNotes(IReadOnlyList<UnitTiming> timings)
{
var notes = new List<TrackNote>(timings.Count);
foreach (var timing in timings)
{
var unit = timing.Unit;
if (unit.Note.IsRest)
continue;
notes.Add(new TrackNote(unit.Note, unit.NoteStartMilliseconds, unit.NoteLengthMilliseconds, unit.Tone, timing.AudioStartMilliseconds));
}
notes.Sort((left, right) => left.StartMilliseconds.CompareTo(right.StartMilliseconds));
var distinct = new List<TrackNote>(notes.Count);
foreach (var note in notes)
{
if (distinct.Count > 0 && distinct[^1].StartMilliseconds == note.StartMilliseconds && ReferenceEquals(distinct[^1].Note, note.Note))
{
distinct[^1] = distinct[^1] with
{
AudioStartMilliseconds = Math.Min(distinct[^1].AudioStartMilliseconds, note.AudioStartMilliseconds),
};
continue;
}
distinct.Add(note);
}
return distinct;
}
static void FillTones(double[] cents, List<TrackNote> notes, double startMilliseconds, double framePeriod)
{
var index = 0;
foreach (var note in notes)
{
while (index < cents.Length && startMilliseconds + index * framePeriod < note.EndMilliseconds)
{
cents[index] = note.Cents;
index++;
}
}
if (index == 0)
{
Array.Fill(cents, notes[^1].Cents);
return;
}
for (var i = index; i < cents.Length; i++)
cents[i] = cents[i - 1];
}
static void ApplyVibrato(double[] cents, List<TrackNote> notes, double startMilliseconds, double framePeriod)
{
foreach (var note in notes)
{
if (!note.Note.Vibrato.IsEnabled)
continue;
var from = Math.Max((int)Math.Ceiling((note.StartMilliseconds - startMilliseconds) / framePeriod), 0);
var to = Math.Min((int)((note.EndMilliseconds - startMilliseconds) / framePeriod), cents.Length);
for (var i = from; i < to; i++)
cents[i] = note.Cents + note.Note.Vibrato.Evaluate(startMilliseconds + i * framePeriod - note.StartMilliseconds, note.LengthMilliseconds);
}
}
static void ApplyPortamento(double[] cents, List<TrackNote> notes, double startMilliseconds, double framePeriod)
{
for (var n = 0; n < notes.Count; n++)
{
var note = notes[n];
if (note.Note.PitchPoints.Count == 0 || note.Note.LengthTicks <= 0)
continue;
var scale = note.LengthMilliseconds / note.Note.LengthTicks;
var points = new List<(double X, double Y, PitchPointShape Shape)>(note.Note.PitchPoints.Count + 2);
foreach (var point in note.Note.PitchPoints)
points.Add((note.StartMilliseconds + point.Ticks * scale, note.Cents + point.Cents, point.Shape));
var opensPhrase = n == 0 || notes[n - 1].EndMilliseconds < note.StartMilliseconds;
var lead = opensPhrase
? Math.Max(startMilliseconds, note.AudioStartMilliseconds)
: note.StartMilliseconds;
if (points[0].X > lead)
points.Insert(0, (lead, points[0].Y, points[0].Shape));
if (points[^1].X < note.EndMilliseconds)
points.Add((note.EndMilliseconds, points[^1].Y, points[^1].Shape));
for (var s = 0; s < points.Count - 1; s++)
{
var from = points[s];
var to = points[s + 1];
var first = Math.Max((int)Math.Ceiling((from.X - startMilliseconds) / framePeriod), 0);
var last = Math.Min((int)Math.Ceiling((to.X - startMilliseconds) / framePeriod), cents.Length);
var span = to.X - from.X;
for (var i = first; i < last; i++)
{
var x = startMilliseconds + i * framePeriod;
var progress = span <= 0.0 ? 1.0 : (x - from.X) / span;
var pitch = PitchPoint.Interpolate(from.Y, to.Y, progress, from.Shape);
var basePitch = n > 0 && x < notes[n - 1].EndMilliseconds ? notes[n - 1].Cents : note.Cents;
cents[i] += pitch - basePitch;
}
}
}
}
}
+3
ファイルの表示
@@ -38,6 +38,7 @@ internal readonly record struct UnitKey(
double RenderLengthMilliseconds,
double FadeInMilliseconds,
double FadeOutMilliseconds,
double SkipMilliseconds,
double NoteStartMilliseconds,
double NoteLengthMilliseconds,
int Tone,
@@ -54,6 +55,7 @@ internal readonly record struct UnitKey(
&& RenderLengthMilliseconds.Equals(other.RenderLengthMilliseconds)
&& FadeInMilliseconds.Equals(other.FadeInMilliseconds)
&& FadeOutMilliseconds.Equals(other.FadeOutMilliseconds)
&& SkipMilliseconds.Equals(other.SkipMilliseconds)
&& NoteStartMilliseconds.Equals(other.NoteStartMilliseconds)
&& NoteLengthMilliseconds.Equals(other.NoteLengthMilliseconds)
&& Tone == other.Tone
@@ -72,6 +74,7 @@ internal readonly record struct UnitKey(
hash.Add(RenderLengthMilliseconds);
hash.Add(FadeInMilliseconds);
hash.Add(FadeOutMilliseconds);
hash.Add(SkipMilliseconds);
hash.Add(NoteStartMilliseconds);
hash.Add(NoteLengthMilliseconds);
hash.Add(Tone);
+4
ファイルの表示
@@ -68,6 +68,10 @@ internal static class SpectrumTransform
}
}
public static double ToAmplitude(double power) => Math.Sqrt(power);
public static double ToPower(double amplitude) => amplitude * amplitude;
public static double Clamp(double aperiodicity)
=> double.IsNaN(aperiodicity)
? MaximumAperiodicity
+6 -7
ファイルの表示
@@ -21,17 +21,14 @@ internal readonly record struct TimeMap(
StretchMode stretchMode)
{
var scale = VelocityToConsonantScale(velocity);
var consonantSourceLength = Math.Max(consonantEnd - regionStart, 0.0);
var consonantOutputLength = Math.Min(consonantSourceLength * scale, Math.Max(outputLength, 0.0));
if (consonantSourceLength > 0.0 && consonantOutputLength > 0.0)
scale = consonantOutputLength / consonantSourceLength;
var consonantOutputLength = Math.Max(consonantEnd - regionStart, 0.0) * scale;
return new TimeMap(
regionStart,
consonantEnd,
regionEnd,
consonantOutputLength,
Math.Max(outputLength - consonantOutputLength, 0.0),
Math.Max(Math.Max(outputLength, 0.0) - consonantOutputLength, 0.0),
scale,
stretchMode);
}
@@ -53,8 +50,10 @@ internal readonly record struct TimeMap(
var elapsed = outputMilliseconds - ConsonantOutputLength;
if (StretchMode == StretchMode.Stretch)
{
var progress = SustainOutputLength > 0.0 ? Math.Clamp(elapsed / SustainOutputLength, 0.0, 1.0) : 0.0;
return ConsonantEnd + sustainSourceLength * progress;
var speed = SustainOutputLength > 0.0
? Math.Clamp(sustainSourceLength / SustainOutputLength, 0.0, 1.0)
: 0.0;
return Math.Min(ConsonantEnd + elapsed * speed, RegionEnd);
}
var period = sustainSourceLength * 2.0;
+58 -22
ファイルの表示
@@ -1,3 +1,4 @@
using UTAU.Notes;
using UTAU.Phonemes;
namespace UTAU.Synthesis;
@@ -7,7 +8,8 @@ internal readonly record struct UnitTiming(
double AudioStartMilliseconds,
double RenderLengthMilliseconds,
double FadeInMilliseconds,
double FadeOutMilliseconds)
double FadeOutMilliseconds,
double SkipMilliseconds)
{
public double AudioEndMilliseconds => AudioStartMilliseconds + RenderLengthMilliseconds;
@@ -33,32 +35,63 @@ internal readonly record struct UnitTiming(
internal static class UnitTimingBuilder
{
const double AdjacentHeadShare = 0.5;
const double PlosiveHeadShare = 0.9;
public static IReadOnlyList<UnitTiming> Build(IReadOnlyList<PhonemeUnit> units)
{
var timings = new List<UnitTiming>(units.Count);
var preutterances = new double[units.Count];
var overlaps = new double[units.Count];
var adjacent = new bool[units.Count];
var skips = new double[units.Count];
for (var i = 0; i < units.Count; i++)
{
var preutterance = units[i].Preutterance;
var overlap = units[i].Overlap;
var head = preutterance - overlap;
var available = i == 0 ? 0.0 : units[i - 1].LengthMilliseconds;
var consonantScale = TimeMap.VelocityToConsonantScale(units[i].Note.Velocity);
var preutterance = units[i].HasPreutteranceOverride ? units[i].Preutterance : units[i].Preutterance * consonantScale;
var overlap = units[i].HasOverlapOverride ? units[i].Overlap : units[i].Overlap * consonantScale;
var requested = preutterance;
var preceding = FindPrecedingVoiced(units, i);
if (i > 0 && head > available && head > 0.0)
if (preceding >= 0)
{
var ratio = available / head;
preutterance *= ratio;
overlap *= ratio;
}
else if (i == 0 && head < 0.0)
{
overlap = preutterance;
var precedingLength = units[preceding].LengthMilliseconds;
var gap = units[i].StartMilliseconds - units[preceding].EndMilliseconds;
var limit = preutterance;
adjacent[i] = gap <= 0.0;
if (adjacent[i])
{
var head = preutterance - overlap;
if (overlap > 0.0)
{
if (head > precedingLength * AdjacentHeadShare)
limit = precedingLength * AdjacentHeadShare / head * preutterance;
}
else
limit = Math.Min(limit, precedingLength * PlosiveHeadShare);
limit = Math.Min(limit, precedingLength);
if (preutterances[preceding] < UTAUNote.DefaultFadeInMilliseconds)
limit = Math.Min(limit, precedingLength + preutterances[preceding] - UTAUNote.DefaultFadeInMilliseconds);
}
else if (gap < preutterance)
limit = gap;
if (preutterance > limit)
{
overlap *= preutterance > 0.0 ? limit / preutterance : 0.0;
preutterance = limit;
}
if (overlap < 0.0)
overlap = Math.Max(overlap, Math.Min(0.0, UTAUNote.DefaultFadeOutMilliseconds - precedingLength + preutterance));
}
preutterances[i] = preutterance;
overlaps[i] = Math.Max(overlap, 0.0);
preutterances[i] = Math.Max(preutterance, 0.0);
overlaps[i] = overlap;
skips[i] = Math.Max(requested - preutterances[i], 0.0);
}
for (var i = 0; i < units.Count; i++)
@@ -74,12 +107,11 @@ internal static class UnitTimingBuilder
: units[next].StartMilliseconds - preutterances[next] + overlaps[next] - audioStart;
renderLength = Math.Max(renderLength, RenderSettings.MinimumUnitLengthMilliseconds);
var previous = FindPreviousVoiced(units, i);
var fadeIn = previous >= 0 && overlaps[i] > 0.0 ? overlaps[i] : unit.Note.FadeInMilliseconds;
var fadeOut = next >= 0 && overlaps[next] > 0.0 ? overlaps[next] : unit.Note.FadeOutMilliseconds;
var fadeIn = adjacent[i] && overlaps[i] > 0.0 ? overlaps[i] : unit.Note.FadeInMilliseconds;
var fadeOut = next >= 0 && adjacent[next] && overlaps[next] > 0.0 ? overlaps[next] : unit.Note.FadeOutMilliseconds;
(fadeIn, fadeOut) = LimitFades(fadeIn, fadeOut, renderLength);
timings.Add(new UnitTiming(unit, audioStart, renderLength, fadeIn, fadeOut));
timings.Add(new UnitTiming(unit, audioStart, renderLength, fadeIn, fadeOut, skips[i]));
}
return timings;
@@ -103,9 +135,13 @@ internal static class UnitTimingBuilder
return next < units.Count && !units[next].IsSilent ? next : -1;
}
static int FindPreviousVoiced(IReadOnlyList<PhonemeUnit> units, int index)
static int FindPrecedingVoiced(IReadOnlyList<PhonemeUnit> units, int index)
{
var previous = index - 1;
return previous >= 0 && !units[previous].IsSilent ? previous : -1;
for (var preceding = index - 1; preceding >= 0; preceding--)
{
if (!units[preceding].IsSilent)
return preceding;
}
return -1;
}
}
+66 -14
ファイルの表示
@@ -15,7 +15,8 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
double RegionStart,
double RegionEnd,
double ConsonantEnd,
double MeanF0);
double MeanF0,
double AutoGain);
sealed record Segment(int StartFrame, int FrameCount, IReadOnlyList<int> TimingIndices);
@@ -36,7 +37,9 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
int EndSample,
double RegionStart,
double RegionEnd,
double ConsonantEnd);
double ConsonantEnd,
double SourcePeak,
double RegionPeak);
sealed class RenderState : IDisposable
{
@@ -73,6 +76,10 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
const long MaximumFrameElements = 1L << 24;
const double FrameCountEpsilon = 1e-9;
const int SegmentGapFrames = 10;
const double PeakCompressionPercent = 86.0;
const double PeakTarget = 0.5;
const double VoicedRatioBias = 5.0;
const double VoicedRatioSlope = 10.0;
readonly Dictionary<string, AudioSample> loadedSamples = new(StringComparer.OrdinalIgnoreCase);
@@ -224,6 +231,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
timing.RenderLengthMilliseconds,
timing.FadeInMilliseconds,
timing.FadeOutMilliseconds,
timing.SkipMilliseconds,
unit.NoteStartMilliseconds - origin,
unit.NoteLengthMilliseconds,
unit.Tone,
@@ -306,6 +314,12 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
Array.Clear(voicedWeight, 0, frameCount);
Array.Clear(logF0Sum, 0, frameCount);
var track = PitchTrack.Create(
[.. segment.TimingIndices.Select(x => timings[x])],
offset + segment.StartFrame * framePeriod,
framePeriod,
frameCount);
foreach (var index in segment.TimingIndices)
{
var source = BuildSource(requests[index], arena);
@@ -315,6 +329,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
AccumulateUnit(
timings[index],
source,
track,
offset,
framePeriod,
segment.StartFrame,
@@ -351,6 +366,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
void AccumulateUnit(
UnitTiming timing,
UnitSource source,
PitchTrack track,
double offset,
double framePeriod,
int segmentStartFrame,
@@ -369,11 +385,11 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
var note = unit.Note;
var startFrame = Math.Max((int)Math.Floor((timing.AudioStartMilliseconds - offset) / framePeriod) - segmentStartFrame, 0);
var endFrame = Math.Min((int)Math.Ceiling((timing.AudioEndMilliseconds - offset) / framePeriod) - segmentStartFrame, frameCount - 1);
var gain = settings.Gain * Math.Clamp(note.Intensity, 0.0, 200.0) / 100.0;
var gain = settings.Gain * Math.Clamp(note.Intensity, 0.0, 200.0) / 100.0 * source.AutoGain;
var baseFormantRatio = settings.FormantRatio;
var hasFormantCurve = curves.HasFormant;
var hasBreathinessCurve = curves.HasBreathiness;
var map = TimeMap.Create(source.RegionStart, source.ConsonantEnd, source.RegionEnd, timing.RenderLengthMilliseconds, note.Velocity, settings.StretchMode);
var map = TimeMap.Create(source.RegionStart, source.ConsonantEnd, source.RegionEnd, timing.RenderLengthMilliseconds + timing.SkipMilliseconds, note.Velocity, settings.StretchMode);
var modulation = Math.Clamp(note.Modulation, -200.0, 200.0) / 100.0;
for (var frame = startFrame; frame <= endFrame; frame++)
@@ -384,7 +400,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
if (weight <= 0.0)
continue;
var sourceMilliseconds = map.Map(elapsed);
var sourceMilliseconds = map.Map(elapsed + timing.SkipMilliseconds);
var frameIndex = source.Features.GetFrameIndex(sourceMilliseconds);
SampleFeatures(source.Features, frameIndex, frameSpectrum, frameAperiodicity, out var sourceF0);
@@ -404,7 +420,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
var baseIndex = (long)frame * spectrumSize;
for (var k = 0; k < spectrumSize; k++)
{
spectrogram[baseIndex + k] += weight * warpedSpectrum[k];
spectrogram[baseIndex + k] += weight * SpectrumTransform.ToAmplitude(warpedSpectrum[k]);
aperiodicity[baseIndex + k] += weight * frameAperiodicity[k];
}
weightSum[frame] += weight;
@@ -412,11 +428,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
if (sourceF0 <= 0.0)
continue;
var progress = unit.NoteLengthMilliseconds > 0.0
? (absolute - unit.NoteStartMilliseconds) / unit.NoteLengthMilliseconds
: 0.0;
var cents = note.EvaluatePitchOffsetCents(progress, unit.NoteLengthMilliseconds);
var targetF0 = MusicalTone.FrequencyOf(unit.Tone + cents / 100.0);
var targetF0 = MusicalTone.FrequencyOf(track.CentsAt(frame) / 100.0);
var ratio = source.MeanF0 > 0.0 ? sourceF0 / source.MeanF0 : 1.0;
var value = targetF0 * Math.Pow(ratio, modulation);
if (!double.IsFinite(value) || value <= 0.0)
@@ -455,7 +467,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
for (var k = 0; k < spectrumSize; k++)
{
spectrogram[baseIndex + k] = Math.Max(spectrogram[baseIndex + k], SpectrumTransform.MinimumPower);
spectrogram[baseIndex + k] = Math.Max(SpectrumTransform.ToPower(spectrogram[baseIndex + k]), SpectrumTransform.MinimumPower);
aperiodicity[baseIndex + k] = SpectrumTransform.Clamp(aperiodicity[baseIndex + k] / total);
}
@@ -534,7 +546,19 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
endSample,
regionStart,
regionEnd,
consonantEnd);
consonantEnd,
Peak(sample.Samples, 0, sample.Samples.Length),
Peak(sample.Samples, sample.MillisecondsToSamples(regionStart), sample.MillisecondsToSamples(regionEnd)));
}
static double Peak(ReadOnlySpan<double> samples, int from, int to)
{
from = Math.Clamp(from, 0, samples.Length);
to = Math.Clamp(to, from, samples.Length);
var peak = 0.0;
for (var i = from; i < to; i++)
peak = Math.Max(peak, Math.Abs(samples[i]));
return peak;
}
void AnalyzeInParallel(IReadOnlyList<AnalysisRequest?> requests)
@@ -582,7 +606,35 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
value.RegionStart,
value.RegionEnd,
value.ConsonantEnd,
ComputeMeanF0(features, value.RegionStart, value.RegionEnd));
ComputeMeanF0(features, value.RegionStart, value.RegionEnd),
ComputeAutoGain(
value.SourcePeak,
value.RegionPeak,
ComputeVoicedRatio(features, value.RegionStart, value.RegionEnd)));
}
static double ComputeVoicedRatio(WorldFeatures features, double regionStart, double regionEnd)
{
var voiced = 0;
var count = 0;
var first = Math.Max((int)Math.Floor(features.GetFrameIndex(regionStart)), 0);
var last = Math.Min((int)Math.Ceiling(features.GetFrameIndex(regionEnd)), features.FrameCount - 1);
for (var i = first; i <= last; i++)
{
count++;
if (features.F0[i] > 0.0)
voiced++;
}
return count == 0 ? 0.0 : (double)voiced / count;
}
static double ComputeAutoGain(double sourcePeak, double regionPeak, double voicedRatio)
{
var weight = 1.0 / (1.0 + Math.Exp(VoicedRatioBias - VoicedRatioSlope * voicedRatio));
var peak = regionPeak * weight + sourcePeak * (1.0 - weight);
return peak <= 0.0 ? 1.0 : Math.Pow(PeakTarget / peak, PeakCompressionPercent / 100.0);
}
static double ComputeMeanF0(WorldFeatures features, double regionStart, double regionEnd)
+1 -1
ファイルの表示
@@ -5,7 +5,7 @@
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.4.1</Version>
<Version>1.6.2</Version>
<Platforms>AnyCPU;x64;x64</Platforms>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
バイナリ
ファイルの表示
バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 650 KiB