Skip to content

Commit

Permalink
Update voiced line editor to account for new subtitle features (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jan 25, 2025
1 parent eeb322d commit 12d9503
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 27 deletions.
24 changes: 17 additions & 7 deletions src/SerialLoops.Lib/Items/VoicedLineItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using HaruhiChokuretsuLib.Archive.Event;
using HaruhiChokuretsuLib.Audio.ADX;
using HaruhiChokuretsuLib.Util;
using NAudio.Flac;
Expand All @@ -24,7 +25,7 @@ public VoicedLineItem(string voiceFile, int index, Project project) : base(Path.
_vceFile = voiceFile;
Index = index;
}

public IWaveProvider GetWaveProvider(ILogger log, bool loop = false)
{
byte[] adxBytes = [];
Expand Down Expand Up @@ -61,7 +62,7 @@ public IWaveProvider GetWaveProvider(ILogger log, bool loop = false)
return new AdxWaveProvider(decoder);
}

public void Replace(string audioFile, string baseDirectory, string iterativeDirectory, string vceCachedFile, ILogger log)
public void Replace(string audioFile, string baseDirectory, string iterativeDirectory, string vceCachedFile, ILogger log, VoiceMapFile.VoiceMapEntry vceMapEntry = null)
{
// The MP3 decoder is able to create wave files but for whatever reason messes with the ADX encoder
// So we just convert to WAV AOT
Expand All @@ -78,18 +79,21 @@ public void Replace(string audioFile, string baseDirectory, string iterativeDire
WaveFileWriter.CreateWaveFile(vceCachedFile, vorbisReader.ToSampleProvider().ToWaveProvider16());
audioFile = vceCachedFile;
}

using WaveStream audio = Path.GetExtension(audioFile).ToLower() switch
{
".wav" => new WaveFileReader(audioFile),
".flac" => new FlacReader(audioFile),
_ => null,
};

if (audio is null)
{
log.LogError("Invalid audio file selected.");
log.LogWarning(audioFile);
return;
}

if (audio.WaveFormat.Channels > 1 || audio.WaveFormat.SampleRate > SoundItem.MAX_SAMPLERATE)
{
string newAudioFile = "";
Expand All @@ -115,19 +119,25 @@ public void Replace(string audioFile, string baseDirectory, string iterativeDire
}
}

log.Log($"Encoding audio to AHX...");
audioFile = newAudioFile;
log.Log("Encoding audio to AHX...");
AdxUtil.EncodeWav(newAudioFile, Path.Combine(baseDirectory, VoiceFile), true);
}
else
{
log.Log($"Encoding audio to AHX...");
log.Log("Encoding audio to AHX...");
AdxUtil.EncodeAudio(audio, Path.Combine(baseDirectory, VoiceFile), true);
}
File.Copy(Path.Combine(baseDirectory, VoiceFile), Path.Combine(iterativeDirectory, VoiceFile), true);

// Adjust subtitle length to new voice item length
if (vceMapEntry is not null)
{
vceMapEntry.Timer = (int)(audio.TotalTime.TotalSeconds * 180 + 30);
UnsavedChanges = true;
}
}

public override void Refresh(Project project, ILogger log)
{
}
}
}
}
4 changes: 2 additions & 2 deletions src/SerialLoops.Lib/SerialLoops.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<PackageReference Include="BunLabs.NAudio.Flac" Version="2.0.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="8.3.0.1" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.48.3" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.50.1" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="NitroPacker.Core" Version="2.6.0" />
<PackageReference Include="NLayer" Version="1.16.0" />
<PackageReference Include="NLayer.NAudioSupport" Version="1.4.0" />
<PackageReference Include="QuikGraph" Version="2.5.0" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
<PackageReference Include="SoftCircuits.OrderedDictionary" Version="3.2.0" />
<PackageReference Include="SoftCircuits.OrderedDictionary" Version="3.3.0" />
<PackageReference Include="Topten.RichTextKit" Version="0.4.167" />
<PackageReference Include="VCDiff" Version="4.0.1" />
</ItemGroup>
Expand Down
63 changes: 63 additions & 0 deletions src/SerialLoops/Assets/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/SerialLoops/Assets/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3086,4 +3086,25 @@ This action is irreversible.</value>
<data name="Import Item Image" xml:space="preserve">
<value>Import Item Image</value>
</data>
<data name="Force Drop Shadow" xml:space="preserve">
<value>Force Drop Shadow</value>
</data>
<data name="YELLOW" xml:space="preserve">
<value>Yellow</value>
</data>
<data name="OFF_WHITE" xml:space="preserve">
<value>Off White</value>
</data>
<data name="GRAY" xml:space="preserve">
<value>Gray</value>
</data>
<data name="LAVENDER" xml:space="preserve">
<value>Lavender</value>
</data>
<data name="RED" xml:space="preserve">
<value>Red</value>
</data>
<data name="FADED_GRAY" xml:space="preserve">
<value>Faded Gray</value>
</data>
</root>
4 changes: 2 additions & 2 deletions src/SerialLoops/SerialLoops.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@
<!--The behaviors packages past 11.1.0.4 break our middle click to close functionality, so we're staying on that package for now.-->
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0.4" />
<PackageReference Include="BinToss.GroupBox.Avalonia" Version="1.0.0" />
<PackageReference Include="DialogHost.Avalonia" Version="0.8.1" />
<PackageReference Include="DialogHost.Avalonia" Version="0.9.1" />
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
<PackageReference Include="MiniToolbar.Avalonia" Version="1.0.81" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
<PackageReference Include="SixLabors.Fonts" Version="2.0.7" />
<PackageReference Include="SixLabors.Fonts" Version="2.0.9" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
<PackageReference Include="Tabalonia" Version="0.10.4.2" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 12d9503

Please sign in to comment.