Skip to content

Commit

Permalink
Tweak format names
Browse files Browse the repository at this point in the history
  • Loading branch information
libertyernie committed Dec 21, 2021
1 parent 4eeda99 commit ad2a1e7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
13 changes: 12 additions & 1 deletion LoopingAudioConverter/Exporters/MP3Exporter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using RunProcessAsTask;
using MSFContainerLib;
using RunProcessAsTask;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -19,6 +21,15 @@ public async Task WriteFileAsync(PCM16Audio lwav, string output_dir, string orig
throw new AudioExporterException("Invalid character (\") found in output filename");
}

if (Path.GetExtension(lwav.OriginalPath ?? "").Equals(".msf", StringComparison.InvariantCultureIgnoreCase)) {
byte[] data = File.ReadAllBytes(lwav.OriginalPath);
IPcmAudioSource<short> msf = MSF.Parse(data);
if (msf is MSF_MP3 mp3) {
File.WriteAllBytes(outPath, mp3.Body);
return;
}
}

string infile = TempFiles.Create("wav");
File.WriteAllBytes(infile, lwav.Export());

Expand Down
1 change: 1 addition & 0 deletions LoopingAudioConverter/Interfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface IRenderingAudioImporter : IAudioImporter {
}

public interface IEffectEngine {
string GetImporterName();
PCM16Audio ApplyEffects(PCM16Audio lwav, int channels = int.MaxValue, decimal db = 0, decimal amplitude = 1, int rate = int.MaxValue, decimal pitch_semitones = 0, decimal tempo_ratio = 1);
Task WriteFileAsync(PCM16Audio lwav, string output_filename, string encodingParameters);
}
Expand Down
48 changes: 27 additions & 21 deletions LoopingAudioConverter/OptionsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,38 @@ public OptionsForm() {
hcaOptions = new HcaOptions();
adxOptions = new AdxOptions();

string effectEngineName = Program.BuildImporters()
.OfType<IEffectEngine>()
.Select(x => x.GetImporterName())
.DefaultIfEmpty("???")
.First();

var exporters = new[] {
new NVPair<ExporterType>(ExporterType.BRSTM, "BRSTM"),
new NVPair<ExporterType>(ExporterType.BCSTM, "BCSTM"),
new NVPair<ExporterType>(ExporterType.BFSTM, "BFSTM"),
new NVPair<ExporterType>(ExporterType.DSP, "DSP (Nintendo)"),
new NVPair<ExporterType>(ExporterType.IDSP, "IDSP (Nintendo)"),
new NVPair<ExporterType>(ExporterType.HPS, "HPS (HAL)"),
new NVPair<ExporterType>(ExporterType.ADX, "CRI ADX"),
new NVPair<ExporterType>(ExporterType.HCA, "CRI HCA"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BRSTM_ADPCM, "BRSTM (ADPCM) [BrawlLib]"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BRSTM_PCM16, "BRSTM (PCM16) [BrawlLib]"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BCSTM, "BCSTM (ADPCM) [BrawlLib]"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BFSTM, "BFSTM (ADPCM) [BrawlLib]"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BRWAV, "BRWAV (ADPCM) [BrawlLib]"),
new NVPair<ExporterType>(ExporterType.BRSTM, "[VGAudio] BRSTM"),
new NVPair<ExporterType>(ExporterType.BCSTM, "[VGAudio] BCSTM"),
new NVPair<ExporterType>(ExporterType.BFSTM, "[VGAudio] BFSTM"),
new NVPair<ExporterType>(ExporterType.DSP, "[VGAudio] DSP (Nintendo)"),
new NVPair<ExporterType>(ExporterType.IDSP, "[VGAudio] IDSP (Nintendo)"),
new NVPair<ExporterType>(ExporterType.HPS, "[VGAudio] HPS (HAL)"),
new NVPair<ExporterType>(ExporterType.ADX, "[VGAudio] CRI ADX"),
new NVPair<ExporterType>(ExporterType.HCA, "[VGAudio] CRI HCA"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BRSTM_ADPCM, "[BrawlLib] BRSTM (ADPCM)"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BRSTM_PCM16, "[BrawlLib] BRSTM (PCM16)"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BCSTM, "[BrawlLib] BCSTM (ADPCM)"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BFSTM, "[BrawlLib] BFSTM (ADPCM)"),
new NVPair<ExporterType>(ExporterType.BrawlLib_BRWAV, "[BrawlLib] BRWAV (ADPCM)"),
new NVPair<ExporterType>(ExporterType.MSF_PCM16BE, "MSF (PCM16, big-endian)"),
new NVPair<ExporterType>(ExporterType.MSF_PCM16LE, "MSF (PCM16, little-endian)"),
new NVPair<ExporterType>(ExporterType.MSU1, "MSU-1"),
new NVPair<ExporterType>(ExporterType.WAV, "WAV"),
new NVPair<ExporterType>(ExporterType.FLAC, "FLAC"),
new NVPair<ExporterType>(ExporterType.FFmpeg_MP3, "MP3"),
new NVPair<ExporterType>(ExporterType.MP3, "MP3 [LAME]"),
new NVPair<ExporterType>(ExporterType.FFmpeg_AAC_M4A, "AAC (.m4a)"),
new NVPair<ExporterType>(ExporterType.AAC_M4A, "AAC (.m4a) [qaac]"),
new NVPair<ExporterType>(ExporterType.FFmpeg_AAC_ADTS, "AAC (ADTS .aac)"),
new NVPair<ExporterType>(ExporterType.AAC_ADTS, "AAC (ADTS .aac) [qaac]"),
new NVPair<ExporterType>(ExporterType.OggVorbis, "Vorbis (.ogg)"),
new NVPair<ExporterType>(ExporterType.FLAC, $"[{effectEngineName}] FLAC"),
new NVPair<ExporterType>(ExporterType.FFmpeg_MP3, $"[{effectEngineName}] MP3"),
new NVPair<ExporterType>(ExporterType.FFmpeg_AAC_M4A, $"[{effectEngineName}] AAC (.m4a)"),
new NVPair<ExporterType>(ExporterType.FFmpeg_AAC_ADTS, $"[{effectEngineName}] AAC (ADTS .aac)"),
new NVPair<ExporterType>(ExporterType.OggVorbis, $"[{effectEngineName}] Vorbis (.ogg)"),
new NVPair<ExporterType>(ExporterType.MP3, "[LAME] MP3"),
new NVPair<ExporterType>(ExporterType.AAC_M4A, "[qaac] AAC (.m4a)"),
new NVPair<ExporterType>(ExporterType.AAC_ADTS, "[qaac] AAC (ADTS .aac)"),
};
comboBox1.DataSource = exporters;
if (comboBox1.SelectedIndex < 0) comboBox1.SelectedIndex = 0;
Expand Down
38 changes: 19 additions & 19 deletions LoopingAudioConverter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ static void Main(string[] args) {
}
}

