Esempio n. 1
0
        public override void StorePcm(Dictionary <int, clsPcm> newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[v.Value.loopAdr == 0 ? 0 : 1];

            try
            {
                EncAdpcmA ea = new EncAdpcmA();
                buf = v.Value.loopAdr == 0
                    ? ea.YM_ADPCM_A_Encode(buf, is16bit)
                    : ea.YM_ADPCM_B_Encode(buf, is16bit, true);
                long   size   = buf.Length;
                byte[] newBuf = new byte[size];
                Array.Copy(buf, newBuf, size);
                buf = newBuf;
                long tSize = size;
                size = buf.Length;

                newDic.Add(
                    v.Key
                    , new clsPcm(
                        v.Value.num
                        , v.Value.seqNum, v.Value.chip
                        , v.Value.chipNumber
                        , v.Value.fileName
                        , v.Value.freq
                        , v.Value.vol
                        , pi.totalBufPtr
                        , pi.totalBufPtr + size - 1
                        , size
                        , v.Value.loopAdr == 0 ? 0 : 1
                        , is16bit
                        , samplerate)
                    );

                pi.totalBufPtr += size;
                newBuf          = new byte[pi.totalBuf.Length + buf.Length];
                Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);

                pi.totalBuf = newBuf;
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4))
                    , ChipNumber != 0
                    );
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr + 4
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + 4 + 4))
                    );
                pi.use       = true;
                pcmDataEasyA = pi.use ? pcmDataInfo[0].totalBuf : null;
                pcmDataEasyB = pi.use ? pcmDataInfo[1].totalBuf : null;
            }
            catch
            {
                pi.use = false;
            }
        }
Esempio n. 2
0
        public C140(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.C140;
            _Name      = "C140";
            _ShortName = "C140";
            _ChMax     = 24;
            _canUsePcm = true;
            _canUsePI  = true;
            ChipNumber = chipNumber;

            Frequency = 8000000;
            port      = new byte[][] { new byte[] { 0xd4 } };
            Interface = 0x0;//System2

            dataType = 0x8d;

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.PCM;
                ch.chipNumber = chipID == 1;
                ch.MaxVolume  = 255;
            }

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x8D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x8D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                };
            }
            else
            {
                pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x8D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
            };

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;

            Envelope     = new Function();
            Envelope.Max = 255;
            Envelope.Min = 0;

            makePcmTbl();
            memoryMap = new List <long>();
        }
Esempio n. 3
0
        public YM2612(ClsVgm parent, int chipID, string initialPartName, string stPath, bool isSecondary) : base(parent, chipID, initialPartName, stPath, isSecondary)
        {
            _chipType   = enmChipType.YM2612;
            _Name       = "YM2612";
            _ShortName  = "OPN2";
            _ChMax      = 10;
            _canUsePcm  = true;
            _canUsePI   = false;
            FNumTbl     = _FNumTbl;
            IsSecondary = isSecondary;

            Frequency = 7670454;

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                FNumTbl[0][FNumTbl[0].Length - 1] = FNumTbl[0][0] * 2;
            }

            Ch = new ClsChannel[ChMax];
            char[] PART_OPN2 = new char[] { 'A', 'B', 'C', 'H', 'I', 'J', 'K', 'L', 'M', 'N' };
            for (int i = 0; i < Ch.Length; i++)
            {
                if (Ch[i] == null)
                {
                    Ch[i] = new ClsChannel();
                }
                Ch[i].Name = PART_OPN2[i].ToString();
            }

            foreach (ClsChannel ch in Ch)
            {
                ch.Type        = enmChannelType.FMOPN;
                ch.isSecondary = chipID == 1;
            }

            Ch[2].Type = enmChannelType.FMOPNex;
            Ch[6].Type = enmChannelType.FMPCM;
            Ch[7].Type = enmChannelType.FMOPNex;
            Ch[8].Type = enmChannelType.FMOPNex;
            Ch[9].Type = enmChannelType.FMOPNex;

            pcmDataInfo             = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBuf = new byte[7] {
                0x67, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
        }
Esempio n. 4
0
        public override void StorePcm(Dictionary <int, Tuple <string, clsPcm> > newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                long size = buf.Length;

                for (int i = 0; i < size; i++)
                {
                    buf[i] >>= 3;//5bit化
                }

                if (newDic.ContainsKey(v.Key))
                {
                    newDic.Remove(v.Key);
                }

                newDic.Add(
                    v.Key
                    , new Tuple <string, clsPcm>("", new clsPcm(
                                                     v.Value.num
                                                     , v.Value.seqNum
                                                     , v.Value.chip
                                                     , 0
                                                     , v.Value.fileName
                                                     , v.Value.freq != -1 ? v.Value.freq : samplerate
                                                     , v.Value.vol
                                                     , pi.totalBufPtr
                                                     , pi.totalBufPtr + size - 1
                                                     , size
                                                     , -1
                                                     , is16bit
                                                     , samplerate
                                                     )
                                                 ));

                pi.totalBufPtr += size;

                byte[] newBuf = new byte[pi.totalBuf.Length + buf.Length];
                Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);

                pi.totalBuf = newBuf;

                pi.use = true;
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4))
                    , ChipNumber != 0);
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
                return;
            }
        }
Esempio n. 5
0
        public override void StorePcm(Dictionary <int, Tuple <string, clsPcm> > newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                byte[] newBuf;
                long   size = buf.Length;

                for (int i = 0; i < size; i++)
                {
                    buf[i] -= 0x80;//符号化
                }

                //Padding
                if (size % 0x100 != 0)
                {
                    newBuf = Common.PcmPadding(ref buf, ref size, 0x00, 0x100);
                    buf    = newBuf;
                }

                if (newDic.ContainsKey(v.Key))
                {
                    newDic.Remove(v.Key);
                }
                newDic.Add(v.Key, new Tuple <string, clsPcm>("", new clsPcm(
                                                                 v.Value.num
                                                                 , v.Value.seqNum
                                                                 , v.Value.chip
                                                                 , 0
                                                                 , v.Value.fileName
                                                                 , v.Value.freq != -1 ? v.Value.freq : samplerate
                                                                 , v.Value.vol
                                                                 , pi.totalBufPtr
                                                                 , pi.totalBufPtr + size - 1
                                                                 , size
                                                                 , -1
                                                                 , is16bit
                                                                 , samplerate)
                                                             ));
                pi.totalBufPtr += size;

                newBuf = new byte[pi.totalBuf.Length + buf.Length];
                Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);

                pi.totalBuf = newBuf;
                pi.use      = true;
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
            }
        }
