Example #1
0
        /// <summary>
        /// From a binary wave.
        /// </summary>
        /// <param name="b"></param>
        public FISP(BinaryWave b)
        {
            //New info.
            regions = new List <RegionInfo>();
            tracks  = new List <TrackInfo>();
            data    = new DataInfo();
            stream  = new StreamInfo();

            //Stream info.
            stream.sampleRate        = b.SampleRate;
            stream.encoding          = 2;
            stream.isLoop            = b.Loops && b.LoopEndSample != 0xFFFFFFFF;
            stream.loopEnd           = b.LoopEndSample;
            stream.loopStart         = b.LoopStartSample;
            stream.originalLoopEnd   = b.LoopEndSample;
            stream.originalLoopStart = b.LoopStartSample;
            stream.vMajor            = 1;
            stream.vMinor            = 1;
            stream.vRevision         = 0;

            //Tracks.
            for (int i = 0; i < b.ChannelPans.Length; i++)
            {
                try {
                    if (b.ChannelPans[i] == BinaryWave.ChannelPan.Left)
                    {
                        tracks.Add(new TrackInfo()
                        {
                            channels = new List <byte>()
                            {
                                (byte)i, (byte)(i + 1)
                            }, volume = 100, pan = 64
                        });
                    }
                    else if (b.ChannelPans[i] == BinaryWave.ChannelPan.Middle)
                    {
                        tracks.Add(new TrackInfo()
                        {
                            channels = new List <byte>()
                            {
                                (byte)i
                            }, volume = 100, pan = 64
                        });
                    }
                } catch { }
            }

            //Data.
            data.data = (b.Data.GetDataWAV(b.DspAdpcmInfo, b.LoopEndSample == 0xFFFFFFFF ? b.NumSamples : b.LoopEndSample) as short[][]).ToList();
        }
Example #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");*/
    }
Example #3
0
    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!!!") + "\"");
    }