Пример #1
0
        public static byte[] GetPcmData(mucomPCMInfo info, int maxVol)
        {
            int  sadr   = info.stAdr;
            int  eadr   = info.edAdr;
            int  deltaN = 0x49BA + 200;// 0x243e *2;//8kHz
            byte vol    = (byte)maxVol;

            mds.WriteYM2608(0, 1, 0x10, 0x08);
            mds.WriteYM2608(0, 1, 0x10, 0x80);
            mds.WriteYM2608(0, 1, 0x02, (byte)sadr);
            mds.WriteYM2608(0, 1, 0x03, (byte)(sadr >> 8));
            mds.WriteYM2608(0, 1, 0x04, (byte)eadr);
            mds.WriteYM2608(0, 1, 0x05, (byte)(eadr >> 8));
            mds.WriteYM2608(0, 1, 0x09, (byte)deltaN);
            mds.WriteYM2608(0, 1, 0x0a, (byte)(deltaN >> 8));
            mds.WriteYM2608(0, 1, 0x0b, vol);
            mds.WriteYM2608(0, 1, 0x01, 0xc0);
            mds.WriteYM2608(0, 1, 0x00, 0xa0);

            List <byte> pcm = new List <byte>();

            do
            {
                short[] buf = new short[2];
                mds.Update(buf, 0, 1, null);
                //Console.Write("[{0:d8}]/[{1:d8}]\r\n", buf[0]>>8, buf[1]);
                pcm.Add((byte)((buf[0] / (double)short.MaxValue) * sbyte.MaxValue + 0x80));
            } while ((mds.ReadStatusExYM2608(0) & 0x20) != 0);

            //dumpData(pcm.ToArray(), (int)SamplingRate, info.name);
            return(pcm.ToArray());
        }
Пример #2
0
        private static List <mucomPCMInfo> setPCMData(byte[] pcmdata, byte[] adpcmBuffer)
        {
            if (pcmdata == null)
            {
                return(null);
            }

            int infosize;
            int i;
            int pcmtable;
            int inftable;
            int adr, whl, eadr;

            byte[] pcmname          = new byte[17];
            int    maxpcm           = 32;
            List <mucomPCMInfo> ret = null;

            infosize = 0x400;
            inftable = 0x0000;

            pcmtable = 0xe300;
            for (i = 0; i < maxpcm; i++)
            {
                adr  = pcmdata[inftable + 28] | (pcmdata[inftable + 29] * 0x100);
                whl  = pcmdata[inftable + 30] | (pcmdata[inftable + 31] * 0x100);
                eadr = adr + (whl >> 2);
                if (pcmdata[i * 32] != 0)
                {
                    if (ret == null)
                    {
                        ret = new List <mucomPCMInfo>();
                    }
                    mucomPCMInfo info = new mucomPCMInfo();
                    info.no    = i + 1;
                    info.stAdr = adr;
                    info.edAdr = eadr;
                    Array.Copy(pcmdata, i * 32, pcmname, 0, 16);
                    pcmname[16] = 32;
                    info.name   = Encoding.GetEncoding("shift_jis").GetString(pcmname).Trim();
                    ret.Add(info);
                    //Console.WriteLine(string.Format("#PCM{0} ${1:x04} ${2:x04} {3}", info.no, info.stAdr, info.edAdr, info.name));
                }
                pcmtable += 8;
                inftable += 32;
            }

            // データ転送
            Array.Copy(pcmdata, infosize, adpcmBuffer, 0, pcmdata.Length - infosize);

            return(ret);
        }