private void LoadFromRawFile(IArchData channel, string fullPath) { switch (channel) { case XwmaArchData xwma: xwma.Data.Data = File.ReadAllBytes(fullPath); var dpds = Path.ChangeExtension(fullPath, ".dpds"); if (File.Exists(dpds)) { xwma.Dpds.Data = File.ReadAllBytes(dpds); } var fmt = Path.ChangeExtension(fullPath, ".fmt"); if (File.Exists(fmt)) { xwma.Fmt.Data = File.ReadAllBytes(fmt); } break; case Atrac9ArchData at9: at9.Data.Data = File.ReadAllBytes(fullPath); break; case OpusArchData opus: opus.Data.Data = File.ReadAllBytes(fullPath); break; default: channel.Data.Data = File.ReadAllBytes(fullPath); //Console.WriteLine($"[WARN] {fullPath} is not used."); break; } channel.SetPsbArchData(channel.ToPsbArchData()); }
public bool TryGetArchData(PSB psb, PsbDictionary dic, out IArchData data) { data = null; //if (psb.Platform != PsbSpec.nx) //{ // return false; //} if (dic.Count != 1 || !(dic["archData"] is PsbDictionary archDic)) { return(false); } if (archDic["body"] is PsbDictionary body && body["data"] is PsbResource aData && body["sampleCount"] is PsbNumber sampleCount && archDic["ext"] is PsbString ext && ext.Value == Extensions[0] && archDic["samprate"] is PsbNumber sampRate) { data = new OpusArchData { Data = aData, SampRate = sampRate.IntValue, SampleCount = sampleCount.IntValue }; return(true); } return(false); }
public bool CanToWave(IArchData archData, Dictionary <string, object> context = null) { if (archData is Atrac9ArchData) { return(true); } return(false); }
public byte[] ToWave(IArchData archData, Dictionary <string, object> context = null) { VagFile vag = new VagFile(); if (vag.LoadFromStream(new MemoryStream(archData.Data.Data))) { return(vag.ToWave().ToArray()); } return(null); }
public byte[] ToWave(IArchData archData, Dictionary <string, object> context = null) { NxOpusReader reader = new NxOpusReader(); var data = reader.Read(archData.Data.Data); using MemoryStream oms = new MemoryStream(); WaveWriter writer = new WaveWriter(); writer.WriteToStream(data, oms, new WaveConfiguration { Codec = WaveCodec.Pcm16Bit }); //only 16Bit supported return(oms.ToArray()); }
public bool CanToWave(IArchData archData, Dictionary <string, object> context = null) { if (archData is PsArchData psArch) { if (psArch.Data?.Data != null && psArch.Data.Data.Length > 4) { if (psArch.Data.Data.AsciiEqual("RIFF")) { return(true); } } } return(false); }
public bool TryGetArchData(PSB psb, PsbDictionary dic, out IArchData data) { data = null; if (psb.Platform == PsbSpec.ps4 || psb.Platform == PsbSpec.vita) { if (dic.Count == 1 && dic["archData"] is PsbResource res) { data = new Atrac9ArchData { Data = res }; return(true); } return(false); } return(false); }
/// <summary> /// Load a common audio file into a channel /// </summary> /// <param name="channel">target channel</param> /// <param name="fullPath">path to load audio file</param> /// <param name="fileName">used in some audio types to keep file name</param> /// <param name="fileExt">common audio extension like "wav"</param> /// <param name="encodeExt">encode audio extension like "vag"</param> /// <param name="context"></param> private void LoadFileToChannel(IArchData channel, string fullPath, string fileName, string fileExt, string encodeExt, FreeMountContext context) { var newArch = context.WaveToArchData(this, encodeExt, File.ReadAllBytes(fullPath), fileName, channel.WaveExtension); if (newArch != null) { channel.SetPsbArchData(newArch.ToPsbArchData()); } else { if (channel.Extension == fileExt) { LoadFromRawFile(channel, fullPath); } else { Console.WriteLine( $"[WARN] There is no encoder for {channel.Extension}! {fullPath} is not used."); } } }
public bool TryGetArchData(PSB psb, PsbDictionary dic, out IArchData data) { data = null; if (psb.Platform == PsbSpec.win) { if (dic.Count == 1 && dic["archData"] is PsbDictionary archDic && archDic["data"] is PsbResource aData && archDic["dpds"] is PsbResource aDpds && archDic["fmt"] is PsbResource aFmt && archDic["wav"] is PsbString aWav) { data = new XwmaArchData() { Data = aData, Fmt = aFmt, Dpds = aDpds, Wav = aWav.Value }; return(true); } return(false); } return(false); }
public byte[] ToWave(IArchData archData, Dictionary <string, object> context = null) { if (string.IsNullOrEmpty(ToolPath)) { archData.WaveExtension = Extensions[0]; return(((XwmaArchData)archData).ToXwma()); } archData.WaveExtension = ".wav"; var xwmaBytes = ((XwmaArchData)archData).ToXwma(); var tempFile = Path.GetTempFileName(); File.WriteAllBytes(tempFile, xwmaBytes); var tempOutFile = Path.GetTempFileName(); byte[] outBytes = null; try { ProcessStartInfo info = new ProcessStartInfo(ToolPath, $"\"{tempFile}\" \"{tempOutFile}\"") { WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true }; Process process = Process.Start(info); process?.WaitForExit(); outBytes = File.ReadAllBytes(tempOutFile); File.Delete(tempFile); File.Delete(tempOutFile); } catch (Exception e) { Console.WriteLine(e); } return(outBytes); }
/// <summary> /// Convert <see cref="IArchData"/> to Wave /// </summary> /// <param name="archData"></param> /// <param name="context"></param> /// <returns></returns> public static byte[] TryToWave(this IArchData archData, FreeMountContext context) { return(context?.ArchDataToWave(archData.Extension, archData)); }
/// <summary> /// Set archData value to archData object /// </summary> /// <param name="archData"></param> /// <param name="val"></param> public static void SetPsbArchData(this IArchData archData, IPsbValue val) { archData.PsbArchData["archData"] = val; }
public bool CanToWave(IArchData archData, Dictionary <string, object> context = null) { return(true); }
public byte[] ArchDataToWave(string ext, IArchData archData) { return(FreeMount._.ArchDataToWave(ext, archData, Context)); }
public byte[] ToWave(IArchData archData, Dictionary <string, object> context = null) { WavArchData arch = archData as WavArchData; return(arch?.ToWav()); }