示例#1
0
        public RealChip()
        {
            log.ForcedWrite("RealChip:Ctr:STEP 00(Start)");

            int n = 0;

            try
            {
                nScci = new NScci.NScci();
                n     = nScci.NSoundInterfaceManager_.getInterfaceCount();
                if (n == 0)
                {
                    nScci.Dispose();
                    nScci = null;
                    log.ForcedWrite("RealChip:Ctr:Not found SCCI.");
                }
                else
                {
                    log.ForcedWrite(string.Format("RealChip:Ctr:Found SCCI.(Interface count={0})", n));
                    getScciInstances();
                    nScci.NSoundInterfaceManager_.setLevelDisp(false);
                }
            }
            catch
            {
                nScci = null;
            }

            log.ForcedWrite("RealChip:Ctr:STEP 01");
            try
            {
                nc86ctl = new Nc86ctl.Nc86ctl();
                nc86ctl.initialize();
                n = nc86ctl.getNumberOfChip();
                if (n == 0)
                {
                    nc86ctl.deinitialize();
                    nc86ctl = null;
                    log.ForcedWrite("RealChip:Ctr:Not found G.I.M.I.C.");
                }
                else
                {
                    log.ForcedWrite(string.Format("RealChip:Ctr:Found G.I.M.I.C.(Interface count={0})", n));
                    Nc86ctl.NIRealChip nirc = nc86ctl.getChipInterface(0);
                    nirc.reset();
                }
            }
            catch
            {
                nc86ctl = null;
            }
            log.ForcedWrite("RealChip:Ctr:STEP 02(Success)");
        }
示例#2
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (scci != null)
            {
                scci.Dispose();
                scci = null;
            }

            if (c86 != null)
            {
                c86.deinitialize();
                c86 = null;
            }
        }
示例#3
0
 public void Close()
 {
     if (nScci != null)
     {
         try
         {
             nScci.Dispose();
         }
         catch { }
         nScci = null;
     }
     if (nc86ctl != null)
     {
         try
         {
             nc86ctl.deinitialize();
         }
         catch { }
         nc86ctl = null;
     }
 }
