Exemple #1
0
        /// <summary>
        /// Create a wave from a FISP.
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public static b_wav CreateWave(FISP f, byte vMajor, byte vMinor, byte vRevision)
        {
            //New wave.
            b_wav b = new b_wav();

            //Trim the fat from each loop.
            object channels = new short[f.data.data.Count()][];

            for (int i = 0; i < (channels as short[][]).Length; i++)
            {
                List <short> l = new List <short>();

                for (int j = 0; j < f.stream.loopEnd; j++)
                {
                    l.Add(f.data.data[i][j]);
                }

                (channels as short[][])[i] = l.ToArray();
            }

            //PCM8 conversion.
            if (f.stream.encoding == EncodingTypes.PCM8)
            {
                channels = EncoderFactory.Pcm16ToPcm8(channels as short[][]);
            }

            //If looped.
            if (f.stream.isLoop)
            {
                b = WaveFactory.CreateWave(f.stream.sampleRate, f.stream.loopEnd, channels, f.stream.encoding, vMajor, vMinor, vRevision, f.stream.loopStart);
            }

            //Not looped.
            else
            {
                b = WaveFactory.CreateWave(f.stream.sampleRate, f.stream.loopEnd, channels, f.stream.encoding, vMajor, vMinor, vRevision);
            }

            //Info.
            b.info.originalLoopStart = f.stream.originalLoopStart;

            return(b);
        }
Exemple #2
0
        /// <summary>
        /// Make a RIFF Wave from a FISP.
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public static RiffWave CreateRiffWave(FISP f)
        {
            //New wave.
            RiffWave r = new RiffWave();

            //Not looped.
            if (!f.stream.isLoop)
            {
                r = RiffWaveFactory.CreateRiffWave(f.stream.sampleRate, 2, f.data.data.ToArray());
            }

            //Looped.
            else
            {
                r = RiffWaveFactory.CreateRiffWave(f.stream.sampleRate, 2, f.data.data.ToArray(), f.stream.loopStart, f.stream.loopEnd);
            }

            return(r);
        }
Exemple #3
0
 /// <summary>
 /// Create a binary wave.
 /// </summary>
 /// <param name="f">FISP.</param>
 public static BinaryWave FromFISP(FISP f)
 {
     //Set data.
     return(new BinaryWave(StreamFactory.CreateStream(f, 4, 0, 0)));
 }
Exemple #4
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");*/
    }
Exemple #5
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!!!") + "\"");
    }
Exemple #6
0
        /// <summary>
        /// Create a wave from a FISP.
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public static b_stm CreateStream(FISP f, byte vMajor, byte vMinor, byte vRevision)
        {
            //New stream.
            b_stm s = new b_stm();

            //Trim the fat from each loop.
            object channels = new short[f.data.data.Count()][];

            for (int i = 0; i < (channels as short[][]).Length; i++)
            {
                List <short> l = new List <short>();

                for (int j = 0; j < f.stream.loopEnd; j++)
                {
                    l.Add(f.data.data[i][j]);
                }

                (channels as short[][])[i] = l.ToArray();
            }

            //PCM8 conversion.
            if (f.stream.encoding == EncodingTypes.PCM8)
            {
                channels = EncoderFactory.Pcm16ToPcm8(channels as short[][]);
            }

            //If looped.
            if (f.stream.isLoop)
            {
                s = StreamFactory.CreateStream(f.stream.sampleRate, f.stream.loopEnd, channels, f.stream.encoding, vMajor, vMinor, vRevision, f.stream.loopStart);
            }

            //Not looped.
            else
            {
                s = StreamFactory.CreateStream(f.stream.sampleRate, f.stream.loopEnd, channels, f.stream.encoding, vMajor, vMinor, vRevision);
            }

            //Make tracks.
            s.info.tracks = new List <b_stm.TrackInfo>();
            foreach (FISP.TrackInfo i in f.tracks)
            {
                b_stm.TrackInfo t = new b_stm.TrackInfo();
                t.globalChannelIndexTable         = new Table <byte>();
                t.globalChannelIndexTable.count   = (uint)i.channels.Count();
                t.globalChannelIndexTable.entries = i.channels;
                t.pan          = i.pan;
                t.span         = i.span;
                t.surroundMode = i.surroundMode;
                t.volume       = i.volume;
                s.info.tracks.Add(t);
            }

            //Nullify.
            if (f.tracks.Count() <= 0)
            {
                s.info.tracks = null;
            }

            //Make regions. EXPERIMENTAL! Yell at me if this doesn't work.
            s.region = null;
            if (f.regions.Count > 0)
            {
                s.region         = new SoundNStreamRegionBlock();
                s.region.regions = new SoundNStreamRegionBlock.RegionInfo[f.regions.Count];
                int index = 0;
                foreach (FISP.RegionInfo i in f.regions)
                {
                    SoundNStreamRegionBlock.RegionInfo r = new SoundNStreamRegionBlock.RegionInfo();
                    r.start    = i.start;
                    r.end      = i.end;
                    r.loopInfo = new SoundNStreamRegionBlock.RegionInfo.DspAdpcmLoopInfo[s.info.channels.Count];
                    if (f.stream.encoding >= EncodingTypes.DSP_ADPCM)
                    {
                        for (int j = 0; j < s.info.channels.Count; j++)
                        {
                            short h1 = 0;
                            short h2 = 0;
                            if (r.start >= 1)
                            {
                                h1 = f.data.data[j][r.start - 1];
                            }
                            if (r.start >= 2)
                            {
                                h2 = f.data.data[j][r.start - 2];
                            }

                            r.loopInfo[j] = new SoundNStreamRegionBlock.RegionInfo.DspAdpcmLoopInfo()
                            {
                                loopPredScale = s.info.channels[j].dspAdpcmInfo.loop_pred_scale,
                                loopYn1       = h1,
                                loopYn2       = h2
                            };
                        }
                    }
                    s.region.regions[index] = r;

                    index++;
                }
            }

            //Set info.
            s.info.streamSoundInfo.originalLoopStart = f.stream.originalLoopStart;
            s.info.streamSoundInfo.originalLoopEnd   = f.stream.originalLoopEnd;
            s.info.streamSoundInfo.secretInfo        = f.stream.secretInfo;

            return(s);
        }
Exemple #7
0
 public FisPRepository(FISP fisp)
 {
     _fisp = fisp;
 }