Esempio n. 6
0
        private byte[] Encode(byte[] buf, bool is16bit)
        {
            long size  = buf.Length;
            long tSize = buf.Length;

            byte[]         newBuf;
            clsPcmDataInfo pi = pcmDataInfo[0];

            //Padding
            if (size % 0x100 != 0)
            {
                size++;
                tSize  = size;
                newBuf = new byte[size];
                Array.Copy(buf, newBuf, size - 1);
                buf    = newBuf;
                newBuf = Common.PcmPadding(ref buf, ref size, 0x80, 0x100);
            }
            else
            {
                newBuf = new byte[size];
                Array.Copy(buf, newBuf, size);
            }

            //65536 バイトを超える場合はそれ以降をカット
            if (size > 0x10000)
            {
                List <byte> n = newBuf.ToList();
                n.RemoveRange(0x10000, (int)(size - 0x10000));
                newBuf = n.ToArray();
                size   = 0x10000;
            }

            //パディング(空きが足りない場合はバンクをひとつ進める(0x10000)為、空きを全て埋める)
            int fs = (pi.totalBuf.Length - 15) % 0x10000;

            if (size > 0x10000 - fs)
            {
                List <byte> n = pi.totalBuf.ToList();
                for (int i = 0; i < 0x10000 - fs; i++)
                {
                    n.Add(0x80);
                }
                pi.totalBuf     = n.ToArray();
                pi.totalBufPtr += 0x10000 - fs;
            }

            buf = newBuf;

            return(buf);
        }
Esempio n. 7
0
        public override void StorePcm(Dictionary <int, clsPcm> newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                long size = buf.Length;
                if (newDic.ContainsKey(v.Key))
                {
                    newDic.Remove(v.Key);
                }
                newDic.Add(
                    v.Key
                    , new clsPcm(
                        v.Value.num
                        , v.Value.seqNum
                        , v.Value.chip
                        , false
                        , v.Value.fileName
                        , v.Value.freq != -1 ? v.Value.freq : samplerate
                        , v.Value.vol
                        , pi.totalBufPtr
                        , pi.totalBufPtr + size - 1
                        , size
                        , -1
                        , is16bit
                        , samplerate));
                pi.totalBufPtr += size;

                byte[] newBuf = new byte[pi.totalBuf.Length + buf.Length];
                Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);

                pi.totalBuf = newBuf;
                Common.SetUInt32bit31(pi.totalBuf, 3, (UInt32)(pi.totalBuf.Length - 7), IsSecondary);
                pi.use      = true;
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
            }
        }
Esempio n. 8
0
        public override void StorePcm(Dictionary <int, clsPcm> newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                long   size   = buf.Length;
                byte[] newBuf = new byte[size + 1];
                //Array.Copy(buf, newBuf, size);
                //newBuf[size] = 0xff;
                //buf = newBuf;
                long tSize = size;
                //size = buf.Length;

                buf  = Encode(buf, false);
                size = buf.Length;
                //long tSize = size - 1;

                newDic.Add(
                    v.Key
                    , new clsPcm(
                        v.Value.num, v.Value.seqNum, v.Value.chip
                        , v.Value.chipNumber
                        , v.Value.fileName
                        , v.Value.freq
                        , v.Value.vol
                        , pi.totalBufPtr
                        , pi.totalBufPtr + size - 1
                        , size
                        , pi.totalBufPtr + (v.Value.loopAdr == -1 ? tSize : v.Value.loopAdr)
                        , is16bit
                        , samplerate
                        )
                    );

                pi.totalBufPtr += size;

                newBuf = new byte[pi.totalBuf.Length + buf.Length];
                Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);

                pi.totalBuf = newBuf;
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr + (parent.ChipCommandSize == 2 ? 4 : 3)                                      //通常コマンド分を他のチップと比べて余計に加算する
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + (parent.ChipCommandSize == 2 ? 4 : 3))) //通常コマンド分を他のチップと比べて余計に加算する
                    , ChipNumber != 0
                    );

                //RF5C164のPCMブロックの前に通常コマンドが存在するため書き換える
                if (parent.info.format == enmFormat.ZGM)
                {
                    pi.totalBuf[0] = port[0][0];
                    if (parent.ChipCommandSize == 2)
                    {
                        pi.totalBuf[1] = port[0][1];
                    }
                }

                pi.use      = true;
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
            }
        }
Esempio n. 9
0
        public SN76489(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _Name      = "SN76489";
            _ShortName = "DCSG";
            _ChMax     = 4;
            _canUsePcm = true;
            _canUsePI  = false;
            FNumTbl    = _FNumTbl;
            port       = new byte[][] {
                new byte[] { (byte)(chipNumber != 0 ? 0x30 : 0x50) }
                , new byte[] { (byte)(chipNumber != 0 ? 0x3f : 0x4f) }
            };

            Frequency       = 3579545;
            this.ChipNumber = chipNumber;

            Envelope     = new Function();
            Envelope.Max = 15;
            Envelope.Min = 0;

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.DCSG;
                ch.chipNumber = chipID == 1;
                ch.MaxVolume  = 15;
            }
            Ch[3].Type = enmChannelType.DCSGNOISE;

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;

            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x08, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x08, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x08, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x08, 0x00, 0x00, 0x00, 0x00 }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x08, 0x00, 0x00, 0x00, 0x00 }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;
        }
Esempio n. 10
0
        public HuC6280(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.HuC6280;
            _Name      = "HuC6280";
            _ShortName = "HuC8";
            _ChMax     = 6;
            _canUsePcm = true;
            _canUsePI  = false;
            ChipNumber = chipNumber;

            Frequency = 3579545;
            port      = new byte[][] { new byte[] { 0xb9 } };

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.WaveForm;
                ch.chipNumber = chipID == 1;
                ch.MaxVolume  = 15;
            }

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;

            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;


            Envelope     = new Function();
            Envelope.Max = 31;
            Envelope.Min = 0;
        }