示例#4
0
        static int Main(string[] args)
        {
            Log.writeLine += WriteLine;
#if DEBUG
            //Log.writeLine += WriteLineF;
            Log.level = LogLevel.TRACE;// 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);
            }

            rsc = CheckDevice();

            try
            {
                SineWaveProvider16 waveProvider;
                int latency = 1000;

                switch (device)
                {
                case 0:
                    waveProvider = new SineWaveProvider16();
                    waveProvider.SetWaveFormat((int)SamplingRate, 2);
                    callBack    = EmuCallback;
                    audioOutput = new DirectSoundOut(latency);
                    audioOutput.Init(waveProvider);
                    break;

                case 1:
                case 2:
                    trdMain              = new Thread(new ThreadStart(RealCallback));
                    trdMain.Priority     = ThreadPriority.Highest;
                    trdMain.IsBackground = true;
                    trdMain.Name         = "trdVgmReal";
                    sw     = Stopwatch.StartNew();
                    swFreq = Stopwatch.Frequency;
                    break;
                }

                List <MDSound.MDSound.Chip> lstChips = new List <MDSound.MDSound.Chip>();
                MDSound.MDSound.Chip        chip     = null;

                MDSound.ym2608 ym2608 = new MDSound.ym2608();
                for (int i = 0; i < 2; i++)
                {
                    chip = new MDSound.MDSound.Chip
                    {
                        type         = MDSound.MDSound.enmInstrumentType.YM2608,
                        ID           = (byte)i,
                        Instrument   = ym2608,
                        Update       = ym2608.Update,
                        Start        = ym2608.Start,
                        Stop         = ym2608.Stop,
                        Reset        = ym2608.Reset,
                        SamplingRate = SamplingRate,
                        Clock        = opnaMasterClock,
                        Volume       = 0,
                        Option       = new object[] { GetApplicationFolder() }
                    };
                    lstChips.Add(chip);
                }
                MDSound.ym2610 ym2610 = new MDSound.ym2610();
                for (int i = 0; i < 2; i++)
                {
                    chip = new MDSound.MDSound.Chip
                    {
                        type         = MDSound.MDSound.enmInstrumentType.YM2610,
                        ID           = (byte)i,
                        Instrument   = ym2610,
                        Update       = ym2610.Update,
                        Start        = ym2610.Start,
                        Stop         = ym2610.Stop,
                        Reset        = ym2610.Reset,
                        SamplingRate = SamplingRate,
                        Clock        = opnbMasterClock,
                        Volume       = 0,
                        Option       = new object[] { GetApplicationFolder() }
                    };
                    lstChips.Add(chip);
                }
                mds = new MDSound.MDSound(SamplingRate, samplingBuffer
                                          , lstChips.ToArray());

#if NETCOREAPP
                System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
                List <ChipAction> lca = new List <ChipAction>();
                mucomChipAction   ca;
                ca = new mucomChipAction(OPNAWriteP, null, OPNAWaitSend); lca.Add(ca);
                ca = new mucomChipAction(OPNAWriteS, null, null); lca.Add(ca);
                ca = new mucomChipAction(OPNBWriteP, OPNBWriteAdpcmP, null); lca.Add(ca);
                ca = new mucomChipAction(OPNBWriteS, OPNBWriteAdpcmS, null); lca.Add(ca);

                List <MmlDatum> bl     = new List <MmlDatum>();
                byte[]          srcBuf = File.ReadAllBytes(args[fnIndex]);
                foreach (byte b in srcBuf)
                {
                    bl.Add(new MmlDatum(b));
                }

                drv = new Driver.Driver();
                ((Driver.Driver)drv).Init(
                    lca
                    , bl.ToArray()
                    , null
                    , new object[] {
                    false
                    , isLoadADPCM
                    , loadADPCMOnly
                    , args[fnIndex]
                }
                    );

                List <Tuple <string, string> > tags = ((Driver.Driver)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));
                    }
                }

                if (loadADPCMOnly)
                {
                    return(0);
                }

                drv.StartRendering((int)SamplingRate,
                                   new Tuple <string, int>[] {
                    new Tuple <string, int>("YM2608", (int)opnaMasterClock)
                    , new Tuple <string, int>("YM2608", (int)opnaMasterClock)
                    , new Tuple <string, int>("YM2610B", (int)opnbMasterClock)
                    , new Tuple <string, int>("YM2610B", (int)opnbMasterClock)
                }
                                   );

                switch (device)
                {
                case 0:
                    audioOutput.Play();
                    break;

                case 1:
                case 2:
                    trdMain.Start();
                    break;
                }

                drv.MusicSTART(0);

                Log.WriteLine(LogLevel.INFO, "終了する場合は何かキーを押してください");

                while (true)
                {
                    System.Threading.Thread.Sleep(1);
                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                    //ステータスが0(終了)又は0未満(エラー)の場合はループを抜けて終了
                    if (drv.GetStatus() <= 0)
                    {
                        if (drv.GetStatus() == 0)
                        {
                            System.Threading.Thread.Sleep((int)(latency * 2.0));//実際の音声が発音しきるまでlatency*2の分だけ待つ
                        }
                        break;
                    }
                }

                drv.MusicSTOP();
                drv.StopRendering();
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogLevel.FATAL, "演奏失敗");
                Log.WriteLine(LogLevel.FATAL, string.Format("message:{0}", ex.Message));
                Log.WriteLine(LogLevel.FATAL, string.Format("stackTrace:{0}", ex.StackTrace));
            }
            finally
            {
                if (audioOutput != null)
                {
                    audioOutput.Stop();
                    while (audioOutput.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(1);
                    }
                    audioOutput.Dispose();
                    audioOutput = null;
                }
                if (trdMain != null)
                {
                    trdClosed = true;
                    while (!trdStopped)
                    {
                        Thread.Sleep(1);
                    }
                }
                if (nc86ctl != null)
                {
                    nc86ctl.deinitialize();
                    nc86ctl = null;
                }
                if (nScci != null)
                {
                    nScci.Dispose();
                    nScci = null;
                }
            }

            return(0);
        }
