Skip to content

Commit

Permalink
add new switch ignore_audio_missing for some bms which missing some a…
Browse files Browse the repository at this point in the history
…udio file and user want to ignore these error.
  • Loading branch information
MikiraSora committed Jun 6, 2022
1 parent e802bf3 commit becc02c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BmsPreviewAudioGenerator/BmsPreviewAudioGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Platforms>AnyCPU;x86;x64</Platforms>
<Version>0.9.6</Version>
<Version>0.9.7</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down
21 changes: 15 additions & 6 deletions BmsPreviewAudioGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static void Main(string[] args)
var fc = CommandLine.ContainSwitchOption("fast_clip");
var cv = CommandLine.ContainSwitchOption("check_valid");
var ns = CommandLine.ContainSwitchOption("no_skip");
var ig = CommandLine.ContainSwitchOption("ignore_audio_missing");
var rm = CommandLine.ContainSwitchOption("rm");

if (CommandLine.ContainSwitchOption("support_extend_format"))
Expand Down Expand Up @@ -117,6 +118,7 @@ static void Main(string[] args)
check_vaild: cv,
fade_in: fi,
fade_out: fo,
ignore_audio_missing: ig,
encoding_type: enc,
encoder_command_line: eopt))
failed_paths.Add(dir);
Expand Down Expand Up @@ -208,7 +210,8 @@ public static bool GeneratePreviewAudio(
bool check_vaild = false,
bool fast_clip = false,
bool no_skip = false,
SupportEncodingType encoding_type = SupportEncodingType.Any)
SupportEncodingType encoding_type = SupportEncodingType.Any,
bool ignore_audio_missing = false)
{
var created_audio_handles = new HashSet<int>();
var sync_record = new HashSet<int>();
Expand Down Expand Up @@ -257,8 +260,8 @@ public static bool GeneratePreviewAudio(
resourceId = i,
dataPath = x
})
.Select(x => (x.resourceId, Directory.EnumerateFiles(dir_path, $"{Path.GetFileNameWithoutExtension(x.dataPath)}.*").FirstOrDefault()))
.Select(x => (x.resourceId, LoadAudio(x.Item2)))
.Select(x => (x.resourceId, Directory.EnumerateFiles(dir_path, $"{Path.GetFileNameWithoutExtension(x.dataPath)}.*").FirstOrDefault(), x.dataPath))
.Select(x => (x.resourceId, LoadAudio(x.Item2, x.dataPath)))
.Where(x => x.Item2 is int)
.ToDictionary(x => x.resourceId, x => x.Item2.Value);

Expand Down Expand Up @@ -440,10 +443,16 @@ public static bool GeneratePreviewAudio(
#endregion
}

int? LoadAudio(string audioFilePath)
int? LoadAudio(string audioFilePath, string hintDataPath = default)
{
if (!File.Exists(audioFilePath))
throw new Exception($"Audio file not found: {audioFilePath}");
{
if (!ignore_audio_missing)
throw new Exception($"Audio file not found: {audioFilePath} (hintDataPath : {hintDataPath})");

Console.WriteLine($"Audio file not found: {audioFilePath} (hintDataPath : {hintDataPath}) , but ignore it.");
return default;
}

var buffer = File.ReadAllBytes(audioFilePath);

Expand All @@ -453,7 +462,7 @@ public static bool GeneratePreviewAudio(
handle = BassOpus.CreateStream(buffer, 0, buffer.LongLength, BassFlags.Decode | BassFlags.Float);

if (handle == 0)
return null;
return default;

created_audio_handles.Add(handle);

Expand Down
2 changes: 1 addition & 1 deletion BmsPreviewAudioGenerator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"BmsPreviewAudioGenerator": {
"commandName": "Project",
"commandLineArgs": "-fade_in=\"2000\" -fade_out=\"2000\" -path=\"H:\\LR2Songs\" -start=\"50%\" -end=\"75%\" -batch -no_skip -fast_clip -check_vaild -support_extend_format -encoder=ogg"
"commandLineArgs": "-fade_in=\"2000\" -fade_out=\"2000\" -path=\"F:\\bms-20220606T170829Z-001\\bms\" -start=\"50%\" -end=\"75%\" -batch -no_skip -ignore_audio_missing -fast_clip -check_vaild -support_extend_format -encoder=ogg"
}
}
}

0 comments on commit becc02c

Please sign in to comment.