/// <summary> /// Get the wave data from a file path. /// </summary> /// <returns>Wave data.</returns> public Wave GetWave() { string wavePath = GetWavePath(); if (wavePath == "") { return(null); } //Extension. string ext = Path.GetExtension(wavePath).ToLower(); //RIFF. if (ext.StartsWith(".w")) { RiffWave r = new RiffWave(); r.Load(System.IO.File.ReadAllBytes(wavePath)); return(new Wave() { Wav = WaveFactory.CreateWave(r, true, forceWavMaj, forceWavMin, forceWavRev) }); } //Wave. else if (ext.EndsWith("wav")) { b_wav b = new b_wav(); b.Load(System.IO.File.ReadAllBytes(wavePath)); return(new Wave() { Wav = b }); } //Stream. else if (ext.EndsWith("stm")) { b_stm s = new b_stm(); s.Load(System.IO.File.ReadAllBytes(wavePath)); return(new Wave() { Wav = WaveFactory.CreateWave(s, forceWavMaj, forceWavMin, forceWavRev) }); } //Null. return(null); }
public void ConvertFile(string filename, string OutputFormat) { FISP file; string outputfilepath; switch (filename.Substring(filename.Length - 4)) { case ".wav": RiffWave w = new RiffWave(); w.Load(File.ReadAllBytes(filename)); file = new FISP(w); outputfilepath = entry_output_file_path.Text; if (checkbutton_output_copy_input_name.Active) { int lastDotLocate = entry_input_file_path.Text.LastIndexOf('.'); if (lastDotLocate > 0) { if (OutputFormat == "BWAV") { outputfilepath = entry_input_file_path.Text.Substring(0, lastDotLocate) + ".bwav"; } if (OutputFormat == "WAV") { outputfilepath = entry_input_file_path.Text.Substring(0, lastDotLocate) + ".wav"; } } else { if (OutputFormat == "BWAV") { outputfilepath = entry_input_file_path.Text + ".bwav"; } if (OutputFormat == "WAV") { outputfilepath = entry_input_file_path.Text + ".wav"; } } } //MsgBox("in?:" + filename +"\nout:"+outputfilepath); file.stream.isLoop = checkbutton_looping.Active; file.stream.loopStart = (uint)spinbutton_loop_start.Value; file.stream.loopEnd = (uint)spinbutton_loop_end.Value; //File.WriteAllBytes(outputfilepath, BinaryWave.FromRiff(w).ToBytes()); if (OutputFormat == "BWAV") { File.WriteAllBytes(outputfilepath, BinaryWave.FromFISP(file).ToBytes()); } if (OutputFormat == "WAV") { File.WriteAllBytes(outputfilepath, RiffWaveFactory.CreateRiffWave(file).ToBytes()); } break; case "bwav": BinaryWave r = new BinaryWave(); r.Load(File.ReadAllBytes(filename)); file = new FISP(r); outputfilepath = entry_output_file_path.Text; if (checkbutton_output_copy_input_name.Active) { int lastDotLocate = entry_input_file_path.Text.LastIndexOf('.'); if (lastDotLocate > 0) { if (OutputFormat == "BWAV") { outputfilepath = entry_input_file_path.Text.Substring(0, lastDotLocate) + ".bwav"; } if (OutputFormat == "WAV") { outputfilepath = entry_input_file_path.Text.Substring(0, lastDotLocate) + ".wav"; } } else { if (OutputFormat == "BWAV") { outputfilepath = entry_input_file_path.Text + ".bwav"; } if (OutputFormat == "WAV") { outputfilepath = entry_input_file_path.Text + ".wav"; } } } //riffWave file.stream.encoding = (byte)1; if (OutputFormat == "BWAV") { File.WriteAllBytes(outputfilepath, file.ToBytes()); } if (OutputFormat == "WAV") { File.WriteAllBytes(outputfilepath, RiffWaveFactory.CreateRiffWave(file).ToBytes()); } break; default: MsgBox("Unknown type - Only WAV and BWAV are supported.\nIf file isn't WAV or BWAV but like Ogg, convert before. (Oddly, some WAVs crash. Exporting with Audacity may work.)\nThis check depends on the file name (mainly the extension), not the actual file contents.\nIf it is WAV or BWAV, please change the file name.\nBut BWAV input support is too bad. In that case, try using VGMStream.", "Error", MessageType.Error, ButtonsType.Ok); return; } //file.stream /*MsgBox("file.stream.isLoop: \"" + (file.stream.isLoop.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.loopStart: \"" + (file.stream.loopStart.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.loopEnd: \"" + (file.stream.loopEnd.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.originalLoopStart: \"" + (file.stream.originalLoopStart.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.originalLoopEnd: \"" + (file.stream.originalLoopEnd.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.encoding: \"" + (file.stream.encoding.ToString() ?? "NULL!!!") + "\"\n" + //+ "file.stream.magic: \"" + (file.stream.magic.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.sampleRate: \"" + (file.stream.sampleRate.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.secretInfo: \"" + (file.stream.secretInfo.ToString() ?? "NULL!!!") + "\"\n");*/ }
protected void OnButtonLoadClicked(object sender, EventArgs e) { var filepath = entry_input_file_path.Text; System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(filepath); try { stringBuilder.Replace("~", Environment.GetEnvironmentVariable("HOME"), 0, 1); } catch (Exception ex) { } filepath = stringBuilder.ToString(); if (!IsReadable(filepath, true)) { return; } entry_loaded_file_path.Text = filepath; FISP file; switch (filepath.Substring(filepath.Length - 4)) { case ".wav": entry_loaded_file_format.Text = "WAV"; RiffWave w = new RiffWave(); w.Load(File.ReadAllBytes(filepath)); file = new FISP(w); break; case "bwav": entry_loaded_file_format.Text = "BWAV"; BinaryWave r = new BinaryWave(); if (r.Codic == 0) { entry_loaded_file_format.Text = "BWAV(PCM16)"; } if (r.Codic == 1) { entry_loaded_file_format.Text = "BWAV(DSPADPCM)"; } //RiffWave riffWave = new RiffWave(); r.Load(File.ReadAllBytes(filepath)); file = new FISP(r); break; default: entry_loaded_file_format.Text = "Unknown"; MsgBox("Unknown type - Only WAV and BWAV are supported.\nIf file isn't WAV or BWAV but like Ogg, convert before. (Oddly, some WAVs crash. Exporting with Audacity may work.)\nThis check depends on the file name (mainly the extension), not the actual file contents.\nIf it is WAV or BWAV, please change the file name.\nBut BWAV input support is too bad. In that case, try using VGMStream.", "Error", MessageType.Error, ButtonsType.Ok); return; } checkbutton_looping.Sensitive = spinbutton_loop_start.Sensitive = spinbutton_loop_end.Sensitive = hbox_convert_buttons.Sensitive = true; checkbutton_looping.Inconsistent = false; spinbutton_loop_start.Adjustment.Upper = spinbutton_loop_end.Adjustment.Upper = double.MaxValue; checkbutton_looping.Active = file.stream.isLoop; spinbutton_loop_start.Value = file.stream.loopStart; spinbutton_loop_end.Value = file.stream.loopEnd; //MsgBox(spinbutton_loop_start.Adjustment.Upper.ToString()+"\n" +spinbutton_loop_end.Adjustment.Upper.ToString()); MsgBox("file.stream.isLoop: \"" + (file.stream.isLoop.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.loopStart: \"" + (file.stream.loopStart.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.loopEnd: \"" + (file.stream.loopEnd.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.originalLoopStart: \"" + (file.stream.originalLoopStart.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.originalLoopEnd: \"" + (file.stream.originalLoopEnd.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.encoding: \"" + (file.stream.encoding.ToString() ?? "NULL!!!") + "\"\n" //+ "file.stream.magic: \"" + (file.stream.magic.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.sampleRate: \"" + (file.stream.sampleRate.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.secretInfo: \"" + (file.stream.secretInfo.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.vMajor: \"" + (file.stream.vMajor.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.vMinor: \"" + (file.stream.vMinor.ToString() ?? "NULL!!!") + "\"\n" + "file.stream.vRevision: \"" + (file.stream.vRevision.ToString() ?? "NULL!!!") + "\""); }
/// <summary> /// Import files. /// </summary> public override void WarBatchImport() { //File open check. if (!FileTest(null, null, false, true)) { return; } //Safety. string path = GetFolderPath(); if (path == "") { return; } //Sort files. List <string> files = Directory.EnumerateFiles(path).ToList(); for (int i = files.Count - 1; i >= 0; i--) { if (!files[i].Contains("wav")) { files.RemoveAt(i); } } //Read each file. foreach (string d in files) { if (Path.GetExtension(d).ToLower().Contains(".wav")) { byte[] b = System.IO.File.ReadAllBytes(d); if (b.Length > 0) { RiffWave r = new RiffWave(); r.Load(b); (File as SoundWaveArchive).Add(new Wave() { Wav = WaveFactory.CreateWave(r, true, forceWavMaj, forceWavMin, forceWavRev) }); } else { (File as SoundWaveArchive).Add(null); } } else { byte[] b = System.IO.File.ReadAllBytes(d); if (b.Length > 0) { Wave a = new Wave(); a.Wav = new b_wav(); a.Wav.Load(b); (File as SoundWaveArchive).Add(a); } else { (File as SoundWaveArchive).Add(null); } } } //Update. UpdateNodes(); DoInfoStuff(); }