Esempio n. 11
0
        public HuC6280(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.HuC6280;
            _Name      = "HuC6280";
            _ShortName = "HuC8";
            _ChMax     = 6;
            _canUsePcm = true;
            _canUsePI  = false;
            ChipNumber = chipNumber;

            Frequency = 3579545;
            port      = new byte[][] { new byte[] { 0xb9 } };

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                FNumTbl = new int[1][] { new int[96] };
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                if (dic.ContainsKey("MASTERCLOCK"))
                {
                    Frequency = (int)dic["MASTERCLOCK"][0];
                }
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.WaveForm;
                ch.chipNumber = chipID == 1;
                ch.MaxVolume  = 15;
            }

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;

            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x05, 0x00, 0x00, 0x00, 0x00 }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;


            Envelope     = new Function();
            Envelope.Max = 31;
            Envelope.Min = 0;
        }
Esempio n. 12
0
        public AY8910(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.AY8910;
            _Name      = "AY8910";
            _ShortName = "AY10";
            _ChMax     = 3;
            _canUsePcm = true;
            _canUsePI  = false;
            ChipNumber = chipNumber;

            Frequency  = 1789750;
            port       = new byte[][] { new byte[] { 0xa0 } };
            DataBankID = 0x09;//TBD(固定値ではなく、恐らくデータごとに連番を振るのが良いと思われる。)

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                FNumTbl = new int[1][] { new int[96] };
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                if (dic.ContainsKey("MASTERCLOCK"))
                {
                    Frequency = (int)dic["MASTERCLOCK"][0];
                }
                if (dic.ContainsKey("CHIPTYPE"))
                {
                    ChipType = (byte)(int)dic["CHIPTYPE"][0];
                }
                if (dic.ContainsKey("FLAGS"))
                {
                    Flags = (byte)(int)dic["FLAGS"][0];
                }
                c         = 0;
                hsFnumTbl = new int[72];
                foreach (double v in dic["HSFNUM_00"])
                {
                    hsFnumTbl[c++] = (int)v;
                    if (c == hsFnumTbl.Length)
                    {
                        break;
                    }
                }
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.SSG;
                ch.chipNumber = chipID == 1;
                ch.MaxVolume  = 15;
            }

            Envelope     = new Function();
            Envelope.Max = 15;
            Envelope.Min = 0;

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;

            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;


            //from fmgen code
            EmitTable = new int[16];
            double Base = 0x4000 / 3.0 * Math.Pow(10.0, 0.0 / 40.0);

            for (int i = 15; i >= 1; i--)
            {
                EmitTable[i] = (int)(Base);
                Base        /= 1.189207115;
                Base        /= 1.189207115;
            }
            EmitTable[0] = 0;

            for (int i = 0; i < 16; i++)
            {
                EmitTable[i] = (int)(EmitTable[i] / (EmitTable[15] / 255.0));
            }
        }
Esempio n. 13
0
        public override void StorePcm(Dictionary <int, Tuple <string, clsPcm> > newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                EncAdpcmA ea = new EncAdpcmA();
                buf = ea.YM_ADPCM_B_Encode(buf, is16bit, false, true);
                long size = buf.Length;

                byte[] newBuf;
                newBuf = new byte[size];
                Array.Copy(buf, newBuf, size);
                buf = newBuf;
                int m256kbyte = 0b100_0000_0000_0000_0000;//CASAdr 9bit  RASAdr 9bit = 18bit(2+4+4+4+4)

                //262,144 バイトを超える場合はそれ以降をカット
                if (size > m256kbyte)
                {
                    List <byte> n = newBuf.ToList();
                    n.RemoveRange(m256kbyte, (int)(size - m256kbyte));
                    newBuf = n.ToArray();
                    size   = m256kbyte;
                }

                //空いているBankを探す
                int freeBank = 0;
                int freeAdr  = 0;
                do
                {
                    if (memoryMap.Count < freeBank + 1)
                    {
                        memoryMap.Add(0);
                        freeAdr              = 0 + freeBank * m256kbyte;
                        memoryMap[freeBank] += size;
                        break;
                    }

                    if (size < m256kbyte - memoryMap[freeBank])
                    {
                        freeAdr              = (int)(memoryMap[freeBank] + freeBank * m256kbyte);
                        memoryMap[freeBank] += size;
                        break;
                    }

                    freeBank++;
                } while (true);

                //パディング(空きが足りない場合はバンクをひとつ進める(0b100_0000_0000_0000_0000)為、空きを全て埋める)
                while (freeAdr > pi.totalBuf.Length - pi.totalHeaderLength)
                {
                    int fs = (pi.totalBuf.Length - pi.totalHeaderLength) % m256kbyte;

                    List <byte> n = pi.totalBuf.ToList();
                    for (int i = 0; i < m256kbyte - fs; i++)
                    {
                        n.Add(0x00);
                    }
                    pi.totalBuf     = n.ToArray();
                    pi.totalBufPtr += m256kbyte - fs;
                }

                //long tSize = size;
                //size = buf.Length;

                newDic.Add(
                    v.Key
                    , new Tuple <string, clsPcm>("", new clsPcm(
                                                     v.Value.num
                                                     , v.Value.seqNum, v.Value.chip
                                                     , v.Value.chipNumber
                                                     , v.Value.fileName
                                                     , v.Value.freq
                                                     , v.Value.vol
                                                     , freeAdr
                                                     , freeAdr + size - 1
                                                     , size
                                                     , -1
                                                     , is16bit
                                                     , samplerate
                                                     , (v.Value.loopAdr & 3)
                                                     )
                                                 ));

                if (freeAdr == pi.totalBufPtr)
                {
                    pi.totalBufPtr += size;

                    newBuf = new byte[pi.totalBuf.Length + buf.Length];
                    Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                    Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);
                    pi.totalBuf = newBuf;
                }
                else
                {
                    Array.Copy(buf, 0, pi.totalBuf, freeAdr + pi.totalHeaderLength, buf.Length);
                }

                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4))
                    , ChipNumber != 0
                    );
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr + 4
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + 4 + 4))
                    );
                pi.use      = true;
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
                newDic[v.Key].Item2.status = enmPCMSTATUS.ERROR;
            }
        }