示例#5
0
        private static RSoundChip CheckDevice()
        {
            SChipType ct     = null;
            int       iCount = 0;

            switch (device)
            {
            case 1:    //GIMIC存在チェック
                nc86ctl = new Nc86ctl.Nc86ctl();
                nc86ctl.initialize();
                iCount = nc86ctl.getNumberOfChip();
                if (iCount == 0)
                {
                    nc86ctl.deinitialize();
                    nc86ctl = null;
                    Log.WriteLine(LogLevel.ERROR, "Not found G.I.M.I.C.");
                    device = 0;
                    break;
                }
                for (int i = 0; i < iCount; i++)
                {
                    NIRealChip rc  = nc86ctl.getChipInterface(i);
                    NIGimic2   gm  = rc.QueryInterface();
                    ChipType   cct = gm.getModuleType();
                    int        o   = -1;
                    if (cct == ChipType.CHIP_YM2608 || cct == ChipType.CHIP_YMF288 || cct == ChipType.CHIP_YM2203)
                    {
                        ct = new SChipType();
                        ct.SoundLocation = -1;
                        ct.BusID         = i;
                        string seri = gm.getModuleInfo().Serial;
                        if (!int.TryParse(seri, out o))
                        {
                            o  = -1;
                            ct = null;
                            continue;
                        }
                        ct.SoundChip     = o;
                        ct.ChipName      = gm.getModuleInfo().Devname;
                        ct.InterfaceName = gm.getMBInfo().Devname;
                        break;
                    }
                }
                RC86ctlSoundChip rsc = null;
                if (ct == null)
                {
                    nc86ctl.deinitialize();
                    nc86ctl = null;
                    Log.WriteLine(LogLevel.ERROR, "Not found G.I.M.I.C.(OPNA module)");
                    device = 0;
                }
                else
                {
                    rsc        = new RC86ctlSoundChip(-1, ct.BusID, ct.SoundChip);
                    rsc.c86ctl = nc86ctl;
                    rsc.init();

                    rsc.SetMasterClock(7987200); //SoundBoardII
                    rsc.setSSGVolume(63);        //PC-8801
                }
                return(rsc);

            case 2:    //SCCI存在チェック
                nScci  = new NScci.NScci();
                iCount = nScci.NSoundInterfaceManager_.getInterfaceCount();
                if (iCount == 0)
                {
                    nScci.Dispose();
                    nScci = null;
                    Log.WriteLine(LogLevel.ERROR, "Not found SCCI.");
                    device = 0;
                    break;
                }
                for (int i = 0; i < iCount; i++)
                {
                    NSoundInterface      iIntfc = nScci.NSoundInterfaceManager_.getInterface(i);
                    NSCCI_INTERFACE_INFO iInfo  = nScci.NSoundInterfaceManager_.getInterfaceInfo(i);
                    int sCount = iIntfc.getSoundChipCount();
                    for (int s = 0; s < sCount; s++)
                    {
                        NSoundChip sc = iIntfc.getSoundChip(s);
                        int        t  = sc.getSoundChipType();
                        if (t == 1)
                        {
                            ct = new SChipType();
                            ct.SoundLocation = 0;
                            ct.BusID         = i;
                            ct.SoundChip     = s;
                            ct.ChipName      = sc.getSoundChipInfo().cSoundChipName;
                            ct.InterfaceName = iInfo.cInterfaceName;
                            goto scciExit;
                        }
                    }
                }
                scciExit :;
                RScciSoundChip rssc = null;
                if (ct == null)
                {
                    nScci.Dispose();
                    nScci = null;
                    Log.WriteLine(LogLevel.ERROR, "Not found SCCI(OPNA module).");
                    device = 0;
                }
                else
                {
                    rssc      = new RScciSoundChip(0, ct.BusID, ct.SoundChip);
                    rssc.scci = nScci;
                    rssc.init();
                }
                return(rssc);
            }

            return(null);
        }