public static IEnumerable<IAudioImporter> BuildImporters() {
yield return new WAVImporter();
yield return new VGAudioImporter();
yield return new MP3Importer();
if (ConfigurationManager.AppSettings["faad_path"] is string faad_path)
yield return new MP4Importer(faad_path);
if (ConfigurationManager.AppSettings["vgmplay_path"] is string vgmplay_path)
yield return new VGMImporter(vgmplay_path);
yield return new MSU1();
yield return new MSFImporter();
if (ConfigurationManager.AppSettings["vgmstream_path"] is string vgmstream_path)
yield return new VGMStreamImporter(vgmstream_path);
if (ConfigurationManager.AppSettings["ffmpeg_path"] is string ffmpeg_path)
yield return new FFmpeg(ffmpeg_path);
if (ConfigurationManager.AppSettings["sox_path"] is string sox_path)
yield return new SoX(sox_path);
}

/// <summary>
/// Runs a batch conversion process.
/// </summary>
Expand All @@ -61,25 +79,7 @@ public static async Task RunAsync(Options o, bool showEndDialog = true, IWin32Wi
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

IEnumerable <IAudioImporter> buildImporters() {
yield return new WAVImporter();
yield return new VGAudioImporter();
yield return new MP3Importer();
if (ConfigurationManager.AppSettings["faad_path"] is string faad_path)
yield return new MP4Importer(faad_path);
if (ConfigurationManager.AppSettings["vgmplay_path"] is string vgmplay_path)
yield return new VGMImporter(vgmplay_path);
yield return new MSU1();
yield return new MSFImporter();
if (ConfigurationManager.AppSettings["vgmstream_path"] is string vgmstream_path)
yield return new VGMStreamImporter(vgmstream_path);
if (ConfigurationManager.AppSettings["ffmpeg_path"] is string ffmpeg_path)
yield return new FFmpeg(ffmpeg_path);
if (ConfigurationManager.AppSettings["sox_path"] is string sox_path)
yield return new SoX(sox_path);
}

List<IAudioImporter> importers = buildImporters().ToList();
List<IAudioImporter> importers = BuildImporters().ToList();

IEffectEngine effectEngine = importers.OfType<IEffectEngine>().FirstOrDefault() ?? throw new AudioImporterException("Could not find either ffmpeg or SoX - please specify ffmpeg_path or sox_path in .config file");

Expand Down

0 comments on commit ad2a1e7

Please sign in to comment.