mirror of
https://github.com/stuff-by-3-random-dudes/UWUVCI-AIO-WPF
synced 2024-11-10 13:44:13 +00:00
Just use one-pass sox instead of naudio too
This commit is contained in:
parent
05fa853601
commit
1b059b1fba
1 changed files with 20 additions and 48 deletions
|
@ -312,65 +312,37 @@ namespace UWUVCI_AIO_WPF
|
|||
}
|
||||
static void bootsound(string sound)
|
||||
{
|
||||
string btsndPath = Path.Combine(baseRomPath, "meta", "bootSound.btsnd");
|
||||
FileInfo soundFile = new FileInfo(sound);
|
||||
if(soundFile.Extension.Contains("mp3") || soundFile.Extension.Contains("wav"))
|
||||
{
|
||||
//Do Bootsound stuff
|
||||
if (soundFile.Extension.Contains("mp3"))
|
||||
// Convert input file to 6 second .wav
|
||||
using (Process sox = new Process())
|
||||
{
|
||||
using (Mp3FileReader mp3 = new Mp3FileReader(sound))
|
||||
{
|
||||
using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3))
|
||||
{
|
||||
WaveFileWriter.CreateWaveFile(Path.Combine(tempPath, "in.wav"), pcm);
|
||||
}
|
||||
sox.StartInfo.UseShellExecute = false;
|
||||
sox.StartInfo.CreateNoWindow = true;
|
||||
sox.StartInfo.FileName = Path.Combine(toolsPath, "sox.exe");
|
||||
sox.StartInfo.Arguments = $"\"{sound}\" -b 16 \"{Path.Combine(tempPath, "bootSound.wav")}\" channels 2 rate 48k trim 0 6";
|
||||
sox.Start();
|
||||
sox.WaitForExit();
|
||||
}
|
||||
//convert to btsnd
|
||||
wav2btsnd(Path.Combine(tempPath, "bootSound.wav"), btsndPath);
|
||||
File.Delete(Path.Combine(tempPath, "bootSound.wav"));
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Copy(sound, Path.Combine(tempPath, "in.wav"));
|
||||
}
|
||||
//extract SOX.zip
|
||||
using(Process zip = new Process())
|
||||
{
|
||||
if (Directory.Exists(Path.Combine(toolsPath, "SOX"))) { Directory.Delete(Path.Combine(toolsPath, "SOX"), true); }
|
||||
if (!mvvm.debug)
|
||||
{
|
||||
zip.StartInfo.UseShellExecute = false;
|
||||
zip.StartInfo.CreateNoWindow = true;
|
||||
}
|
||||
|
||||
zip.StartInfo.FileName = Path.Combine(toolsPath, "7za.exe");
|
||||
zip.StartInfo.Arguments = $"x \"{Path.Combine(toolsPath, "SOX.zip")}\" -o\"{Path.Combine(toolsPath, "SOX")}\"";
|
||||
zip.Start();
|
||||
zip.WaitForExit();
|
||||
}
|
||||
//Convert stuff
|
||||
using (Process p = new Process())
|
||||
{
|
||||
p.StartInfo.FileName = Path.Combine(toolsPath, "SOX", "sox.exe");
|
||||
p.StartInfo.Arguments = $"\"{Path.Combine(tempPath, "in.wav")}\" -b 16 \"{Path.Combine(tempPath, "converted.wav")}\" channels 2 rate 48k trim 0 6";
|
||||
p.Start();
|
||||
p.WaitForExit();
|
||||
File.Delete("in.wav");
|
||||
}
|
||||
//Delete SOX Folder
|
||||
Directory.Delete(Path.Combine(toolsPath, "SOX"), true);
|
||||
|
||||
//convert to btsnd
|
||||
sound = Path.Combine(tempPath, "sound.btsnd");
|
||||
wav2btsnd(Path.Combine(tempPath, "converted.wav"), sound);
|
||||
}
|
||||
//Copy BootSound to location
|
||||
File.Delete(Path.Combine(baseRomPath, "meta", "bootSound.btsnd"));
|
||||
File.Copy(sound, Path.Combine(baseRomPath, "meta", "bootSound.btsnd"));
|
||||
File.Delete(btsndPath);
|
||||
File.Copy(sound, btsndPath);
|
||||
}
|
||||
}
|
||||
|
||||
private static void wav2btsnd(string input_wav, string output_btsnd)
|
||||
private static void wav2btsnd(string inputWav, string outputBtsnd)
|
||||
{
|
||||
// credits to the original creator of wav2btsnd for the general logic
|
||||
byte[] buffer = File.ReadAllBytes(input_wav);
|
||||
using (FileStream output = new FileStream(output_btsnd, FileMode.OpenOrCreate))
|
||||
byte[] buffer = File.ReadAllBytes(inputWav);
|
||||
using (FileStream output = new FileStream(outputBtsnd, FileMode.OpenOrCreate))
|
||||
using (BinaryWriter writer = new BinaryWriter(output))
|
||||
{
|
||||
writer.Write(new byte[] {0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0});
|
||||
|
|
Loading…
Reference in a new issue