示例#6
0
        static int Main(string[] args)
        {
            Log.writeLine += WriteLine;
#if DEBUG
            //Log.writeLine += WriteLineF;
            Log.level = LogLevel.INFO;
#else
            Log.level = LogLevel.INFO;
#endif
            int fnIndex = AnalyzeOption(args);
            int mIndex  = -1;

            if (args != null)
            {
                for (int i = fnIndex; i < args.Length; i++)
                {
                    if ((Path.GetExtension(args[i]).ToUpper().IndexOf(".M") < 0) &&
                        (Path.GetExtension(args[i]).ToUpper().IndexOf(".XML") < 0)
                        )
                    {
                        continue;
                    }
                    mIndex = i;
                    break;
                }
            }

            if (mIndex < 0)
            {
                Log.WriteLine(LogLevel.INFO, "引数(.Mファイル)1個欲しいよぉ...");
                return(-1);
            }

            srcFile = args[mIndex];

            if (!File.Exists(args[mIndex]))
            {
                Log.WriteLine(LogLevel.ERROR, string.Format("ファイル[{0}]が見つかりません", args[mIndex]));
                return(-1);
            }

            rsc = CheckDevice();

            try
            {
                SineWaveProvider16 waveProvider;
                int latency = 1000;

                switch (device)
                {
                case 0:
                    waveProvider = new SineWaveProvider16();
                    waveProvider.SetWaveFormat((int)SamplingRate, 2);
                    callBack    = EmuCallback;
                    audioOutput = new DirectSoundOut(latency);
                    audioOutput.Init(waveProvider);
                    break;

                case 1:
                case 2:
                    trdMain              = new Thread(new ThreadStart(RealCallback));
                    trdMain.Priority     = ThreadPriority.Highest;
                    trdMain.IsBackground = true;
                    trdMain.Name         = "trdVgmReal";
                    sw     = Stopwatch.StartNew();
                    swFreq = Stopwatch.Frequency;
                    break;
                }

                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 = SamplingRate,
                    Clock        = opnaMasterClock,
                    Volume       = 0,
                    Option       = new object[] { GetApplicationFolder() }
                };

                ppz8em = new MDSound.PPZ8();
                MDSound.MDSound.Chip chipp = new MDSound.MDSound.Chip
                {
                    type         = MDSound.MDSound.enmInstrumentType.PPZ8,
                    ID           = 0,
                    Instrument   = ppz8em,
                    Update       = ppz8em.Update,
                    Start        = ppz8em.Start,
                    Stop         = ppz8em.Stop,
                    Reset        = ppz8em.Reset,
                    SamplingRate = SamplingRate,
                    Clock        = opnaMasterClock,
                    Volume       = 0,
                    Option       = null
                };

                ppsdrv = new MDSound.PPSDRV();
                MDSound.MDSound.Chip chipps = new MDSound.MDSound.Chip
                {
                    type         = MDSound.MDSound.enmInstrumentType.PPSDRV,
                    ID           = 0,
                    Instrument   = ppsdrv,
                    Update       = ppsdrv.Update,
                    Start        = ppsdrv.Start,
                    Stop         = ppsdrv.Stop,
                    Reset        = ppsdrv.Reset,
                    SamplingRate = (uint)
                                   (
                        device == 0
                            ? SamplingRate
                            : (
                            userPPSFREQ == -1
                                ? (
                                device == 1
                                ? SamplingRatePPSGIMIC
                                : SamplingRatePPSSCCI
                                )
                                : (uint)userPPSFREQ
                            )
                                   ),
                    Clock  = opnaMasterClock,
                    Volume = 0,
                    Option = device == 0 ? null : (new object[] { (Action <int, int>)PPSDRVpsg })
                };

                p86em = new MDSound.P86();
                MDSound.MDSound.Chip chip86 = new MDSound.MDSound.Chip
                {
                    type         = MDSound.MDSound.enmInstrumentType.mpcmX68k,//TBD
                    ID           = 0,
                    Instrument   = p86em,
                    Update       = p86em.Update,
                    Start        = p86em.Start,
                    Stop         = p86em.Stop,
                    Reset        = p86em.Reset,
                    SamplingRate = SamplingRate,
                    Clock        = opnaMasterClock,
                    Volume       = 0,
                    Option       = null
                };


                mds = new MDSound.MDSound(SamplingRate, samplingBuffer, new MDSound.MDSound.Chip[] { chip, chipp, chipps, chip86 });
                //ppz8em = new PPZ8em(SamplingRate);
                //ppsdrv = new PPSDRV(SamplingRate);



                Common.Environment env = new Common.Environment();
                env.AddEnv("pmd");
                env.AddEnv("pmdopt");
                envPmd    = env.GetEnvVal("pmd");
                envPmdOpt = env.GetEnvVal("pmdopt");

                List <string> opt = (envPmdOpt == null) ? (new List <string>()) : envPmdOpt.ToList();
                for (int i = fnIndex; i < args.Length; i++)
                {
                    opt.Add(args[i]);
                }
                mIndex += (envPmdOpt == null ? 0 : envPmdOpt.Length) - fnIndex;

#if NETCOREAPP
                System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
                drv = new Driver.Driver();
                Driver.PMDDotNETOption dop = new Driver.PMDDotNETOption();
                dop.isAUTO        = isAUTO;
                dop.isNRM         = isNRM;
                dop.isSPB         = isSPB;
                dop.isVA          = isVA;
                dop.usePPS        = usePPS;
                dop.usePPZ        = usePPZ;
                dop.isLoadADPCM   = false;
                dop.loadADPCMOnly = false;
                //dop.ppz8em = ppz8em;
                //dop.ppsdrv = ppsdrv;
                dop.envPmd    = envPmd;
                dop.srcFile   = srcFile;
                dop.jumpIndex = -1;// -1;
                List <string> pop         = new List <string>();
                bool          pmdvolFound = false;
                for (int i = 0; i < opt.Count; i++)
                {
                    if (i == mIndex)
                    {
                        continue;
                    }
                    string op = opt[i].ToUpper().Trim();
                    pop.Add(op);
                    if (op.IndexOf("-D") >= 0 || op.IndexOf("/D") >= 0)
                    {
                        pmdvolFound = true;
                    }
                }

                Log.WriteLine(LogLevel.INFO, "");

                ((Driver.Driver)drv).Init(
                    srcFile
                    , OPNAWrite
                    , OPNAWaitSend
                    , dop
                    , pop.ToArray()
                    , appendFileReaderCallback
                    , PPZ8Write
                    , PPSDRVWrite
                    , P86Write
                    );


                //AUTO指定の場合に構成が変わるので、構成情報を受け取ってから音量設定を行う
                isNRM  = dop.isNRM;
                isSPB  = dop.isSPB;
                isVA   = dop.isVA;
                usePPS = dop.usePPS;
                usePPZ = dop.usePPZ;
                string[] pmdOptionVol = SetVolume();
                //ユーザーがコマンドラインでDオプションを指定していない場合はpmdVolを適用させる
                if (!pmdvolFound && pmdOptionVol != null && pmdOptionVol.Length > 0)
                {
                    ((Driver.Driver)drv).resetOption(pmdOptionVol);//
                }


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

                Log.WriteLine(LogLevel.INFO, "");

                drv.StartRendering((int)SamplingRate
                                   , new Tuple <string, int>[] { new Tuple <string, int>("YM2608", (int)opnaMasterClock) });

                drv.MusicSTART(0);

                switch (device)
                {
                case 0:
                    audioOutput.Play();
                    break;

                case 1:
                case 2:
                    trdMain.Start();
                    break;
                }

                Log.WriteLine(LogLevel.INFO, "演奏を終了する場合は何かキーを押してください(実chip時は特に。)");

                while (true)
                {
                    System.Threading.Thread.Sleep(1);
                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                    //ステータスが0(終了)又は0未満(エラー)の場合はループを抜けて終了
                    if (drv.GetStatus() <= 0)
                    {
                        if (drv.GetStatus() == 0)
                        {
                            System.Threading.Thread.Sleep((int)(latency * 2.0));//実際の音声が発音しきるまでlatency*2の分だけ待つ
                        }
                        break;
                    }

                    if (loop != 0 && drv.GetNowLoopCounter() > loop)
                    {
                        System.Threading.Thread.Sleep((int)(latency * 2.0));//実際の音声が発音しきるまでlatency*2の分だけ待つ
                        break;
                    }
                }

                drv.MusicSTOP();
                drv.StopRendering();
                ((Driver.Driver)drv).dispStatus();
            }
            catch (PmdException pe)
            {
                Log.WriteLine(LogLevel.ERROR, pe.Message);
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogLevel.FATAL, "演奏失敗");
                Log.WriteLine(LogLevel.FATAL, string.Format("message:{0}", ex.Message));
                Log.WriteLine(LogLevel.FATAL, string.Format("stackTrace:{0}", ex.StackTrace));
            }
            finally
            {
                if (((Driver.Driver)drv).renderingException != null)
                {
                    Log.WriteLine(LogLevel.FATAL, "演奏失敗");
                    Log.WriteLine(LogLevel.FATAL, string.Format("message:{0}", ((Driver.Driver)drv).renderingException.Message));
                    Log.WriteLine(LogLevel.FATAL, string.Format("stackTrace:{0}", ((Driver.Driver)drv).renderingException.StackTrace));
                }

                if (audioOutput != null)
                {
                    audioOutput.Stop();
                    while (audioOutput.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(1);
                    }
                    audioOutput.Dispose();
                    audioOutput = null;
                }
                if (trdMain != null)
                {
                    trdClosed = true;
                    while (!trdStopped)
                    {
                        Thread.Sleep(1);
                    }
                }
                if (nc86ctl != null)
                {
                    nc86ctl.deinitialize();
                    nc86ctl = null;
                }
                if (nScci != null)
                {
                    nScci.Dispose();
                    nScci = null;
                }
            }

            return(0);
        }
