Esempio n. 1
0
        //War tools.
        #region WarTools

        /// <summary>
        /// Extract waves.
        /// </summary>
        public override void WarExtractWave()
        {
            //File open check.
            if (!FileTest(null, null, false, true))
            {
                return;
            }

            //Safety.
            string path = GetFolderPath();

            if (path == "")
            {
                return;
            }

            //Write each wave.
            int count = 0;

            foreach (var w in (File as SoundWaveArchive))
            {
                if (w == null)
                {
                    System.IO.File.WriteAllBytes(path + "/" + count.ToString("D5") + " - " + w.Name + " (NULL).wav", new byte[0]);
                }
                else
                {
                    System.IO.File.WriteAllBytes(path + "/" + count.ToString("D5") + " - " + w.Name + ".wav", RiffWaveFactory.CreateRiffWave(w.Wav).ToBytes());
                }

                count++;
            }
        }
Esempio n. 2
0
    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");*/
    }
Esempio n. 3
0
        /// <summary>
        /// Export node.
        /// </summary>
        public override void NodeExport()
        {
            Wave w = (File as SoundWaveArchive)[tree.SelectedNode.Index];

            if (w != null)
            {
                //Get export path.
                SaveFileDialog s = new SaveFileDialog();
                s.RestoreDirectory = true;
                s.FileName         = tree.SelectedNode.Text;
                s.Filter           = "Wave|*.wav|Wave (3ds or Wii U)|*.bfwav;*.bcwav|Wave (Switch)|*.bfwav|Stream (3ds or Wii U)|*.bfstm;*.bcstm|Stream (Switch)|*.bfstm";
                s.ShowDialog();
                if (Path.GetExtension(s.FileName) == "")
                {
                    s.FileName += "wav";
                }
                if (s.FileName != "")
                {
                    //Get file data.
                    WriteMode m = WriteMode.Cafe;
                    if (Path.GetExtension(s.FileName).ToLower()[2] == 'c')
                    {
                        m = WriteMode.CTR;
                    }
                    byte[] b = null;
                    switch (s.FilterIndex)
                    {
                    //Wave.
                    case 1:
                        b = RiffWaveFactory.CreateRiffWave(w.Wav).ToBytes();
                        break;

                    //SDK Wave.
                    case 2:
                        if (m == WriteMode.Cafe)
                        {
                            b = w.Wav.ToBytes(ByteOrder.BigEndian, true);
                        }
                        else
                        {
                            b = w.Wav.ToBytes(ByteOrder.LittleEndian);
                        }
                        break;

                    //SDK Wave Switch.
                    case 3:
                        b = w.Wav.ToBytes(ByteOrder.LittleEndian, true);
                        break;

                    //SDK Stream.
                    case 4:
                        if (m == WriteMode.Cafe)
                        {
                            b = StreamFactory.CreateStream(w.Wav, w.Wav.fileHeader.vMajor, w.Wav.fileHeader.vMinor, w.Wav.fileHeader.vRevision).ToBytes(ByteOrder.BigEndian, true);
                        }
                        else
                        {
                            b = StreamFactory.CreateStream(w.Wav, w.Wav.fileHeader.vMajor, w.Wav.fileHeader.vMinor, w.Wav.fileHeader.vRevision).ToBytes(ByteOrder.LittleEndian);
                        }
                        break;

                    //SDK Stream Switch.
                    case 5:
                        b = StreamFactory.CreateStream(w.Wav, w.Wav.fileHeader.vMajor, w.Wav.fileHeader.vMinor, w.Wav.fileHeader.vRevision).ToBytes(ByteOrder.LittleEndian, true);
                        break;
                    }

                    //Write if possible.
                    if (b != null)
                    {
                        System.IO.File.WriteAllBytes(s.FileName, b);
                    }
                }
            }
            else
            {
                MessageBox.Show("You can't export a null file!", "Notice:");
            }
        }