示例#1
0
        public static void initial(byte[] mucompcmbin, enmFormat format)
        {
            uint samplingBuffer = 1024;

            MDSound.MDSound.Chip[] chips = new MDSound.MDSound.Chip[1];
            MDSound.MDSound.Chip   chip  = null;

            chip      = new MDSound.MDSound.Chip();
            chip.type = MDSound.MDSound.enmInstrumentType.YM2608;
            chip.ID   = 0;
            MDSound.ym2608 ym2608 = new MDSound.ym2608();
            chip.Instrument   = ym2608;
            chip.Update       = ym2608.Update;
            chip.Start        = ym2608.Start;
            chip.Stop         = ym2608.Stop;
            chip.Reset        = ym2608.Reset;
            chip.SamplingRate = format == enmFormat.VGM ? vgmSamplingRate : xgmSamplingRate;
            chip.Clock        = 7987200;
            chip.Volume       = 0;
            chip.Option       = null;
            chips[0]          = chip;

            mds = new MDSound.MDSound(format == enmFormat.VGM ? vgmSamplingRate : xgmSamplingRate, samplingBuffer, chips);

            mds.WriteYM2608(0, 0, 0x2d, 0x00);
            mds.WriteYM2608(0, 0, 0x29, 0x82);
            mds.WriteYM2608(0, 0, 0x07, 0x38);

            byte[] adpcmBuffer = mds.GetADPCMBufferYM2608(0);
            lstMucomPCMInfo = setPCMData(mucompcmbin, adpcmBuffer);
        }
示例#2
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);
        }
示例#3
0
        public void screenChangeParams()
        {
            int[] Y8950Register = Audio.GetY8950Register(chipID);
            MDChipParams.Channel nyc;
            int         slot = 0;
            ChipKeyInfo ki   = Audio.getY8950KeyInfo(chipID);

            MDSound.MDSound.Chip chipInfo = Audio.GetMDSChipInfo(MDSound.MDSound.enmInstrumentType.Y8950);
            uint masterClock = chipInfo == null ? 3579545 : chipInfo.Clock; //3579545 -> Default master clock

            //FM
            for (int c = 0; c < 9; c++)
            {
                nyc = newParam.channels[c];
                for (int i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        slot = slot1Tbl[c];
                    }
                    else
                    {
                        slot = slot2Tbl[c];
                    }
                    slot = (slot % 6) + 8 * (slot / 6);

                    //AR
                    nyc.inst[0 + i * 17] = Y8950Register[0x60 + slot] >> 4;
                    //DR
                    nyc.inst[1 + i * 17] = Y8950Register[0x60 + slot] & 0xf;
                    //SL
                    nyc.inst[2 + i * 17] = Y8950Register[0x80 + slot] >> 4;
                    //RR
                    nyc.inst[3 + i * 17] = Y8950Register[0x80 + slot] & 0xf;
                    //KL
                    nyc.inst[4 + i * 17] = Y8950Register[0x40 + slot] >> 6;
                    //TL
                    nyc.inst[5 + i * 17] = Y8950Register[0x40 + slot] & 0x3f;
                    //MT
                    nyc.inst[6 + i * 17] = Y8950Register[0x20 + slot] & 0xf;
                    //AM
                    nyc.inst[7 + i * 17] = Y8950Register[0x20 + slot] >> 7;
                    //VB
                    nyc.inst[8 + i * 17] = (Y8950Register[0x20 + slot] >> 6) & 1;
                    //EG
                    nyc.inst[9 + i * 17] = (Y8950Register[0x20 + slot] >> 5) & 1;
                    //KR
                    nyc.inst[10 + i * 17] = (Y8950Register[0x20 + slot] >> 4) & 1;
                }

                //BL
                nyc.inst[11] = (Y8950Register[0xb0 + c] >> 2) & 7;
                //FNUM
                nyc.inst[12] = Y8950Register[0xa0 + c]
                               + ((Y8950Register[0xb0 + c] & 3) << 8);

                //FB
                nyc.inst[15] = (Y8950Register[0xc0 + c] >> 1) & 7;
                //CN
                nyc.inst[14] = (Y8950Register[0xc0 + c] & 1);

                // FNUM / (2^19) * (mClock/72) * (2 ^ (block - 1))
                double fmus = (double)nyc.inst[12] / (1 << 19) * (masterClock / 72.0) * (1 << nyc.inst[11]);
                nyc.note = Common.searchSegaPCMNote(fmus / 523.3);//523.3 -> c4

                if (ki.On[c])
                {
                    int tl1 = nyc.inst[5 + 0 * 17];
                    int tl2 = nyc.inst[5 + 1 * 17];
                    int tl  = tl2;
                    if (nyc.inst[14] != 0)
                    {
                        tl = Math.Min(tl1, tl2);
                    }
                    nyc.volume = (19 * (64 - tl) / 64);
                }
                else
                {
                    if ((Y8950Register[0xb0 + c] & 0x20) == 0)
                    {
                        nyc.note = -1;
                    }
                    nyc.volume--; if (nyc.volume < 0)
                    {
                        nyc.volume = 0;
                    }
                }
            }
            newParam.channels[9].dda  = ((Y8950Register[0xbd] >> 7) & 0x01) != 0; //DA
            newParam.channels[10].dda = ((Y8950Register[0xbd] >> 6) & 0x01) != 0; //DV

            #region リズム情報の取得

            //slot14 TL 0x51 HH
            //slot15 TL 0x52 TOM
            //slot16 TL 0x53 BD
            //slot17 TL 0x54 SD
            //slot18 TL 0x55 CYM

            for (int i = 0; i < 5; i++)
            {
                if (ki.On[i + 9])
                {
                    newParam.channels[i + 9].volume = 19 - ((Y8950Register[rhythmAdr[i]] & 0x3f) >> 2);
                }
                else
                {
                    newParam.channels[i + 9].volume--;
                    if (newParam.channels[i + 9].volume < 0)
                    {
                        newParam.channels[i + 9].volume = 0;
                    }
                }
            }

            #endregion

            #region ADPCM

            //Delta
            newParam.channels[14].inst[12] = Y8950Register[0x10]
                                             + (Y8950Register[0x11] << 8);

            if (ki.On[14] || ki.Off[14])
            {
                //fSample = deltaN * 50KHz / (2^16)
                double fSample = newParam.channels[14].inst[12] * 50000.0 / (double)(1 << 16);
                int    pnt     = ki.Off[14] ? -1 : Common.searchSegaPCMNote(fSample / 8000.0);

                if (newParam.channels[14].note != pnt || ki.Off[14])
                {
                    newParam.channels[14].note = pnt;
                    int tl = Y8950Register[0x12];
                    newParam.channels[14].volume = pnt == -1 ? 0 : Common.Range(tl >> 3, 0, 19);
                }
                else
                {
                    newParam.channels[14].volume--; if (newParam.channels[14].volume < 0)
                    {
                        newParam.channels[14].volume = 0;
                    }
                }
            }
            else
            {
                newParam.channels[14].note = -1;
                newParam.channels[14].volume--; if (newParam.channels[14].volume < 0)
                {
                    newParam.channels[14].volume = 0;
                }
            }

            #endregion
        }