Esempio n. 14
0
        public QSound(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.QSound;
            _Name      = "QSound";
            _ShortName = "QSnd";
            _ChMax     = 16;
            _canUsePcm = true;
            _canUsePI  = false;
            ChipNumber = chipNumber; //QSound はDualChip非対応

            Frequency = 4_000_000;   //4MHz
            port      = new byte[][] { new byte[] { 0xc4 } };

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.PCM;
                ch.chipNumber = chipID == 1;
                ch.MaxVolume  = 65535;
            }

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0x07, 0x00, 0x66, 0x8f
                        , 0x00, 0x00, 0x00, 0x00 //size of data
                        , 0x00, 0x00, 0x00, 0x00 //size of the entire ROM
                        , 0x00, 0x00, 0x00, 0x00 //start address of data
                    };
                }
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0x07, 0x66, 0x8f
                        , 0x00, 0x00, 0x00, 0x00 //size of data
                        , 0x00, 0x00, 0x00, 0x00 //size of the entire ROM
                        , 0x00, 0x00, 0x00, 0x00 //start address of data
                    };
                }
            }
            else
            {
                pcmDataInfo[0].totalBuf = new byte[] {
                    0x67, 0x66, 0x8f
                    , 0x00, 0x00, 0x00, 0x00 //size of data
                    , 0x00, 0x00, 0x00, 0x00 //size of the entire ROM
                    , 0x00, 0x00, 0x00, 0x00 //start address of data
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;

            memoryMap = new List <long>();
        }
Esempio n. 15
0
        public Y8950(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.Y8950;
            _Name      = "Y8950";
            _ShortName = "Y89";
            _ChMax     = 9 + 5 + 1;//FM 9ch Rhythm 5ch ADPCM 1ch
            _canUsePcm = true;

            Frequency = 3579545;
            port      = new byte[][] {
                new byte[] { (byte)(chipNumber != 0 ? 0xac : 0x5c) }
            };

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                FNumTbl    = new int[1][];
                FNumTbl[0] = new int[13];
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                FNumTbl[0][FNumTbl[0].Length - 1] = FNumTbl[0][0] * 2;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;

            memoryMap = new List <long>();
        }
Esempio n. 16
0
        public YM2612X(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.YM2612X;
            _Name      = "YM2612X";
            _ShortName = "OPN2X";
            _ChMax     = 6 + 3 + 3 + 4 + 4 + 4;//fm:6ch + fmex:3ch + fmpcm:3ch + fmpcm(overlay):12ch = total:24ch
            _canUsePcm = true;
            _canUsePI  = false;
            FNumTbl    = _FNumTbl;
            ChipNumber = chipNumber;

            Frequency = 7670454;
            port      = new byte[][] {
                new byte[] { (byte)(chipNumber != 0 ? 0xa2 : 0x52) }
                , new byte[] { (byte)(chipNumber != 0 ? 0xa3 : 0x53) }
            };

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                FNumTbl[0][FNumTbl[0].Length - 1] = FNumTbl[0][0] * 2;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.FMOPN;
                ch.chipNumber = chipID == 1;
            }

            Ch[2].Type = enmChannelType.FMOPNex;
            Ch[5].Type = enmChannelType.FMPCMex;
            Ch[6].Type = enmChannelType.FMOPNex;
            Ch[7].Type = enmChannelType.FMOPNex;
            Ch[8].Type = enmChannelType.FMOPNex;
            for (int i = 9; i < ChMax; i++)
            {
                Ch[i].Type = enmChannelType.FMPCMex;
            }

            pcmDataInfo                = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBuf    = new byte[0];
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;

            for (int i = 0; i < 4; i++)
            {
                pcmKeyOnCh[i]      = 0;
                pcmKeyOnInstNum[i] = -1;
            }
        }
Esempio n. 17
0
        public override void StorePcm(Dictionary <int, clsPcm> newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                long   size   = buf.Length;
                byte[] newBuf = new byte[size];
                Array.Copy(buf, newBuf, size);
                buf = newBuf;

                //Padding
                if (size % 0x100 != 0)
                {
                    newBuf = Common.PcmPadding(ref buf, ref size, 0x80, 0x100);
                }

                //65536 バイトを超える場合はそれ以降をカット
                if (size > 0x10000)
                {
                    List <byte> n = newBuf.ToList();
                    n.RemoveRange(0x10000, (int)(size - 0x10000));
                    newBuf = n.ToArray();
                    size   = 0x10000;
                }

                //パディング(空きが足りない場合はバンクをひとつ進める(0x10000)為、空きを全て埋める)
                int fs = (pi.totalBuf.Length - pi.totalHeaderLength) % 0x10000;
                if (size > 0x10000 - fs)
                {
                    List <byte> n = pi.totalBuf.ToList();
                    for (int i = 0; i < 0x10000 - fs; i++)
                    {
                        n.Add(0x80);
                    }
                    pi.totalBuf     = n.ToArray();
                    pi.totalBufPtr += 0x10000 - fs;
                }

                newDic.Add(
                    v.Key
                    , new clsPcm(
                        v.Value.num
                        , v.Value.seqNum, v.Value.chip
                        , v.Value.chipNumber
                        , v.Value.fileName
                        , v.Value.freq
                        , v.Value.vol
                        , pi.totalBufPtr
                        , pi.totalBufPtr + size
                        , size
                        , v.Value.loopAdr == -1 ? -1 : (pi.totalBufPtr + v.Value.loopAdr)
                        , is16bit
                        , samplerate)
                    );

                pi.totalBufPtr += size;
                newBuf          = new byte[pi.totalBuf.Length + buf.Length];
                Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);

                pi.totalBuf = newBuf;
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4))
                    , ChipNumber != 0
                    );
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr + 4
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + 4 + 4))
                    );
                pi.use      = true;
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
                newDic[v.Key].status = enmPCMSTATUS.ERROR;
            }
        }