示例#7
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            for (int i = 0; i < 1; i++)
            {
                try
                {
                    MsgDisp("SCCI:処理開始");

                    MsgDisp("SCCI:コンストラクタ開始");
                    scci = new NScci.NScci();
                    MsgDisp("SCCI:コンストラクタ終了");

                    MsgDisp("SCCI:getInterfaceCount開始");
                    int n = scci.NSoundInterfaceManager_.getInterfaceCount();
                    MsgDisp("SCCI:getInterfaceCount完了");
                    if (n == 0)
                    {
                        MsgDisp("SCCI:SCCI見つからず");
                        scci.Dispose();
                        scci = null;
                    }
                    else
                    {
                        for (int j = 0; j < n; j++)
                        {
                            MsgDisp(string.Format("SCCI:====================== Interface {0}", j));
                            MsgDisp("SCCI:getInterface 開始");
                            NSoundInterface nsif = scci.NSoundInterfaceManager_.getInterface(j);
                            MsgDisp("SCCI:getInterface 完了");

                            MsgDisp("SCCI:getSoundChipCount 開始");
                            int c = nsif.getSoundChipCount();
                            MsgDisp("SCCI:getSoundChipCount 完了");

                            for (int k = 0; k < c; k++)
                            {
                                MsgDisp("SCCI:------------------- Chip Information");

                                MsgDisp("SCCI:getSoundChip 開始");
                                NSoundChip nsc = nsif.getSoundChip(k);
                                MsgDisp("SCCI:getSoundChip 完了");

                                MsgDisp("SCCI:getSoundChipInfo 開始");
                                NSCCI_SOUND_CHIP_INFO nssci = nsc.getSoundChipInfo();
                                MsgDisp("SCCI:getSoundChipInfo 完了");

                                MsgDisp(string.Format("SCCI:cSoundChipName {0}", nssci.cSoundChipName));
                                MsgDisp(string.Format("SCCI:dClock {0}", nssci.dClock));
                                MsgDisp(string.Format("SCCI:iSoundChip {0}", nssci.iSoundChip));
                                MsgDisp(string.Format("SCCI:bIsUsed {0}", nssci.bIsUsed));
                            }
                        }

                        if (scci != null)
                        {
                            scci.Dispose();
                            scci = null;
                        }
                    }
                }
                catch (Exception escci)
                {
                    MsgDisp("SCCI:Exception発生");
                    MsgDisp(string.Format("SCCI:Message:{0}", escci.Message));
                    MsgDisp(string.Format("SCCI:StackTrace:{0}", escci.StackTrace));
                }

                try
                {
                    MsgDisp("c86ctl:処理開始");

                    MsgDisp("c86ctl:Nc86ctl 開始");
                    c86 = new Nc86ctl.Nc86ctl();
                    MsgDisp("c86ctl:Nc86ctl 完了");

                    MsgDisp("c86ctl:initialize 開始");
                    c86.initialize();
                    MsgDisp("c86ctl:initialize 完了");

                    MsgDisp("c86ctl:getNumberOfChip 開始");
                    int nc = c86.getNumberOfChip();
                    MsgDisp("c86ctl:getNumberOfChip 完了");
                    if (nc == 0)
                    {
                        MsgDisp("c86ctl:deinitialize 開始");
                        c86.deinitialize();
                        MsgDisp("c86ctl:deinitialize 完了");
                        MsgDisp("c86ctl:c86ctl見つからず");
                        c86.Dispose();
                        c86 = null;
                    }
                    else
                    {
                        MsgDisp("c86ctl:getChipInterface 開始");
                        NIRealChip nirc = c86.getChipInterface(0);
                        MsgDisp("c86ctl:getChipInterface 完了");

                        MsgDisp("c86ctl:reset 開始");
                        nirc.reset();
                        MsgDisp("c86ctl:reset 完了");

                        MsgDisp("c86ctl:QueryInterface 開始");
                        NIGimic2 nig = nirc.QueryInterface();
                        MsgDisp("c86ctl:QueryInterface 完了");

                        UInt16 aa = 0;
                        UInt16 bb = 0;
                        UInt16 cc = 0;
                        UInt16 dd = 0;
                        MsgDisp("c86ctl:getFWVer 開始");
                        nig.getFWVer(ref aa, ref bb, ref cc, ref dd);
                        MsgDisp(string.Format("c86ctl:getFWVer 完了({0}.{1}.{2}.{3})", aa, bb, cc, dd));

                        MsgDisp("c86ctl:getMBInfo 開始");
                        Devinfo dv = nig.getMBInfo();
                        MsgDisp(string.Format("c86ctl:getMBInfo 完了 {0}", dv.Devname));

                        MsgDisp("c86ctl:getModuleType 開始");
                        ChipType tp = nig.getModuleType();
                        MsgDisp(string.Format("c86ctl:getModuleType 完了 {0}", tp));

                        MsgDisp("c86ctl:getModuleInfo 開始");
                        Devinfo di = nig.getModuleInfo();
                        MsgDisp(string.Format("c86ctl:getModuleInfo 完了 {0}", di.Devname));

                        MsgDisp("c86ctl:getSSGVolume 開始");
                        byte vol = nig.getSSGVolume();
                        MsgDisp(string.Format("c86ctl:getSSGVolume 完了 {0}", vol));

                        MsgDisp("c86ctl:getPLLClock 開始");
                        uint clock = nig.getPLLClock();
                        MsgDisp(string.Format("c86ctl:getPLLClock 完了 {0}", clock));
                    }
                }
                catch (Exception ec86)
                {
                    MsgDisp("c86ctl:Exception発生");
                    MsgDisp(string.Format("c86ctl:Message:{0}", ec86.Message));
                    MsgDisp(string.Format("c86ctl:StackTrace:{0}", ec86.StackTrace));
                }
            }
        }
