static void AudioEncoder(AudioEncoderOptions options) { bool IsCeltFile(string path) { string ext = Path.GetExtension(path); return(ext.Equals(".clt", StringComparison.CurrentCultureIgnoreCase)); } // Imports audio file Celt celt = IsCeltFile(options.InputPath) ? Celt.FromFile(options.InputPath) : Celt.FromAudio(options.InputPath); Console.WriteLine($"Opened {options.InputPath}"); string o = options.OutputPath; // Exports audio file if (IsCeltFile(o)) { celt.Export(o); } else { o = Path.Combine(Path.GetDirectoryName(o), Path.GetFileNameWithoutExtension(o)) + ".wav"; // Creates directory if it doesn't exist if (!Directory.Exists(Path.GetDirectoryName(o))) { Directory.CreateDirectory(Path.GetDirectoryName(o)); } celt.WriteToWavFile(o); } Console.WriteLine($"Saved {o}"); }
private void EncodeAudio(FusedSong song) { string mapPath = GetFilePath("hashes.json"); // Imports existing mappings if found AudioHashMappings audioMap = File.Exists(mapPath) ? AudioHashMappings.Import(mapPath) : new AudioHashMappings(); string GetPackageFilePath(string relativePath) => Path.Combine(_packageManager.CurrentPackageDirectory + "\\songs\\", song.Identifier.Replace(".", "\\") + "\\" + relativePath); bool IsCeltFile(string path) { string ext = Path.GetExtension(path); return(ext.Equals(".clt", StringComparison.CurrentCultureIgnoreCase)); } HashMapping EncodeAudio(string input, string output, HashMapping oldMap) { if (!File.Exists(input)) { // Delete if no input if (File.Exists(output)) { File.Delete(output); } return(oldMap); } else if (!File.Exists(output)) { // Encodes audio (Import from celt supported) Celt celt = IsCeltFile(input) ? Celt.FromFile(input) : Celt.FromAudio(input); celt.Export(output); // Updates hashes return(HashMapping.CreateMapping(input, output)); } HashMapping newMap = HashMapping.CreateMapping(input, output); if (newMap.Input != oldMap.Input || newMap.Output != oldMap.Output) { // Encodes audio Celt celt = IsCeltFile(input) ? Celt.FromFile(input) : Celt.FromAudio(input); celt.Export(output); // Updates output hash newMap.Output = HashMapping.ComputeHashFromFile(output); } // Else means they're equal, no need to re-encode // Returns new hashes return(newMap); } audioMap.Preview = EncodeAudio(GetFilePath(song.AudioPaths.Preview), GetPackageFilePath("preview\\audio.clt"), audioMap.Preview); audioMap.Backing = EncodeAudio(GetFilePath(song.AudioPaths.Backing), GetPackageFilePath("gamestems\\back\\audio.clt"), audioMap.Backing); audioMap.Bass = EncodeAudio(GetFilePath(song.AudioPaths.Bass), GetPackageFilePath("gamestems\\bass\\audio.clt"), audioMap.Bass); audioMap.Drums = EncodeAudio(GetFilePath(song.AudioPaths.Drums), GetPackageFilePath("gamestems\\drums\\audio.clt"), audioMap.Drums); audioMap.LeadGuitar = EncodeAudio(GetFilePath(song.AudioPaths.LeadGuitar), GetPackageFilePath("gamestems\\gtr1\\audio.clt"), audioMap.LeadGuitar); audioMap.RhythmGuitar = EncodeAudio(GetFilePath(song.AudioPaths.RhythmGuitar), GetPackageFilePath("gamestems\\gtr2\\audio.clt"), audioMap.RhythmGuitar); audioMap.Vox = EncodeAudio(GetFilePath(song.AudioPaths.Vox), GetPackageFilePath("gamestems\\vox\\audio.clt"), audioMap.Vox); audioMap.Export(mapPath); }