Esempio n. 18
0
        public segaPcm(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.SEGAPCM;
            _Name      = "SEGAPCM";
            _ShortName = "SPCM";
            _ChMax     = 16;
            _canUsePcm = true;
            _canUsePI  = true;
            ChipNumber = chipNumber;
            dataType   = 0x80;
            Frequency  = 4026987;
            port       = new byte[][] { new byte[] { 0xc0 } };
            Interface  = 0x00f8000d;

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.PCM;
                ch.chipNumber = chipID == 1;
                ch.MaxVolume  = 127;
            }

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;


            Envelope     = new Function();
            Envelope.Max = 127;
            Envelope.Min = 0;
        }
Esempio n. 19
0
        public override void StorePcm(Dictionary <int, Tuple <string, clsPcm> > newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                List <byte> nbuf  = new List <byte>();
                int         now   = 0;
                int         depth = 0;
                int         ndt   = 0;
                if (!is16bit)
                {
                    for (int i = 0; i < ((buf.Length + 7) / 8) * 8; i++)
                    {
                        sbyte dt = (sbyte)(i < buf.Length ? (buf[i] - 0x80) : 0);
                        if (now <= dt)
                        {
                            ndt |= (1 << depth);
                            now += 8;
                        }
                        else
                        {
                            now -= 8;
                        }

                        depth++;
                        if (depth == 8)
                        {
                            depth = 0;
                            nbuf.Add((byte)ndt);
                            ndt = 0;
                        }
                    }
                    if (nbuf.Count % 16 != 0)
                    {
                        int n = (16 - (nbuf.Count % 16)) * 8;
                        for (int i = 0; i < n; i++)
                        {
                            //if (now <= 0)
                            //{
                            //    ndt |= (1 << depth);
                            //    now += 8;
                            //}
                            //else
                            now -= 8;

                            depth++;
                            if (depth == 8)
                            {
                                depth = 0;
                                nbuf.Add((byte)ndt);
                                ndt = 0;
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < (((buf.Length / 2) + 7) / 8) * 8; i++)
                    {
                        short dt = (short)(i * 2 + 1 < buf.Length ? (buf[i * 2] + buf[i * 2 + 1] * 0x100) : 0);
                        if (now <= dt)
                        {
                            ndt |= (1 << depth);
                            now += 16;
                        }
                        else
                        {
                            now -= 16;
                        }

                        depth++;
                        if (depth == 8)
                        {
                            depth = 0;
                            nbuf.Add((byte)ndt);
                            ndt = 0;
                        }
                    }
                }

                buf = nbuf.ToArray();
                long size = buf.Length;

                if (newDic.ContainsKey(v.Key))
                {
                    newDic.Remove(v.Key);
                }

                newDic.Add(
                    v.Key
                    , new Tuple <string, clsPcm>("", new clsPcm(
                                                     v.Value.num
                                                     , v.Value.seqNum
                                                     , v.Value.chip
                                                     , 0
                                                     , v.Value.fileName
                                                     , v.Value.freq != -1 ? v.Value.freq : samplerate
                                                     , v.Value.vol
                                                     , pi.totalBufPtr
                                                     , pi.totalBufPtr + size - 1
                                                     , size
                                                     , -1
                                                     , is16bit
                                                     , samplerate
                                                     )
                                                 ));

                pi.totalBufPtr += size;

                byte[] newBuf = new byte[pi.totalBuf.Length + buf.Length];
                Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);

                pi.totalBuf = newBuf;

                pi.use = true;
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4))
                    , ChipNumber != 0);
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
                return;
            }
        }
Esempio n. 20
0
        public NES(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.NES;
            _Name      = "NES";
            _ShortName = "NES";
            _ChMax     = 5 + 1;
            _canUsePcm = true;
            _canUsePI  = false;
            ChipNumber = chipNumber;

            Frequency    = 1789772;//NTSC (PAL=1662607)
            port         = new byte[][] { new byte[] { 0xb4 } };
            vgmHeaderPos = 0x84;
            DataBankID   = 0xa;
            int c = 0;

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                c       = 0;
                FNumTbl = new int[1][] { new int[96] };
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                if (dic.ContainsKey("MASTERCLOCK"))
                {
                    Frequency = (int)dic["MASTERCLOCK"][0];
                }
                c           = 0;
                FDS_FNumTbl = new int[1][] { new int[96] };
                foreach (double v in dic["FDS_FNUM_00"])
                {
                    FDS_FNumTbl[0][c++] = (int)v;
                    if (c == FDS_FNumTbl[0].Length)
                    {
                        break;
                    }
                }
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            c = 0;
            foreach (ClsChannel ch in Ch)
            {
                ch.Type = c < 2
                    ? enmChannelType.Pulse
                    : (c == 2
                        ? enmChannelType.Triangle
                        : (c == 3
                            ? enmChannelType.Noise
                           : (c == 4
                                ? enmChannelType.DPCM
                                : enmChannelType.WaveForm
                              )
                           )
                       );
                ch.chipNumber = chipID == 1;
                if (c != 5)
                {
                    ch.MaxVolume = 15;
                }
                else
                {
                    ch.MaxVolume = 63;
                }

                c++;
            }

            Envelope     = new Function();
            Envelope.Max = 15;
            Envelope.Min = 0;

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0x07, 0x00, 0x66, 0xc2
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0x07, 0x00, 0x66, 0xc2
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0x07, 0x66, 0xc2
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0x07, 0x66, 0xc2
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0x67, 0x66, 0xc2
                        , 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                    }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0x67, 0x66, 0xc2
                        , 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                    }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;
        }
