Exemplo n.º 1
0
        //private void WriteLog(LogLevel arg1, string arg2)
        //{
        //disp?.Invoke(arg2);
        //}

        public void InitDriver(
            string fileName
            , List <Action <ChipDatum> > oPNAWrite
            , List <Action <byte[], int, int> > WritePCMData
            , Action <long, int> oPNAWaitSend
            , bool notSoundBoard2
            , musicDriverInterface.MmlDatum[] mubBuf
            , bool isLoadADPCM
            , bool loadADPCMOnly)
        {
            List <ChipAction> lca = new List <ChipAction>();
            mucomChipAction   ca;

            ca = new mucomChipAction(oPNAWrite[0], null, oPNAWaitSend); lca.Add(ca);
            ca = new mucomChipAction(oPNAWrite[1], null, null); lca.Add(ca);
            ca = new mucomChipAction(oPNAWrite[2], WritePCMData[2], null); lca.Add(ca);
            ca = new mucomChipAction(oPNAWrite[3], WritePCMData[3], null); lca.Add(ca);
            ca = new mucomChipAction(oPNAWrite[4], null, null); lca.Add(ca);

            driver.Init(
                lca
                //fileName
                //, oPNAWrite
                //, WritePCMData
                //, oPNAWaitSend
                , mubBuf
                , null
                , new object[] {
                notSoundBoard2
                , isLoadADPCM
                , loadADPCMOnly
                , fileName
            });
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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
            {
                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

                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);
                ca = new mucomChipAction(OPMWriteP, null, 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));
                }
                vw.useChipsFromMub(srcBuf);
                MmlDatum[] blary = bl.ToArray();

                MUBHeader mh = new MUBHeader(blary, myEncoding.Default);
                mh.GetTags();
                if (mh.OPMClockMode == MUBHeader.enmOPMClockMode.X68000)
                {
                    opmMasterClock = Driver.cOPMMasterClock_X68k;
                }

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

                drv.SetLoopCount(loop);

                tags = ((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));
                    }
                }

                for (int i = 0; i < 2; i++)
                {
                    byte[] pcmSrcdata = ((Driver)drv).pcm[i];
                    if (pcmSrcdata != null)
                    {
                        int pcmStartPos = ((Driver)drv).pcmStartPos[i];
                        if (pcmStartPos < pcmSrcdata.Length)
                        {
                            byte[] pcmdata = new byte[pcmSrcdata.Length - pcmStartPos];
                            Array.Copy(pcmSrcdata, pcmStartPos, pcmdata, 0, pcmdata.Length - pcmStartPos);
                            if (pcmdata != null && pcmdata.Length > 0)
                            {
                                vw.WriteAdpcm((byte)i, pcmdata);
                            }
                        }
                    }
                }

                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)
                    , new Tuple <string, int>("YM2151", (int)opmMasterClock)
                }
                                   );

                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, opnaMasterClock, opnbMasterClock, opmMasterClock);
                }
            }

            return(0);
        }
Exemplo n.º 4
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")
                    );

                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 = (uint)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 = (uint)SamplingRate,
                        Clock        = opnbMasterClock,
                        Volume       = 0,
                        Option       = new object[] { GetApplicationFolder() }
                    };
                    lstChips.Add(chip);
                }
                mds = new MDSound.MDSound((uint)SamplingRate, (uint)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)drv).Init(
                    lca
                    , bl.ToArray()
                    , null
                    , new object[] {
                    false
                    , true
                    , false
                }
                    );

                drv.SetLoopCount(loop);

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

                drv.StartRendering((int)SamplingRate, new Tuple <string, int>[] {
                    new Tuple <string, int>("YM2608", (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);
        }