Added 2 second padding if offset is > - 1f
This commit is contained in:
parent
d45e33f966
commit
b27df30815
@ -22,6 +22,9 @@ namespace TJAConvert
|
|||||||
{
|
{
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
|
public const int PaddedSongTime = 2 * 1000; // in ms
|
||||||
|
public const float TjaOffsetForPaddingSong = -1.0f; // in ms
|
||||||
|
|
||||||
public static async Task Main(string[] args)
|
public static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length != 1)
|
if (args.Length != 1)
|
||||||
@ -100,7 +103,7 @@ namespace TJAConvert
|
|||||||
Directory.CreateDirectory(tempOutDirectory);
|
Directory.CreateDirectory(tempOutDirectory);
|
||||||
|
|
||||||
var originalTjaData = File.ReadAllBytes(tjaPath);
|
var originalTjaData = File.ReadAllBytes(tjaPath);
|
||||||
var tjaHash = (int)(MurmurHash2.Hash(originalTjaData) & 0xFFFF_FFF);
|
var tjaHash = (int) (MurmurHash2.Hash(originalTjaData) & 0xFFFF_FFF);
|
||||||
|
|
||||||
var passed = await TJAToFumens(metadata, tjaPath, tjaHash, tempOutDirectory);
|
var passed = await TJAToFumens(metadata, tjaPath, tjaHash, tempOutDirectory);
|
||||||
if (passed >= 0) passed = CreateMusicFile(metadata, tjaHash, tempOutDirectory) ? 0 : -1;
|
if (passed >= 0) passed = CreateMusicFile(metadata, tjaHash, tempOutDirectory) ? 0 : -1;
|
||||||
@ -108,14 +111,16 @@ namespace TJAConvert
|
|||||||
var copyFilePath = Path.Combine(newDirectory, Path.GetFileName(originalAudioPath));
|
var copyFilePath = Path.Combine(newDirectory, Path.GetFileName(originalAudioPath));
|
||||||
File.Copy(originalAudioPath, copyFilePath);
|
File.Copy(originalAudioPath, copyFilePath);
|
||||||
|
|
||||||
|
int millisecondsAddedSilence = metadata.Offset > TjaOffsetForPaddingSong ? PaddedSongTime : 0;
|
||||||
|
|
||||||
var audioExtension = Path.GetExtension(copyFilePath).TrimStart('.');
|
var audioExtension = Path.GetExtension(copyFilePath).TrimStart('.');
|
||||||
switch (audioExtension.ToLowerInvariant())
|
switch (audioExtension.ToLowerInvariant())
|
||||||
{
|
{
|
||||||
case "wav":
|
case "wav":
|
||||||
if (passed >= 0) passed = WavToACB(copyFilePath, tempOutDirectory, tjaHash) ? 0 : -1;
|
if (passed >= 0) passed = WavToACB(copyFilePath, tempOutDirectory, tjaHash, millisecondsAddedSilence: millisecondsAddedSilence) ? 0 : -1;
|
||||||
break;
|
break;
|
||||||
case "ogg":
|
case "ogg":
|
||||||
if (passed >= 0) passed = OGGToACB(copyFilePath, tempOutDirectory, tjaHash) ? 0 : -1;
|
if (passed >= 0) passed = OGGToACB(copyFilePath, tempOutDirectory, tjaHash, millisecondsAddedSilence) ? 0 : -1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine($"Do not support {audioExtension} audio files");
|
Console.WriteLine($"Do not support {audioExtension} audio files");
|
||||||
@ -202,6 +207,7 @@ namespace TJAConvert
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var addedTime = metadata.Offset > TjaOffsetForPaddingSong ? PaddedSongTime : 0;
|
||||||
var musicInfo = new CustomSong
|
var musicInfo = new CustomSong
|
||||||
{
|
{
|
||||||
id = tjaHash.ToString(),
|
id = tjaHash.ToString(),
|
||||||
@ -212,8 +218,8 @@ namespace TJAConvert
|
|||||||
branchHard = false,
|
branchHard = false,
|
||||||
branchMania = false,
|
branchMania = false,
|
||||||
branchUra = false,
|
branchUra = false,
|
||||||
previewPos = (int) (metadata.PreviewTime * 1000),
|
previewPos = (int) (metadata.PreviewTime * 1000) + addedTime,
|
||||||
fumenOffsetPos = (int) (metadata.Offset * 10),
|
fumenOffsetPos = (int) (metadata.Offset * 10) + (addedTime),
|
||||||
tjaFileHash = tjaHash,
|
tjaFileHash = tjaHash,
|
||||||
songName = new TextEntry()
|
songName = new TextEntry()
|
||||||
{
|
{
|
||||||
@ -882,8 +888,9 @@ namespace TJAConvert
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
number2 = test;
|
number2 = test;
|
||||||
currentLines[i] = $"#BRANCHSTART p,{(int)Math.Ceiling(number1)},{(int)Math.Ceiling(number2)}";
|
currentLines[i] = $"#BRANCHSTART p,{(int) Math.Ceiling(number1)},{(int) Math.Ceiling(number2)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllLines(newPath, currentLines);
|
File.WriteAllLines(newPath, currentLines);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1059,7 +1066,7 @@ namespace TJAConvert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool OGGToACB(string oggPath, string outDirectory, int tjaHash)
|
private static bool OGGToACB(string oggPath, string outDirectory, int tjaHash, int millisecondsAddedSilence = 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -1072,7 +1079,7 @@ namespace TJAConvert
|
|||||||
using (FileStream compressedFileStream = File.Create($"{acbPath}.acb"))
|
using (FileStream compressedFileStream = File.Create($"{acbPath}.acb"))
|
||||||
decompressor.CopyTo(compressedFileStream);
|
decompressor.CopyTo(compressedFileStream);
|
||||||
|
|
||||||
var hca = OggToHca(oggPath);
|
var hca = OggToHca(oggPath, millisecondsAddedSilence);
|
||||||
if (hca == null)
|
if (hca == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1092,7 +1099,7 @@ namespace TJAConvert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool WavToACB(string wavPath, string outDirectory, int tjaHash, bool deleteWav = false)
|
private static bool WavToACB(string wavPath, string outDirectory, int tjaHash, bool deleteWav = false, int millisecondsAddedSilence = 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -1105,7 +1112,7 @@ namespace TJAConvert
|
|||||||
using (FileStream compressedFileStream = File.Create($"{acbPath}.acb"))
|
using (FileStream compressedFileStream = File.Create($"{acbPath}.acb"))
|
||||||
decompressor.CopyTo(compressedFileStream);
|
decompressor.CopyTo(compressedFileStream);
|
||||||
|
|
||||||
var hca = WavToHca(wavPath);
|
var hca = WavToHca(wavPath, millisecondsAddedSilence);
|
||||||
File.WriteAllBytes($"{acbPath}/00000.hca", hca);
|
File.WriteAllBytes($"{acbPath}/00000.hca", hca);
|
||||||
Pack(acbPath);
|
Pack(acbPath);
|
||||||
if (File.Exists($"{outDirectory}/song_{tjaHash}.bin"))
|
if (File.Exists($"{outDirectory}/song_{tjaHash}.bin"))
|
||||||
@ -1125,22 +1132,53 @@ namespace TJAConvert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] WavToHca(string path)
|
private static byte[] WavToHca(string path, int millisecondSilence = 0)
|
||||||
{
|
{
|
||||||
|
var wavReader = new WaveReader();
|
||||||
var hcaWriter = new HcaWriter();
|
var hcaWriter = new HcaWriter();
|
||||||
var waveReader = new WaveReader();
|
|
||||||
var audioData = waveReader.Read(File.ReadAllBytes(path));
|
if (millisecondSilence > 0)
|
||||||
return hcaWriter.GetFile(audioData);
|
{
|
||||||
|
WaveFileReader reader = new WaveFileReader(path);
|
||||||
|
var memoryStream = new MemoryStream();
|
||||||
|
|
||||||
|
var trimmed = new OffsetSampleProvider(reader.ToSampleProvider())
|
||||||
|
{
|
||||||
|
DelayBy = TimeSpan.FromMilliseconds(millisecondSilence)
|
||||||
|
};
|
||||||
|
WaveFileWriter.WriteWavFileToStream(memoryStream, trimmed.ToWaveProvider16());
|
||||||
|
|
||||||
|
var audioData = wavReader.Read(memoryStream.ToArray());
|
||||||
|
return hcaWriter.GetFile(audioData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var audioData = wavReader.Read(File.ReadAllBytes(path));
|
||||||
|
return hcaWriter.GetFile(audioData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] OggToHca(string inPath)
|
private static byte[] OggToHca(string inPath, int millisecondSilence = 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using FileStream fileIn = new FileStream(inPath, FileMode.Open);
|
using FileStream fileIn = new FileStream(inPath, FileMode.Open);
|
||||||
var vorbis = new VorbisWaveReader(fileIn);
|
var vorbis = new VorbisWaveReader(fileIn);
|
||||||
|
var wavProvider = new SampleToWaveProvider16(vorbis);
|
||||||
var memoryStream = new MemoryStream();
|
var memoryStream = new MemoryStream();
|
||||||
WaveFileWriter.WriteWavFileToStream(memoryStream, new SampleToWaveProvider16(vorbis));
|
|
||||||
|
if (millisecondSilence > 0)
|
||||||
|
{
|
||||||
|
var trimmed = new OffsetSampleProvider(wavProvider.ToSampleProvider())
|
||||||
|
{
|
||||||
|
DelayBy = TimeSpan.FromMilliseconds(millisecondSilence)
|
||||||
|
};
|
||||||
|
WaveFileWriter.WriteWavFileToStream(memoryStream, trimmed.ToWaveProvider16());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WaveFileWriter.WriteWavFileToStream(memoryStream, wavProvider);
|
||||||
|
}
|
||||||
|
|
||||||
var hcaWriter = new HcaWriter();
|
var hcaWriter = new HcaWriter();
|
||||||
var waveReader = new WaveReader();
|
var waveReader = new WaveReader();
|
||||||
|
@ -192,7 +192,7 @@ public class MusicPatch
|
|||||||
{
|
{
|
||||||
if (IsTjaConverted(musicDirectory, out var conversionStatus) && conversionStatus != null)
|
if (IsTjaConverted(musicDirectory, out var conversionStatus) && conversionStatus != null)
|
||||||
{
|
{
|
||||||
foreach (var item in conversionStatus.Items.Where(item => item.Successful))
|
foreach (var item in conversionStatus.Items.Where(item => item.Successful && item.Version == ConversionStatus.ConversionItem.CurrentVersion))
|
||||||
SubmitDirectory(Path.Combine(musicDirectory, item.FolderName), true);
|
SubmitDirectory(Path.Combine(musicDirectory, item.FolderName), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -239,14 +239,14 @@ public class MusicPatch
|
|||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var resultInt = int.Parse(match.Groups["ID"].Value);
|
var resultCode = int.Parse(match.Groups["ID"].Value);
|
||||||
var folderPath = match.Groups["PATH"].Value;
|
var folderPath = match.Groups["PATH"].Value;
|
||||||
|
|
||||||
folderPath = Path.GetFullPath(folderPath).Replace(Path.GetFullPath(musicDirectory), ".");
|
folderPath = Path.GetFullPath(folderPath).Replace(Path.GetFullPath(musicDirectory), ".");
|
||||||
|
|
||||||
var existingEntry = conversionStatus.Items.FirstOrDefault(x => x.FolderName == folderPath);
|
var existingEntry = conversionStatus.Items.FirstOrDefault(x => x.FolderName == folderPath);
|
||||||
var asciiFolderPath = Regex.Replace(folderPath, @"[^\u0000-\u007F]+", string.Empty);
|
var asciiFolderPath = Regex.Replace(folderPath, @"[^\u0000-\u007F]+", string.Empty);
|
||||||
if (resultInt >= 0)
|
if (resultCode >= 0)
|
||||||
Log.LogInfo($"Converted {asciiFolderPath} successfully");
|
Log.LogInfo($"Converted {asciiFolderPath} successfully");
|
||||||
else
|
else
|
||||||
Log.LogError($"Could not convert {asciiFolderPath}");
|
Log.LogError($"Could not convert {asciiFolderPath}");
|
||||||
@ -257,13 +257,17 @@ public class MusicPatch
|
|||||||
{
|
{
|
||||||
Attempts = 1,
|
Attempts = 1,
|
||||||
FolderName = folderPath,
|
FolderName = folderPath,
|
||||||
Successful = resultInt >= 0,
|
Successful = resultCode >= 0,
|
||||||
|
ResultCode = resultCode,
|
||||||
|
Version = ConversionStatus.ConversionItem.CurrentVersion,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
existingEntry.Attempts++;
|
existingEntry.Attempts++;
|
||||||
existingEntry.Successful = resultInt >= 0;
|
existingEntry.Successful = resultCode >= 0;
|
||||||
|
existingEntry.ResultCode = resultCode;
|
||||||
|
existingEntry.Version = ConversionStatus.ConversionItem.CurrentVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,7 +426,7 @@ public class MusicPatch
|
|||||||
if (conversionStatus == null)
|
if (conversionStatus == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return conversionStatus.Items.Count != 0 && conversionStatus.Items.All(x => x.Successful);
|
return conversionStatus.Items.Count != 0 && conversionStatus.Items.All(x => x.Successful && x.Version == ConversionStatus.ConversionItem.CurrentVersion);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -1881,13 +1885,14 @@ public class MusicPatch
|
|||||||
|
|
||||||
public class ConversionItem
|
public class ConversionItem
|
||||||
{
|
{
|
||||||
[JsonIgnore] public const int CurrentVersion = 1;
|
[JsonIgnore] public const int CurrentVersion = 2;
|
||||||
[JsonIgnore] public const int MaxAttempts = 3;
|
[JsonIgnore] public const int MaxAttempts = 3;
|
||||||
|
|
||||||
[JsonProperty("f")] public string FolderName;
|
[JsonProperty("f")] public string FolderName;
|
||||||
[JsonProperty("a")] public int Attempts;
|
[JsonProperty("a")] public int Attempts;
|
||||||
[JsonProperty("s")] public bool Successful;
|
[JsonProperty("s")] public bool Successful;
|
||||||
[JsonProperty("v")] public int Version = CurrentVersion;
|
[JsonProperty("v")] public int Version;
|
||||||
|
[JsonProperty("e")] public int ResultCode;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
@ -1902,4 +1907,4 @@ public class MusicPatch
|
|||||||
public string SongName;
|
public string SongName;
|
||||||
public int UniqueId;
|
public int UniqueId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user