コード例 #1
0
        static int Main(string[] args)
        {
            Log.writeLine += WriteLine;
#if DEBUG
            //Log.writeLine += WriteLineF;
            Log.level = LogLevel.INFO;//.TRACE;
#else
            Log.level = LogLevel.INFO;
#endif
            int fnIndex = AnalyzeOption(args);

            if (args == null || args.Length != fnIndex + 1)
            {
                Log.WriteLine(LogLevel.ERROR, "引数(.mubファイル)1個欲しいよぉ");
                return(-1);
            }
            if (!File.Exists(args[fnIndex]))
            {
                Log.WriteLine(LogLevel.ERROR, "ファイルが見つかりません");
                return(-1);
            }

            try
            {
                ww = new WaveWriter(SamplingRate);
                ww.Open(
                    Path.Combine(
                        Path.GetDirectoryName(args[fnIndex])
                        , Path.GetFileNameWithoutExtension(args[fnIndex]) + ".wav")
                    );

                MDSound.ym2608       ym2608 = new MDSound.ym2608();
                MDSound.MDSound.Chip chip   = new MDSound.MDSound.Chip
                {
                    type         = MDSound.MDSound.enmInstrumentType.YM2608,
                    ID           = 0,
                    Instrument   = ym2608,
                    Update       = ym2608.Update,
                    Start        = ym2608.Start,
                    Stop         = ym2608.Stop,
                    Reset        = ym2608.Reset,
                    SamplingRate = (uint)SamplingRate,
                    Clock        = opnaMasterClock,
                    Volume       = 0,
                    Option       = new object[] { GetApplicationFolder() }
                };
                mds = new MDSound.MDSound((uint)SamplingRate, (uint)samplingBuffer, new MDSound.MDSound.Chip[] { chip });


#if NETCOREAPP
                System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
                drv = new Driver();
                ((Driver)drv).Init(
                    args[fnIndex]
                    , OPNAWrite
                    , OPNAWaitSend
                    , false
                    , true
                    , false
                    );

                drv.SetLoopCount(loop);

                List <Tuple <string, string> > tags = drv.GetTags();
                if (tags != null)
                {
                    foreach (Tuple <string, string> tag in tags)
                    {
                        if (tag.Item1 == "")
                        {
                            continue;
                        }
                        Log.WriteLine(LogLevel.INFO, string.Format("{0,-16} : {1}", tag.Item1, tag.Item2));
                    }
                }

                drv.StartRendering((int)SamplingRate, (int)opnaMasterClock);

                drv.MusicSTART(0);

                while (true)
                {
                    EmuCallback(frames, 0, samplingBuffer);
                    //ステータスが0(終了)又は0未満(エラー)の場合はループを抜けて終了
                    if (drv.GetStatus() <= 0)
                    {
                        break;
                    }

                    //Log.writeLine(LogLevel.TRACE, string.Format("{0}  {1}",frames[0],frames[1]));
                    ww.Write(frames, 0, samplingBuffer);
                }

                drv.MusicSTOP();
                drv.StopRendering();
            }
            catch
            {
            }
            finally
            {
                if (ww != null)
                {
                    ww.Close();
                }
            }

            return(0);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: BouKiCHi/mucomWDotNET
        static int Main(string[] args)
        {
            Log.writeLine += WriteLine;
#if DEBUG
            //Log.writeLine += WriteLineF;
            Log.level = LogLevel.INFO;//.TRACE;
#else
            Log.level = LogLevel.INFO;
#endif
            int fnIndex = AnalyzeOption(args);

            if (args == null || args.Length != fnIndex + 1)
            {
                Log.WriteLine(LogLevel.ERROR, "引数(.mubファイル)1個欲しいよぉ");
                return(-1);
            }
            if (!File.Exists(args[fnIndex]))
            {
                Log.WriteLine(LogLevel.ERROR, "ファイルが見つかりません");
                return(-1);
            }

            try
            {
                vw = new VgmWriter();
                vw.Open(
                    Path.Combine(
                        Path.GetDirectoryName(args[fnIndex])
                        , Path.GetFileNameWithoutExtension(args[fnIndex]) + ".vgm")
                    );

#if NETCOREAPP
                System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif

                drv = new Driver();
                ((Driver)drv).Init(
                    args[fnIndex]
                    , OPNAWrite
                    , OPNAWaitSend
                    , false
                    , false
                    , false
                    );

                drv.SetLoopCount(loop);

                tags = drv.GetTags();
                if (tags != null)
                {
                    foreach (Tuple <string, string> tag in tags)
                    {
                        if (tag.Item1 == "")
                        {
                            continue;
                        }
                        Log.WriteLine(LogLevel.INFO, string.Format("{0,-16} : {1}", tag.Item1, tag.Item2));
                    }
                }

                byte[] pcmdata = drv.GetPCMFromSrcBuf();
                if (pcmdata != null && pcmdata.Length > 0)
                {
                    vw.WriteAdpcm(pcmdata);
                }

                drv.StartRendering((int)SamplingRate, (int)opnaMasterClock);

                drv.MusicSTART(0);

                while (true)
                {
                    drv.Rendering();
                    vw.IncrementWaitCOunter();

                    //ステータスが0(終了)又は0未満(エラー)の場合はループを抜けて終了
                    if (drv.GetStatus() <= 0)
                    {
                        break;
                    }
                }

                drv.MusicSTOP();
                drv.StopRendering();
            }
            catch
            {
            }
            finally
            {
                if (vw != null)
                {
                    vw.Close(tags);
                }
            }

            return(0);
        }