Esempio n. 21
0
        public YM2612(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.YM2612;
            _Name      = "YM2612";
            _ShortName = "OPN2";
            _ChMax     = 9;
            _canUsePcm = true;
            _canUsePI  = false;
            FNumTbl    = _FNumTbl;
            ChipNumber = chipNumber;

            Frequency = 7670454;
            port      = new byte[][] {
                new byte[] { (byte)(0x2 | (chipNumber != 0 ? 0xa0 : 0x50)) }
                , new byte[] { (byte)(0x3 | (chipNumber != 0 ? 0xa0 : 0x50)) }
            };

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                FNumTbl[0][FNumTbl[0].Length - 1] = FNumTbl[0][0] * 2;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.FMOPN;
                ch.chipNumber = chipID == 1;
            }

            Ch[2].Type = enmChannelType.FMOPNex;
            Ch[5].Type = enmChannelType.FMPCM;
            Ch[6].Type = enmChannelType.FMOPNex;
            Ch[7].Type = enmChannelType.FMOPNex;
            Ch[8].Type = enmChannelType.FMOPNex;

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0x07, 0x00,            // data block
                        0x00, 0x00,            // Chip Command Number
                        0x00,                  // data type
                        0x00, 0x00, 0x00, 0x00 // size of data
                    };
                }
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0x07,                  // data block
                        0x00,                  // Chip Command Number
                        0x00,                  // data type
                        0x00, 0x00, 0x00, 0x00 // size of data
                    };
                }
            }
            else
            {
                pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00 };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 5 : 3;
        }
Esempio n. 22
0
        public RF5C164(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.RF5C164;
            _Name      = "RF5C164";
            _ShortName = "RF5C";
            _ChMax     = 8;
            _canUsePcm = true;
            _canUsePI  = true;
            ChipNumber = chipNumber;
            dataType   = 0xc1;

            Frequency = 12500000;
            port      = new byte[][] { new byte[] { 0xb1 } };

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.PCM;
                ch.chipNumber = chipID == 1;
            }

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0xb1, 0x00, 0x07, 0x00,//通常コマンド
                            0x07, 0x00, 0x66, 0xc1
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0xb1, 0x00, 0x87, 0x00,//通常コマンド
                            0x07, 0x00, 0x66, 0xc1
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    };
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0xb1, 0x07, 0x00//通常コマンド
                            , 0x07, 0x66, 0xc1
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    }
                    ;
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] {
                            0xb1, 0x87, 0x00//通常コマンド
                            , 0x07, 0x66, 0xc1
                            , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    };
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0xb1, 0x07, 0x00//通常コマンド
                        , 0x67, 0x66, 0xc1
                        , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                    }
                }
                ;
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] {
                        0xb1, 0x87, 0x00//通常コマンド
                        , 0x67, 0x66, 0xc1
                        , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                    }
                };
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;

            Envelope     = new Function();
            Envelope.Max = 255;
            Envelope.Min = 0;
        }
Esempio n. 23
0
        public override void StorePcm(Dictionary <int, Tuple <string, clsPcm> > newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                List <byte> dBuf = new List <byte>();
                if (is16bit)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    //8bit unsigned -> 8bit signed
                    for (int i = 0; i < buf.Length; i++)
                    {
                        dBuf.Add((byte)(buf[i] - 0x80));//符号化
                    }
                }
                buf = dBuf.ToArray();

                long   size   = buf.Length;
                byte[] newBuf = new byte[size];
                Array.Copy(buf, newBuf, size);
                buf = newBuf;

                //65536/2 バイトを超える場合はそれ以降をカット
                int bankSize = 0x10000 / 2;

                if (size > bankSize)
                {
                    List <byte> n = newBuf.ToList();
                    n.RemoveRange(bankSize, (int)(size - bankSize));
                    newBuf = n.ToArray();
                    size   = bankSize;
                }

                //空いているBankを探す
                int freeBank = 0;
                int freeAdr  = 0;
                do
                {
                    if (memoryMap.Count < freeBank + 1)
                    {
                        memoryMap.Add(0);
                        freeAdr              = 0 + freeBank * bankSize;
                        memoryMap[freeBank] += size;
                        break;
                    }

                    if (size < bankSize - memoryMap[freeBank])
                    {
                        freeAdr              = (int)(memoryMap[freeBank] + freeBank * bankSize);
                        memoryMap[freeBank] += size;
                        break;
                    }

                    freeBank++;
                } while (true);

                //パディング(空きが足りない場合はバンクをひとつ進める(0x10000)為、空きを全て埋める)
                while (freeAdr > pi.totalBuf.Length - pi.totalHeaderLength)
                {
                    int         fs = (pi.totalBuf.Length - pi.totalHeaderLength) % bankSize;
                    List <byte> n  = pi.totalBuf.ToList();
                    for (int i = 0; i < bankSize - fs; i++)
                    {
                        n.Add(0x00);
                    }
                    pi.totalBuf     = n.ToArray();
                    pi.totalBufPtr += bankSize - fs;
                }

                newDic.Add(
                    v.Key
                    , new Tuple <string, clsPcm>("", new clsPcm(
                                                     v.Value.num
                                                     , v.Value.seqNum, v.Value.chip
                                                     , v.Value.chipNumber
                                                     , v.Value.fileName
                                                     , v.Value.freq
                                                     , v.Value.vol
                                                     , freeAdr
                                                     , freeAdr + size - 1
                                                     , size
                                                     , (v.Value.loopAdr == -1 ? freeAdr : (v.Value.loopAdr + freeAdr))
                                                     , is16bit
                                                     , samplerate)
                                                 ));

                if (newDic[v.Key].Item2.loopAdr != -1 &&
                    (newDic[v.Key].Item2.loopAdr < freeAdr || v.Value.loopAdr >= size))
                {
                    msgBox.setErrMsg(string.Format(msg.get("E22000")
                                                   , newDic[v.Key].Item2.loopAdr
                                                   , size - 1), new LinePos(null, "-"));
                    newDic[v.Key].Item2.loopAdr = -1;
                    newDic[v.Key].Item2.status  = enmPCMSTATUS.ERROR;
                }

                if (freeAdr == pi.totalBufPtr)
                {
                    pi.totalBufPtr += size;

                    newBuf = new byte[pi.totalBuf.Length + buf.Length];
                    Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                    Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);
                    pi.totalBuf = newBuf;
                }
                else
                {
                    Array.Copy(buf, 0, pi.totalBuf, freeAdr + pi.totalHeaderLength, buf.Length);
                }

                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4))
                    , false
                    );
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr + 4
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + 4 + 4))
                    );
                pi.use      = true;
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
                newDic[v.Key].Item2.status = enmPCMSTATUS.ERROR;
            }
        }
