Skip to content

Commit 31d7441

Browse files
committed
fix: 截取预览的持续时间错误
1 parent 0a9a97a commit 31d7441

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

MaiChartManager/Controllers/Music/CueConvertController.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public async Task SetAudioPreview(int id, [FromBody] SetAudioPreviewRequest requ
6363
var loopStart = TimeSpan.FromSeconds(request.StartTime);
6464
var loopEnd = TimeSpan.FromSeconds(request.EndTime);
6565

66-
using var sha1 = SHA1.Create();
67-
var awbHash = await sha1.ComputeHashAsync(System.IO.File.OpenRead(StaticSettings.AcbAwb[$"music{id:000000}.awb"]));
68-
var acbBytes = CriUtils.CreateAcbWithPreview(cachePath, awbHash, loopStart, loopEnd);
66+
var acbBytes = await CriUtils.CreateAcbWithPreview(cachePath, await System.IO.File.ReadAllBytesAsync(StaticSettings.AcbAwb[$"music{id:000000}.awb"]), loopStart, loopEnd);
6967
await System.IO.File.WriteAllBytesAsync(targetAcbPath, acbBytes);
7068
}
7169

MaiChartManager/Utils/CriUtils.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Reflection;
2+
using System.Security.Cryptography;
23
using System.Text;
34
using SonicAudioLib.CriMw;
45
using VGAudio.Containers.Wave;
@@ -29,8 +30,11 @@ public static byte[] SetAcbPreview(string acbPath, TimeSpan loopStart, TimeSpan
2930
return criTable.Save();
3031
}
3132

32-
public static byte[] CreateAcbWithPreview(string wavPath, byte[] sha1HashOfAwb, TimeSpan loopStart, TimeSpan loopEnd)
33+
public static async Task<byte[]> CreateAcbWithPreview(string wavPath, byte[] awbBytes, TimeSpan loopStart, TimeSpan loopEnd)
3334
{
35+
using var sha1 = SHA1.Create();
36+
var sha1HashOfAwb = await sha1.ComputeHashAsync(new MemoryStream(awbBytes));
37+
3438
var waveReader = new WaveReader();
3539
var audioData = waveReader.Read(File.ReadAllBytes(wavPath));
3640
var format = audioData.GetFormat<Pcm16Format>();
@@ -56,6 +60,16 @@ public static byte[] CreateAcbWithPreview(string wavPath, byte[] sha1HashOfAwb,
5660
waveFormTable.Rows[0]["NumSamples"] = (byte)format.SampleCount;
5761
criTable.Rows[0]["WaveformTable"] = waveFormTable.Save();
5862

63+
// 修复歌曲持续时间
64+
var count = BitConverter.ToInt32(awbBytes, 8) + 1;
65+
var headSize = 16 + awbBytes[5] * count + awbBytes[6] * count + awbBytes[7] * count;
66+
var header = new byte[headSize];
67+
Array.Copy(awbBytes, header, headSize);
68+
var streamAwbAfs2Header = new CriTable();
69+
streamAwbAfs2Header.Load(criTable.Rows[0]["StreamAwbAfs2Header"] as byte[]);
70+
streamAwbAfs2Header.Rows[0]["Header"] = header;
71+
criTable.Rows[0]["StreamAwbAfs2Header"] = streamAwbAfs2Header.Save();
72+
5973
criTable.WriterSettings = CriTableWriterSettings.Adx2Settings;
6074
return criTable.Save();
6175
}
@@ -105,4 +119,4 @@ private static CriTable GetTable(this CriRow row, string name)
105119
table.Load(row[name] as byte[]);
106120
return table;
107121
}
108-
}
122+
}

0 commit comments

Comments
 (0)