示例#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
        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);
        }
示例#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
        internal void AdditionalUpdate(MDSound.MDSound.Chip sender, byte ChipID, int[][] Buffer, int Length)
        {
            try
            {
                for (int i = 0; i < Length; i++)
                {
                    int m = Buffer[0][i] + Buffer[1][i];
                    if (m == last_out && vgmFrameCounter >= 0)
                    {
                        silent_length++;
                    }
                    else
                    {
                        silent_length = 0;
                    }
                    last_out = m;

                    if (nez_play != null && nez_play.heshes != null)
                    {
                        buf[0] = 0; buf[1] = 0;
                        m_hes.synth(nez_play.heshes, buf);
                        Buffer[0][i] += buf[0];
                        Buffer[1][i] += buf[1];
                    }
                }

                if (!playtime_detected && silent_length > Common.SampleRate * 3)
                {
                    playtime_detected = true;
                    LoopCounter       = 0;
                    Stopped           = true;
                }

                time_in_ms += (1000 * Length / (double)Common.SampleRate * vgmSpeed);// ((* config)["MULT_SPEED"].GetInt()) / 256);
                if (!playtime_detected && ld.IsLooped((int)time_in_ms, 30000, 5000))
                {
                    playtime_detected = true;
                    TotalCounter      = (long)ld.GetLoopEnd() * (long)Common.SampleRate / 1000L;
                    if (TotalCounter == 0)
                    {
                        TotalCounter = Counter;
                    }
                    LoopCounter = (long)(((long)ld.GetLoopEnd() - (long)ld.GetLoopStart()) * (long)Common.SampleRate / 1000L);
                }

                if (!playtime_detected)
                {
                    vgmCurLoop = 0;
                }
                else
                {
                    if (TotalCounter != 0)
                    {
                        vgmCurLoop = (uint)(Counter / TotalCounter);
                    }
                    else
                    {
                        Stopped = true;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Write(string.Format("Exception message:{0} StackTrace:{1}", ex.Message, ex.StackTrace));
            }
        }
示例#8
0
        static int Main(string[] args)
        {
            Log.writeLine = WriteLine;
#if DEBUG
            Log.level = LogLevel.TRACE;
#else
            Log.level = LogLevel.INFO;
#endif

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



            //SDLとMDSoundのセットアップ
            sdlCbHandle = GCHandle.Alloc(sdlCb);
            sdlCbPtr    = Marshal.GetFunctionPointerForDelegate(sdlCb);
            sdl         = new AudioStream((int)SamplingRate, AudioFormat.Signed16Little, SoundChannel.Stereo, (short)samplingBuffer, sdlCb, null)
            {
                Paused = true
            };
            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       = null
            };
            mds = new MDSound.MDSound(SamplingRate, samplingBuffer, new MDSound.MDSound.Chip[] { chip });



            drv = new Driver.Driver();
            drv.Init(args[0], OPNAWrite);

            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));
            }

            drv.StartRendering((int)SamplingRate, (int)opnaMasterClock);
            sdl.Paused = false;
            drv.MSTART(0);

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

            drv.MSTOP();
            sdl.Paused = true;
            drv.StopRendering();



            return(0);
        }
示例#9
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);
        }