Esempio n. 24
0
        public YM2612X(ClsVgm parent, int chipID, string initialPartName, string stPath, bool isSecondary) : base(parent, chipID, initialPartName, stPath, isSecondary)
        {
            _chipType   = enmChipType.YM2612X;
            _Name       = "YM2612X";
            _ShortName  = "OPN2X";
            _ChMax      = 13;
            _canUsePcm  = true;
            _canUsePI   = false;
            FNumTbl     = _FNumTbl;
            IsSecondary = isSecondary;

            Frequency = 7670454;

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null && dic.Count > 0)
            {
                int c = 0;
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                FNumTbl[0][FNumTbl[0].Length - 1] = FNumTbl[0][0] * 2;
            }

            Ch = new ClsChannel[ChMax];
            char[] PART_OPN2 = new char[] {
                'A', 'B', 'C', //FM1-3ch
                'H', 'I', 'J', //FM4-6ch
                'K',           //FM6chPCMEx1ch
                'L', 'M', 'N', //FM3chEx
                'O', 'P', 'Q'  //FM6chPCMEx2-4ch
            };
            for (int i = 0; i < Ch.Length; i++)
            {
                if (Ch[i] == null)
                {
                    Ch[i] = new ClsChannel();
                }
                Ch[i].Name = PART_OPN2[i].ToString();
            }

            foreach (ClsChannel ch in Ch)
            {
                ch.Type        = enmChannelType.FMOPN;
                ch.isSecondary = chipID == 1;
            }

            Ch[2].Type  = enmChannelType.FMOPNex;
            Ch[6].Type  = enmChannelType.FMPCMex;
            Ch[7].Type  = enmChannelType.FMOPNex;
            Ch[8].Type  = enmChannelType.FMOPNex;
            Ch[9].Type  = enmChannelType.FMOPNex;
            Ch[10].Type = enmChannelType.FMPCMex;
            Ch[11].Type = enmChannelType.FMPCMex;
            Ch[12].Type = enmChannelType.FMPCMex;

            pcmDataInfo                = new clsPcmDataInfo[] { new clsPcmDataInfo() };
            pcmDataInfo[0].totalBuf    = new byte[0];
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
        }
Esempio n. 25
0
        public YM2608(ClsVgm parent, int chipID, string initialPartName, string stPath, int chipNumber) : base(parent, chipID, initialPartName, stPath, chipNumber)
        {
            _chipType  = enmChipType.YM2608;
            _Name      = "YM2608";
            _ShortName = "OPNA";
            _ChMax     = 19;
            _canUsePcm = true;
            _canUsePI  = true;
            FNumTbl    = _FNumTbl;
            ChipNumber = chipNumber;
            dataType   = 0x81;
            Frequency  = 7987200;
            port       = new byte[][] {
                new byte[] { (byte)(chipNumber != 0 ? 0xa6 : 0x56) }
                , new byte[] { (byte)(chipNumber != 0 ? 0xa7 : 0x57) }
            };
            DataBankID = 0x0d;//TBD(固定値ではなく、恐らくデータごとに連番を振るのが良いと思われる。)

            if (string.IsNullOrEmpty(initialPartName))
            {
                return;
            }

            Dictionary <string, List <double> > dic = MakeFNumTbl();

            if (dic != null)
            {
                int c = 0;
                foreach (double v in dic["FNUM_00"])
                {
                    FNumTbl[0][c++] = (int)v;
                    if (c == FNumTbl[0].Length)
                    {
                        break;
                    }
                }
                FNumTbl[0][FNumTbl[0].Length - 1] = FNumTbl[0][0] * 2;

                c = 0;
                foreach (double v in dic["FNUM_01"])
                {
                    FNumTbl[1][c++] = (int)v;
                    if (c == FNumTbl[1].Length)
                    {
                        break;
                    }
                }

                c         = 0;
                hsFnumTbl = new int[72];
                foreach (double v in dic["HSFNUM_00"])
                {
                    hsFnumTbl[c++] = (int)v;
                    if (c == hsFnumTbl.Length)
                    {
                        break;
                    }
                }
            }

            Ch = new ClsChannel[ChMax];
            SetPartToCh(Ch, initialPartName);
            foreach (ClsChannel ch in Ch)
            {
                ch.Type       = enmChannelType.FMOPN;
                ch.chipNumber = chipID == 1;
            }

            Ch[2].Type = enmChannelType.FMOPNex;
            Ch[6].Type = enmChannelType.FMOPNex;
            Ch[7].Type = enmChannelType.FMOPNex;
            Ch[8].Type = enmChannelType.FMOPNex;

            Ch[9].Type  = enmChannelType.SSG;
            Ch[10].Type = enmChannelType.SSG;
            Ch[11].Type = enmChannelType.SSG;

            Ch[12].Type = enmChannelType.RHYTHM;
            Ch[13].Type = enmChannelType.RHYTHM;
            Ch[14].Type = enmChannelType.RHYTHM;
            Ch[15].Type = enmChannelType.RHYTHM;
            Ch[16].Type = enmChannelType.RHYTHM;
            Ch[17].Type = enmChannelType.RHYTHM;

            Ch[18].Type = enmChannelType.ADPCM;

            pcmDataInfo = new clsPcmDataInfo[] { new clsPcmDataInfo(), new clsPcmDataInfo() };
            pcmDataInfo[0].totalBufPtr = 0L;
            pcmDataInfo[0].use         = false;
            pcmDataInfo[1].totalBufPtr = 0L;
            pcmDataInfo[1].use         = false;
            if (parent.info.format == enmFormat.ZGM)
            {
                if (parent.ChipCommandSize == 2)
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                        pcmDataInfo[1].totalBuf = new byte[] { 0x07, 0x00, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 };
                    }
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x00, 0x66, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                        pcmDataInfo[1].totalBuf = new byte[] { 0x07, 0x00, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 };
                    }
                }
                else
                {
                    if (chipNumber == 0)
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                        pcmDataInfo[1].totalBuf = new byte[] { 0x07, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 };
                    }
                    else
                    {
                        pcmDataInfo[0].totalBuf = new byte[] { 0x07, 0x66, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                        pcmDataInfo[1].totalBuf = new byte[] { 0x07, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 };
                    }
                }
            }
            else
            {
                if (chipNumber == 0)
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    pcmDataInfo[1].totalBuf = new byte[] { 0x67, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 };
                }
                else
                {
                    pcmDataInfo[0].totalBuf = new byte[] { 0x67, 0x66, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    pcmDataInfo[1].totalBuf = new byte[] { 0x67, 0x66, DataBankID, 0x00, 0x00, 0x00, 0x00 };
                }
            }

            pcmDataInfo[0].totalHeaderLength       = pcmDataInfo[0].totalBuf.Length;
            pcmDataInfo[0].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;
            pcmDataInfo[1].totalHeaderLength       = pcmDataInfo[1].totalBuf.Length;
            pcmDataInfo[1].totalHeadrSizeOfDataPtr = (parent.ChipCommandSize == 2) ? 4 : 3;

            Envelope     = new Function();
            Envelope.Max = 255;
            Envelope.Min = 0;
        }
