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)
|
static void bootsound(string sound)
|
||||||
{
|
{
|
||||||
|
string btsndPath = Path.Combine(baseRomPath, "meta", "bootSound.btsnd");
|
||||||
FileInfo soundFile = new FileInfo(sound);
|
FileInfo soundFile = new FileInfo(sound);
|
||||||
if(soundFile.Extension.Contains("mp3") || soundFile.Extension.Contains("wav"))
|
if(soundFile.Extension.Contains("mp3") || soundFile.Extension.Contains("wav"))
|
||||||
{
|
{
|
||||||
//Do Bootsound stuff
|
// Convert input file to 6 second .wav
|
||||||
if (soundFile.Extension.Contains("mp3"))
|
using (Process sox = new Process())
|
||||||
{
|
{
|
||||||
using (Mp3FileReader mp3 = new Mp3FileReader(sound))
|
sox.StartInfo.UseShellExecute = false;
|
||||||
{
|
sox.StartInfo.CreateNoWindow = true;
|
||||||
using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3))
|
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";
|
||||||
WaveFileWriter.CreateWaveFile(Path.Combine(tempPath, "in.wav"), pcm);
|
sox.Start();
|
||||||
}
|
sox.WaitForExit();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
|
//convert to btsnd
|
||||||
sound = Path.Combine(tempPath, "sound.btsnd");
|
wav2btsnd(Path.Combine(tempPath, "bootSound.wav"), btsndPath);
|
||||||
wav2btsnd(Path.Combine(tempPath, "converted.wav"), sound);
|
File.Delete(Path.Combine(tempPath, "bootSound.wav"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Copy BootSound to location
|
||||||
|
File.Delete(btsndPath);
|
||||||
|
File.Copy(sound, btsndPath);
|
||||||
}
|
}
|
||||||
//Copy BootSound to location
|
|
||||||
File.Delete(Path.Combine(baseRomPath, "meta", "bootSound.btsnd"));
|
|
||||||
File.Copy(sound, Path.Combine(baseRomPath, "meta", "bootSound.btsnd"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// credits to the original creator of wav2btsnd for the general logic
|
||||||
byte[] buffer = File.ReadAllBytes(input_wav);
|
byte[] buffer = File.ReadAllBytes(inputWav);
|
||||||
using (FileStream output = new FileStream(output_btsnd, FileMode.OpenOrCreate))
|
using (FileStream output = new FileStream(outputBtsnd, FileMode.OpenOrCreate))
|
||||||
using (BinaryWriter writer = new BinaryWriter(output))
|
using (BinaryWriter writer = new BinaryWriter(output))
|
||||||
{
|
{
|
||||||
writer.Write(new byte[] {0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0});
|
writer.Write(new byte[] {0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0});
|
||||||
|
|
Loading…
Reference in a new issue