示例#8
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);
            }

            rsc = CheckDevice();

            try
            {
                SineWaveProvider16 waveProvider;
                int latency = 1000;

                switch (device)
                {
                case 0:
                    waveProvider = new SineWaveProvider16();
                    waveProvider.SetWaveFormat((int)SamplingRate, 2);
                    callBack    = EmuCallback;
                    audioOutput = new DirectSoundOut(latency);
                    audioOutput.Init(waveProvider);
                    break;

                case 1:
                case 2:
                    trdMain              = new Thread(new ThreadStart(RealCallback));
                    trdMain.Priority     = ThreadPriority.Highest;
                    trdMain.IsBackground = true;
                    trdMain.Name         = "trdVgmReal";
                    sw     = Stopwatch.StartNew();
                    swFreq = Stopwatch.Frequency;
                    break;
                }

                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 = SamplingRate,
                    Clock        = opnaMasterClock,
                    Volume       = 0,
                    Option       = new object[] { GetApplicationFolder() }
                };
                mds = new MDSound.MDSound(SamplingRate, samplingBuffer, new MDSound.MDSound.Chip[] { chip });



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

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

                if (loadADPCMOnly)
                {
                    return(0);
                }

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

                switch (device)
                {
                case 0:
                    audioOutput.Play();
                    break;

                case 1:
                case 2:
                    trdMain.Start();
                    break;
                }

                drv.MSTART(0);

                Log.WriteLine(LogLevel.INFO, "終了する場合は何かキーを押してください");

                while (true)
                {
                    System.Threading.Thread.Sleep(1);
                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                    //ステータスが0(終了)又は0未満(エラー)の場合はループを抜けて終了
                    if (drv.Status() <= 0)
                    {
                        if (drv.Status() == 0)
                        {
                            System.Threading.Thread.Sleep((int)(latency * 2.0));//実際の音声が発音しきるまでlatency*2の分だけ待つ
                        }
                        break;
                    }
                }

                drv.MSTOP();
                drv.StopRendering();
            }
            catch
            {
            }
            finally
            {
                if (audioOutput != null)
                {
                    audioOutput.Stop();
                    audioOutput.Dispose();
                    audioOutput = null;
                }
                if (trdMain != null)
                {
                    ;
                }
                if (nc86ctl != null)
                {
                    nc86ctl.deinitialize();
                    nc86ctl = null;
                }
                if (nScci != null)
                {
                    nScci.Dispose();
                    nScci = null;
                }
            }

            return(0);
        }