Esempio n. 26
0
        /// <summary>
        ///  8bit unsigned Wave ->  8bit signed LinnerPCM
        /// 16bit signed   Wave -> 13bit signed CompPCM
        /// </summary>
        /// <param name="newDic"></param>
        /// <param name="v"></param>
        /// <param name="buf"></param>
        /// <param name="option"></param>
        public override void StorePcm(Dictionary <int, clsPcm> newDic, KeyValuePair <int, clsPcm> v, byte[] buf, bool is16bit, int samplerate, params object[] option)
        {
            clsPcmDataInfo pi = pcmDataInfo[0];

            try
            {
                List <byte> dBuf = new List <byte>();
                if (is16bit)
                {
                    //16bit signed Only
                    EncC140CompressedPCM(dBuf, buf, true, true);
                }
                else
                {
                    //8bit unsigned Only
                    EncC140LinerSigned8bitPCM(dBuf, buf, false, false);
                }
                buf = dBuf.ToArray();

                long   size   = buf.Length;
                byte[] newBuf = new byte[size];
                Array.Copy(buf, newBuf, size);
                buf = newBuf;

                //65536 バイトを超える場合はそれ以降をカット
                if (size > 0x10000)
                {
                    List <byte> n = newBuf.ToList();
                    n.RemoveRange(0x10000, (int)(size - 0x10000));
                    newBuf = n.ToArray();
                    size   = 0x10000;
                }

                //空いているBankを探す
                int freeBank = 0;
                int freeAdr  = 0;
                do
                {
                    if (memoryMap.Count < freeBank + 1)
                    {
                        memoryMap.Add(0);
                        freeAdr              = 0 + freeBank * 0x10000;
                        memoryMap[freeBank] += size;
                        break;
                    }

                    if (size < 0x10000 - memoryMap[freeBank])
                    {
                        freeAdr              = (int)(memoryMap[freeBank] + freeBank * 0x10000);
                        memoryMap[freeBank] += size;
                        break;
                    }

                    freeBank++;
                } while (true);

                //パディング(空きが足りない場合はバンクをひとつ進める(0x10000)為、空きを全て埋める)
                while (freeAdr > pi.totalBuf.Length - pi.totalHeaderLength)
                {
                    int fs = (pi.totalBuf.Length - pi.totalHeaderLength) % 0x10000;

                    List <byte> n = pi.totalBuf.ToList();
                    for (int i = 0; i < 0x10000 - fs; i++)
                    {
                        n.Add(0x00);
                    }
                    pi.totalBuf     = n.ToArray();
                    pi.totalBufPtr += 0x10000 - fs;
                }

                newDic.Add(
                    v.Key
                    , new clsPcm(
                        v.Value.num
                        , v.Value.seqNum, v.Value.chip
                        , v.Value.chipNumber
                        , v.Value.fileName
                        , v.Value.freq
                        , v.Value.vol
                        , freeAdr
                        , freeAdr + size - 1
                        , size
                        , (v.Value.loopAdr == -1 ? v.Value.loopAdr : (v.Value.loopAdr + freeAdr))
                        , is16bit
                        , samplerate)
                    );

                if (newDic[v.Key].loopAdr != -1 && (v.Value.loopAdr < 0 || v.Value.loopAdr >= size))
                {
                    msgBox.setErrMsg(string.Format(msg.get("E09000")
                                                   , newDic[v.Key].loopAdr
                                                   , size - 1), new LinePos("-"));
                    newDic[v.Key].loopAdr = -1;
                    newDic[v.Key].status  = enmPCMSTATUS.ERROR;
                }

                if (freeAdr == pi.totalBufPtr)
                {
                    pi.totalBufPtr += size;

                    if (pi.totalBufPtr > 0xf_ffff)
                    {
                        isSystem2 = false;
                    }

                    newBuf = new byte[pi.totalBuf.Length + buf.Length];
                    Array.Copy(pi.totalBuf, newBuf, pi.totalBuf.Length);
                    Array.Copy(buf, 0, newBuf, pi.totalBuf.Length, buf.Length);
                    pi.totalBuf = newBuf;
                }
                else
                {
                    Array.Copy(buf, 0, pi.totalBuf, freeAdr + pi.totalHeaderLength, buf.Length);
                }

                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4))
                    , ChipNumber != 0
                    );//size of data ( totalHeadrSizeOfDataPtr:サイズ値を設定する位置 4:サイズ値の大きさ(4byte32bit) )
                Common.SetUInt32bit31(
                    pi.totalBuf
                    , pi.totalHeadrSizeOfDataPtr + 4
                    , (UInt32)(pi.totalBuf.Length - (pi.totalHeadrSizeOfDataPtr + 4 + 4 + 4))
                    );//size of the entire ROM
                pi.use      = true;
                pcmDataEasy = pi.use ? pi.totalBuf : null;
            }
            catch
            {
                pi.use = false;
                newDic[v.Key].status = enmPCMSTATUS.ERROR;
            }

            //for(int i = 0; i < pi.totalBuf.Length; i++)
            //{
            //    if (i % 16 == 0)
            //    {
            //        Console.Write("\r\n{0:x06}::", i);
            //    }
            //    Console.Write("{0:x02} ", pi.totalBuf[i]);
            //}
        }