Esempio n. 1
0
        public override string DispRegion(clsPcm pcm)
        {
            bool mode = false;

            if (pcm.option != null &&
                pcm.option.Length > 0 &&
                pcm.option[0] != null &&
                pcm.option[0] is int &&
                (int)pcm.option[0] == 1)
            {
                mode = true;
            }

            return(string.Format("{0,-10} {1,-7} {2,-5:D3} {3,-4:D2} ${4,-7:X4} ${5,-7:X4} {6} ${7,-7:X4}  {8,4} {9}\r\n"
                                 , Name                                                                                 //0
                                 , pcm.chipNumber != 0 ? "SEC" : "PRI"                                                  //1
                                 , pcm.num                                                                              //2
                                 , pcm.stAdr >> 16                                                                      //3
                                 , pcm.stAdr & 0xffff                                                                   //4
                                 , pcm.edAdr & 0xffff                                                                   //5
                                 , pcm.loopAdr == -1 ? "N/A     " : string.Format("${0,-7:X4}", (pcm.loopAdr & 0xffff)) //6
                                 , pcm.size                                                                             //7
                                 , mode ? "DPCM" : "-"                                                                  //mode //8
                                 , pcm.status.ToString()                                                                //9
                                 ));
        }
Esempio n. 2
0
 public override string DispRegion(clsPcm pcm)
 {
     return(string.Format("{0,-10} {1,-7} {2,-5:D3} N/A  ${3,-7:X6} ${4,-7:X6} N/A      ${5,-7:X6}  NONE {6}\r\n"
                          , Name
                          , pcm.isSecondary ? "SEC" : "PRI"
                          , pcm.num
                          , pcm.stAdr & 0xffffff
                          , pcm.edAdr & 0xffffff
                          , pcm.size
                          , pcm.status.ToString()
                          ));
 }
Esempio n. 3
0
 public override string DispRegion(clsPcm pcm)
 {
     return(string.Format("{0,-10} {1,-7} {2,-5:D3} N/A  ${3,-7:X6} ${4,-7:X6} N/A      ${5,-7:X6}  NONE {6}\r\n"
                          , Name + (pcm.loopAdr == 0 ? "_A" : "_B")
                          , pcm.chipNumber != 0 ? "SEC" : "PRI"
                          , pcm.num
                          , pcm.stAdr & 0xffffff
                          , pcm.edAdr & 0xffffff
                          , pcm.size
                          , pcm.status.ToString()
                          ));
 }
Esempio n. 4
0
 public override string DispRegion(clsPcm pcm)
 {
     return(string.Format("{0,-10} {1,-7} {2,-5:D3} {3,-4:D2} ${4,-7:X4} N/A      ${5,-7:X4} ${6,-7:X4}  NONE {7}\r\n"
                          , Name                                //0
                          , pcm.chipNumber != 0 ? "SEC" : "PRI" //1
                          , pcm.num                             //2
                          , pcm.stAdr >> 16                     //3
                          , pcm.stAdr & 0xffff                  //4
                          , pcm.loopAdr & 0xffff                //5
                          , pcm.size                            //6
                          , pcm.status.ToString()               //7
                          ));
 }
Esempio n. 5
0
 public override string DispRegion(clsPcm pcm)
 {
     return(string.Format("{0,-10} {1,-7} {2,-5:D3} {3,-4:D2} ${4,-7:X4} ${5,-7:X4} {6} ${7,-7:X4}  {8,4} {9}\r\n"
                          , Name                                                                                 //0
                          , pcm.chipNumber != 0 ? "SEC" : "PRI"                                                  //1
                          , pcm.num                                                                              //2
                          , pcm.stAdr >> 16                                                                      //3
                          , pcm.stAdr & 0xffff                                                                   //4
                          , pcm.edAdr & 0xffff                                                                   //5
                          , pcm.loopAdr == -1 ? "N/A     " : string.Format("${0,-7:X4}", (pcm.loopAdr & 0xffff)) //6
                          , pcm.size                                                                             //7
                          , pcm.is16bit ? 1 : 0                                                                  //8
                          , pcm.status.ToString()                                                                //9
                          ));
 }
Esempio n. 6
0
 public virtual string DispRegion(clsPcm pcm)
 {
     return("みじっそう");
 }
Esempio n. 7
0
 public static byte[] GetPCMDataFromFile(string path, clsPcm instPCM, out bool isRaw, out bool is16bit, out int samplerate)
 {
     return(GetPCMDataFromFile(path, instPCM.fileName, instPCM.vol, out isRaw, out is16bit, out samplerate));
 }
Esempio n. 8
0
        private void GetPCMData(string path)
        {
            Dictionary <int, clsPcm> newDic = new Dictionary <int, clsPcm>();

            foreach (clsPcmDatSeq pds in desVGM.instPCMDatSeq)
            {
                byte[] buf;
                clsPcm v;
                bool   isRaw;
                bool   is16bit;
                int    samplerate;

                if (pds.chip == enmChipType.None)
                {
                    continue;
                }

                switch (pds.type)
                {
                case enmPcmDefineType.Easy:
                    if (desVGM.instPCM.ContainsKey(pds.No))
                    {
                        desVGM.instPCM.Remove(pds.No);
                    }
                    v = new clsPcm(
                        pds.No
                        , pcmDataSeqNum++
                        , pds.chip
                        , pds.chipNumber
                        , pds.FileName
                        , pds.BaseFreq
                        , pds.Volume
                        , 0
                        , 0
                        , 0
                        , pds.DatLoopAdr
                        , false
                        , 8000);
                    desVGM.instPCM.Add(pds.No, v);

                    //ファイルの読み込み
                    buf = Common.GetPCMDataFromFile(path, v, out isRaw, out is16bit, out samplerate);
                    if (buf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04007")
                                             , v.fileName), new LinePos(pds.FileName));
                        continue;
                    }

                    //pitch変換
                    if (desVGM.info.format == enmFormat.XGM)
                    {
                        int fFreq = (int)pds.DatLoopAdr;
                        //SOXで変換する
                        ConvertFreq(path, ref buf, pds.BaseFreq, ref fFreq);
                        pds.BaseFreq = fFreq;
                        v.freq       = fFreq;
                    }

                    if (desVGM.info.format == enmFormat.XGM && v.chipNumber != 0)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E01017")
                                             , v.fileName), new LinePos(pds.FileName));
                        continue;
                    }

                    if (desVGM.chips.ContainsKey(v.chip))
                    {
                        desVGM.chips[v.chip][v.chipNumber]
                        .StorePcm(
                            newDic
                            , new KeyValuePair <int, clsPcm>(pds.No, v)
                            , buf
                            , is16bit
                            , samplerate);
                    }

                    if (v.chip == enmChipType.YM2609)
                    {
                        if (pds.DatLoopAdr == 0)
                        {
                            //ADPCM-A
                            if (desVGM.chips != null && desVGM.chips.ContainsKey(v.chip) && desVGM.chips[v.chip] != null)
                            {
                                pds.DatEndAdr = (int)((YM2609)desVGM.chips[v.chip][v.chipNumber]).pcmDataEasyA.Length - 16;
                            }
                        }
                        else if (pds.DatLoopAdr == 1)
                        {
                            //ADPCM-B
                            if (desVGM.chips != null && desVGM.chips.ContainsKey(v.chip) && desVGM.chips[v.chip] != null)
                            {
                                pds.DatEndAdr = (int)((YM2609)desVGM.chips[v.chip][v.chipNumber]).pcmDataEasyB.Length - 16;
                            }
                        }
                        else
                        {
                            //ADPCM-C
                            if (desVGM.chips != null && desVGM.chips.ContainsKey(v.chip) && desVGM.chips[v.chip] != null)
                            {
                                pds.DatEndAdr = (int)((YM2609)desVGM.chips[v.chip][v.chipNumber]).pcmDataEasyC.Length - 16;
                            }
                        }
                    }
                    else if (v.chip == enmChipType.YM2610B)
                    {
                        if (pds.DatLoopAdr == 0)
                        {
                            //ADPCM-A
                            if (desVGM.chips != null && desVGM.chips.ContainsKey(v.chip) && desVGM.chips[v.chip] != null)
                            {
                                pds.DatEndAdr = (int)((YM2610B)desVGM.chips[v.chip][v.chipNumber]).pcmDataEasyA.Length - 16;
                            }
                        }
                        else
                        {
                            //ADPCM-B
                            if (desVGM.chips != null && desVGM.chips.ContainsKey(v.chip) && desVGM.chips[v.chip] != null)
                            {
                                pds.DatEndAdr = (int)((YM2610B)desVGM.chips[v.chip][v.chipNumber]).pcmDataEasyB.Length - 16;
                            }
                        }
                    }
                    else
                    {
                        if (desVGM.chips != null && desVGM.chips.ContainsKey(v.chip) && desVGM.chips[v.chip] != null)
                        {
                            pds.DatEndAdr = (int)desVGM.chips[v.chip][v.chipNumber].pcmDataEasy.Length - 16;
                        }
                    }
                    break;

                case enmPcmDefineType.Mucom88:
                    if (desVGM.instPCM.ContainsKey(pds.No))
                    {
                        desVGM.instPCM.Remove(pds.No);
                    }
                    v = new clsPcm(
                        pds.No
                        , pcmDataSeqNum++
                        , pds.chip
                        , pds.chipNumber
                        , pds.FileName
                        , pds.BaseFreq
                        , pds.Volume
                        , 0
                        , 0
                        , 0
                        , pds.DatLoopAdr
                        , false
                        , 8000);
                    desVGM.instPCM.Add(pds.No, v);

                    mucomADPCM2PCM.mucomPCMInfo info = null;
                    for (int i = 0; i < mucomADPCM2PCM.lstMucomPCMInfo.Count; i++)
                    {
                        mucomADPCM2PCM.mucomPCMInfo inf = mucomADPCM2PCM.lstMucomPCMInfo[i];
                        if (pds.No == inf.no)
                        {
                            info = inf;
                            break;
                        }
                    }
                    if (info == null)
                    {
                        return;
                    }

                    //ファイルの読み込み
                    buf = mucomADPCM2PCM.GetPcmData(info);
                    if (buf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04007")
                                             , v.fileName), new LinePos(pds.FileName));
                        continue;
                    }

                    if (desVGM.info.format == enmFormat.XGM && v.chipNumber != 0)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E01017")
                                             , v.fileName), new LinePos(pds.FileName));
                        continue;
                    }

                    desVGM.chips[v.chip][v.chipNumber]
                    .StorePcm(
                        newDic
                        , new KeyValuePair <int, clsPcm>(pds.No, v)
                        , buf
                        , false
                        , 8000);

                    break;

                case enmPcmDefineType.RawData:
                    //ファイルの読み込み
                    buf = Common.GetPCMDataFromFile(path, pds.FileName, 100, out isRaw, out is16bit, out samplerate);
                    if (buf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04007")
                                             , pds.FileName), new LinePos(pds.FileName));
                        continue;
                    }
                    desVGM.chips[pds.chip][pds.chipNumber]
                    .StorePcmRawData(
                        pds
                        , buf
                        , isRaw
                        , is16bit
                        , samplerate);
                    break;

                case enmPcmDefineType.Set:
                    //if(!desVGM.chips[pds.chip][pds.chipNumber ? 1 : 0].StorePcmCheck())
                    //{
                    //    return;
                    //}
                    if (desVGM.instPCM.ContainsKey(pds.No))
                    {
                        desVGM.instPCM.Remove(pds.No);
                    }
                    v = new clsPcm(
                        pds.No
                        , pcmDataSeqNum++
                        , pds.chip
                        , pds.chipNumber
                        , ""
                        , pds.BaseFreq
                        , 100
                        , pds.DatStartAdr
                        , pds.DatEndAdr
                        , pds.chip != enmChipType.RF5C164
                                ? (pds.DatEndAdr - pds.DatStartAdr + 1)
                                : (pds.DatLoopAdr - pds.DatStartAdr + 1)
                        , pds.DatLoopAdr
                        , false
                        , 8000
                        , pds.Option);
                    newDic.Add(pds.No, v);

                    break;
                }
            }

            desVGM.instPCM = newDic;
        }
Esempio n. 9
0
        private void GetPCMData(string path)
        {
            Dictionary <int, clsPcm> newDic = new Dictionary <int, clsPcm>();

            foreach (clsPcmDatSeq pds in desVGM.instPCMDatSeq)
            {
                byte[] buf;
                clsPcm v;
                bool   isRaw;
                bool   is16bit;
                int    samplerate;

                if (pds.chip == enmChipType.None)
                {
                    continue;
                }

                switch (pds.type)
                {
                case enmPcmDefineType.Easy:
                    if (desVGM.instPCM.ContainsKey(pds.No))
                    {
                        desVGM.instPCM.Remove(pds.No);
                    }
                    v = new clsPcm(
                        pds.No
                        , pcmDataSeqNum++
                        , pds.chip
                        , pds.isSecondary
                        , pds.FileName
                        , pds.BaseFreq
                        , pds.Volume
                        , 0
                        , 0
                        , 0
                        , pds.DatLoopAdr
                        , false
                        , 8000);
                    desVGM.instPCM.Add(pds.No, v);

                    //ファイルの読み込み
                    buf = Common.GetPCMDataFromFile(path, v, out isRaw, out is16bit, out samplerate);
                    if (buf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04007")
                                             , v.fileName));
                        continue;
                    }

                    if (desVGM.info.format == enmFormat.XGM && v.isSecondary)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E01017")
                                             , v.fileName));
                        continue;
                    }

                    desVGM.chips[v.chip][v.isSecondary ? 1 : 0]
                    .StorePcm(
                        newDic
                        , new KeyValuePair <int, clsPcm>(pds.No, v)
                        , buf
                        , is16bit
                        , samplerate);

                    break;

                case enmPcmDefineType.Mucom88:
                    if (desVGM.instPCM.ContainsKey(pds.No))
                    {
                        desVGM.instPCM.Remove(pds.No);
                    }
                    v = new clsPcm(
                        pds.No
                        , pcmDataSeqNum++
                        , pds.chip
                        , pds.isSecondary
                        , pds.FileName
                        , pds.BaseFreq
                        , pds.Volume
                        , 0
                        , 0
                        , 0
                        , pds.DatLoopAdr
                        , false
                        , 8000);
                    desVGM.instPCM.Add(pds.No, v);

                    mucomADPCM2PCM.mucomPCMInfo info = null;
                    for (int i = 0; i < mucomADPCM2PCM.lstMucomPCMInfo.Count; i++)
                    {
                        mucomADPCM2PCM.mucomPCMInfo inf = mucomADPCM2PCM.lstMucomPCMInfo[i];
                        if (pds.No == inf.no)
                        {
                            info = inf;
                            break;
                        }
                    }
                    if (info == null)
                    {
                        return;
                    }

                    //ファイルの読み込み
                    buf = mucomADPCM2PCM.GetPcmData(info, desVGM.info.PcmVolume);
                    if (buf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04007")
                                             , v.fileName));
                        continue;
                    }

                    if (desVGM.info.format == enmFormat.XGM && v.isSecondary)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E01017")
                                             , v.fileName));
                        continue;
                    }

                    desVGM.chips[v.chip][v.isSecondary ? 1 : 0]
                    .StorePcm(
                        newDic
                        , new KeyValuePair <int, clsPcm>(pds.No, v)
                        , buf
                        , false
                        , 8000);

                    break;

                case enmPcmDefineType.RawData:
                    //ファイルの読み込み
                    buf = Common.GetPCMDataFromFile(path, pds.FileName, 100, out isRaw, out is16bit, out samplerate);
                    if (buf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04007")
                                             , pds.FileName));
                        continue;
                    }
                    desVGM.chips[pds.chip][pds.isSecondary ? 1 : 0]
                    .StorePcmRawData(
                        pds
                        , buf
                        , isRaw
                        , is16bit
                        , samplerate);
                    break;

                case enmPcmDefineType.Set:
                    //if(!desVGM.chips[pds.chip][pds.isSecondary ? 1 : 0].StorePcmCheck())
                    //{
                    //    return;
                    //}
                    if (desVGM.instPCM.ContainsKey(pds.No))
                    {
                        desVGM.instPCM.Remove(pds.No);
                    }
                    v = new clsPcm(
                        pds.No
                        , pcmDataSeqNum++
                        , pds.chip
                        , pds.isSecondary
                        , ""
                        , pds.BaseFreq
                        , 100
                        , pds.DatStartAdr
                        , pds.DatEndAdr
                        , pds.chip != enmChipType.RF5C164
                                ? (pds.DatEndAdr - pds.DatStartAdr + 1)
                                : (pds.DatLoopAdr - pds.DatStartAdr + 1)
                        , pds.DatLoopAdr
                        , false
                        , 8000
                        , pds.Option);
                    newDic.Add(pds.No, v);

                    break;
                }
            }

            desVGM.instPCM = newDic;
        }
Esempio n. 10
0
        public override void MultiChannelCommand(MML mml)
        {
            foreach (partWork pw in lstPartWork)
            {
                partPage page = pw.cpg;
                int      vol;

                switch (page.Type)
                {
                case enmChannelType.Pulse:
                {
                    //キーオフした直後
                    if (page.keyOff)
                    {
                        vol = 0x10;        //仮
                        SOutData(page, mml, port[0], (byte)(0x00 + page.ch * 4), (byte)vol);
                    }

                    //
                    // Sweepの更新
                    //

                    if (page.keyOn)
                    {
                        for (int i = 0; i < page.lfo.Length; i++)
                        {
                            if (page.lfo[i].type != eLfoType.Hardware)
                            {
                                continue;
                            }

                            if (!page.lfo[i].sw)
                            {
                                SOutData(page, mml, port[0], (byte)(0x01 + page.ch * 4), (byte)0x70);
                                continue;
                            }

                            vol = 0x80
                                  | (page.lfo[i].depthWaitCounter << 4)
                                  | (page.lfo[i].depth < 0 ? 0x08 : 0x00)
                                  | (Math.Abs(page.lfo[i].depth));
                            SOutData(page, mml, port[0], (byte)(0x01 + page.ch * 4), (byte)vol);
                        }
                    }

                    //
                    // 周波数の更新(と位相、エンベロープの初期化)
                    //

                    //キーオンした直後
                    //または周波数が違う 場合は周波数再セット
                    if (page.keyOn ||
                        page.FNum != page.beforeFNum)
                    {
                        int  f    = page.FNum;
                        byte data = (byte)f;
                        SOutData(page, mml, port[0], (byte)(2 + page.ch * 4), data);

                        //キーオンした直後
                        //または周波数上位が違う 場合は周波数上位再セット
                        //(上位をセットすると位相とエンベロープがリセットされる)
                        if (page.keyOn || (page.FNum != page.beforeFNum && (page.FNum & 0x700) != (page.beforeFNum & 0x700)))
                        {
                            data = (byte)((page.HardEnvelopeSw ? (page.HardEnvelopeSpeed << 3) : 0) | ((f >> 8) & 0x7));
                            SOutData(page, mml, port[0], (byte)(3 + page.ch * 4), data);
                        }
                    }


                    //
                    // ボリュームの更新
                    //

                    if (page.keyOn ||
                        page.latestVolume != page.beforeVolume || page.dutyCycle != page.spg.dutyCycle)
                    {
                        vol = ((page.dutyCycle & 0x3) << 6) | (page.HardEnvelopeSw ? (page.HardEnvelopeType == 0 ? 0x10 : 0x20) : 0x30) | Common.CheckRange(page.latestVolume, 0, 15);        //0x30持続音
                        SOutData(page, mml, port[0], (byte)(0x00 + page.ch * 4), (byte)vol);
                    }
                }
                break;

                case enmChannelType.Triangle:
                {
                    //キーオフした直後
                    if (page.keyOff)
                    {
                        //vol = (page.HardEnvelopeSw ? 0 : 0x80) | (page.HardEnvelopeType & 0x7f);//仮
                        vol = (page.HardEnvelopeSw ? (page.HardEnvelopeType & 0x7f) : 0x80);
                        SOutData(page, mml, port[0], 0x08, (byte)vol);
                    }


                    //
                    // 周波数の更新(と位相、エンベロープの初期化)
                    //

                    //キーオンした直後
                    //または周波数が違う 場合は周波数再セット
                    if (page.keyOn ||
                        page.FNum != page.beforeFNum)
                    {
                        int  f    = page.FNum;
                        byte data = (byte)(f & 0xff);
                        SOutData(page, mml, port[0], 0x0a, data);

                        //キーオンした直後
                        //または周波数上位が違う 場合は周波数上位再セット
                        //(上位をセットすると位相とエンベロープがリセットされる)
                        if (page.keyOn || (page.FNum != page.beforeFNum && (page.FNum & 0x700) != (page.beforeFNum & 0x700)))
                        {
                            data = (byte)((page.HardEnvelopeSw ? (page.HardEnvelopeSpeed << 3) : 0) | ((f >> 8) & 0x7));
                            SOutData(page, mml, port[0], 0x0b, data);
                        }
                    }


                    //
                    // ボリュームの更新
                    //

                    if (page.keyOn || page.latestVolume != page.beforeVolume)
                    {
                        vol = (page.HardEnvelopeSw ? (page.HardEnvelopeSpeed & 0x7f) : 0x81);
                        SOutData(page, mml, port[0], 0x08, (byte)vol);
                    }
                }
                break;

                case enmChannelType.Noise:
                {
                    //キーオフした直後
                    if (page.keyOff)
                    {
                        vol = 0x10;        //仮
                        SOutData(page, mml, port[0], 0x0c, (byte)vol);
                    }


                    //
                    // 周波数の更新(と位相、エンベロープの初期化)
                    //

                    //キーオンした直後
                    //または周波数が違う 場合は周波数再セット
                    if (page.keyOn ||
                        page.FNum != page.beforeFNum)
                    {
                        int  f    = page.FNum;
                        byte data = (byte)(((page.spg.noise & 1) << 7) | (f & 0xf));
                        SOutData(page, mml, port[0], 0x0e, data);

                        ////キーオンした直後
                        ////(セットすると位相とエンベロープがリセットされる)
                        if (page.keyOn)
                        {
                            SOutData(page, mml, port[0], 0x0f, (byte)(page.HardEnvelopeSw ? ((page.HardEnvelopeSpeed & 0x1f) << 3) : 0x08));
                        }
                    }


                    //
                    // ボリュームの更新
                    //

                    if (page.keyOn || page.latestVolume != page.beforeVolume)
                    {
                        vol = (page.HardEnvelopeSw ? (page.HardEnvelopeType == 0 ? 0x10 : 0x20) : 0x30) | Common.CheckRange(page.latestVolume, 0, 15);        //0x30持続音
                        SOutData(page, mml, port[0], 0x0c, (byte)vol);
                    }
                }
                break;

                case enmChannelType.DPCM:
                {
                    //キーオフした直後
                    if (page.keyOff)
                    {
                        vol = 0x0f;        //(DMC bit4 clear)
                        SOutData(page, mml, port[0], (byte)0x15, (byte)vol);
                    }


                    //
                    // 音色のセット
                    //
                    if (page.instrument != page.beforeInstrument)
                    {
                        clsPcm p = parent.instPCM[page.instrument].Item2;
                        SOutData(page, mml, port[0], (byte)0x12, (byte)(p.stAdr >> 6));
                        SOutData(page, mml, port[0], (byte)0x13, (byte)(p.size / 16));
                        page.beforeInstrument = page.instrument;
                    }

                    //
                    // 周波数の更新(と位相、エンベロープの初期化)
                    //

                    //キーオンした直後
                    //または周波数が違う 場合は周波数再セット
                    if (page.keyOn ||
                        page.FNum != page.beforeFNum)
                    {
                        int  f    = page.FNum;
                        byte data = (byte)(f & 0x0f);
                        SOutData(page, mml, port[0], 0x10, data);
                    }


                    //
                    // ボリュームの更新
                    //

                    if (page.keyOn || page.latestVolume != page.beforeVolume)
                    {
                        vol = 64;        // Common.CheckRange(page.latestVolume, 0, 127);
                        SOutData(page, mml, port[0], 0x11, (byte)vol);
                    }


                    //キーオンした直後
                    if (page.keyOn)
                    {
                        vol = 0x1f;        //(Set DMC bit4)
                        SOutData(page, mml, port[0], (byte)0x15, (byte)vol);
                    }
                }
                break;

                case enmChannelType.WaveForm:
                {
                    //キーオフした直後
                    if (page.keyOff)
                    {
                        vol = 0x80;
                        SOutData(page, mml, port[0], (byte)0x29, (byte)vol);        //0x4089 この方法あってるのかなぁ
                    }


                    //
                    // 周波数の更新(と位相、エンベロープの初期化)
                    //

                    //キーオンした直後
                    //または周波数が違う 場合は周波数再セット
                    if (page.keyOn)
                    {
                        vol = 0x00;
                        SOutData(page, mml, port[0], (byte)0x29, (byte)vol);        //0x4089 この方法あってるのかなぁ
                    }
                    if (page.FNum != page.beforeFNum)
                    {
                        int  f    = page.FNum;
                        byte data = (byte)(f & 0xff);
                        SOutData(page, mml, port[0], 0x22, data);        //0x4082 freq low
                        data = (byte)((f >> 8) & 0x0f);
                        SOutData(page, mml, port[0], 0x23, data);        //0x4083 freq high
                                                                         //bit7:envelope faster speed
                                                                         //bit6:disable volume and sweep envelopes
                    }


                    //
                    // ボリュームの更新
                    //

                    if (page.keyOn || page.latestVolume != page.beforeVolume)
                    {
                        vol  = Common.CheckRange(page.latestVolume, 0, 63); //bit5-0:ボリューム(エンベロープ時でinc時は到達音量 dec時は謎)
                        vol |= 0x80;                                        //bit7:エンベロープモード0:on
                        //bit6:エンベロープ方向0:dec 1:inc
                        SOutData(page, mml, port[0], 0x20, (byte)vol);      //0x4080
                    }
                }
                break;
                }

                page.keyOff        = false;
                page.keyOn         = false;
                page.beforeVolume  = page.latestVolume;
                page.beforeFNum    = page.FNum;
                page.spg.dutyCycle = page.dutyCycle;
            }
        }
Esempio n. 11
0
        private byte[] GetPCMDataFromFile(string path, clsPcm instPCM, out bool is16bit)
        {
            string fnPcm = Path.Combine(path, instPCM.fileName);

            is16bit = false;

            if (!File.Exists(fnPcm))
            {
                msgBox.setErrMsg(string.Format("PCMファイルの読み込みに失敗しました。(filename:{0})", instPCM.fileName));
                return(null);
            }

            // ファイルの読み込み
            byte[] buf = File.ReadAllBytes(fnPcm);

            if (buf.Length < 4)
            {
                msgBox.setErrMsg("PCMファイル:不正なRIFFヘッダです。");
                return(null);
            }
            if (buf[0] != 'R' || buf[1] != 'I' || buf[2] != 'F' || buf[3] != 'F')
            {
                msgBox.setErrMsg("PCMファイル:不正なRIFFヘッダです。");
                return(null);
            }

            // サイズ取得
            int fSize = buf[0x4] + buf[0x5] * 0x100 + buf[0x6] * 0x10000 + buf[0x7] * 0x1000000;

            if (buf[0x8] != 'W' || buf[0x9] != 'A' || buf[0xa] != 'V' || buf[0xb] != 'E')
            {
                msgBox.setErrMsg("PCMファイル:不正なRIFFヘッダです。");
                return(null);
            }

            try
            {
                int    p   = 12;
                byte[] des = null;

                while (p < fSize + 8)
                {
                    if (buf[p + 0] == 'f' && buf[p + 1] == 'm' && buf[p + 2] == 't' && buf[p + 3] == ' ')
                    {
                        p += 4;
                        int size = buf[p + 0] + buf[p + 1] * 0x100 + buf[p + 2] * 0x10000 + buf[p + 3] * 0x1000000;
                        p += 4;
                        int format = buf[p + 0] + buf[p + 1] * 0x100;
                        if (format != 1)
                        {
                            msgBox.setErrMsg(string.Format("PCMファイル:無効なフォーマットです。({0})", format));
                            return(null);
                        }

                        int channels = buf[p + 2] + buf[p + 3] * 0x100;
                        if (channels != 1)
                        {
                            msgBox.setErrMsg(string.Format("PCMファイル:仕様(mono)とは異なるチャネル数です。({0})", channels));
                            return(null);
                        }

                        int samplerate = buf[p + 4] + buf[p + 5] * 0x100 + buf[p + 6] * 0x10000 + buf[p + 7] * 0x1000000;
                        if (samplerate != 8000 && samplerate != 16000 && samplerate != 18500 && samplerate != 14000)
                        {
                            msgBox.setWrnMsg(string.Format("PCMファイル:仕様(8KHz/14KHz/16KHz/18.5KHz)とは異なるサンプリングレートです。({0})", samplerate));
                            //return null;
                        }

                        int bytepersec = buf[p + 8] + buf[p + 9] * 0x100 + buf[p + 10] * 0x10000 + buf[p + 11] * 0x1000000;
                        if (bytepersec != 8000)
                        {
                            //    msgBox.setWrnMsg(string.Format("PCMファイル:仕様とは異なる平均データ割合です。({0})", bytepersec));
                            //    return null;
                        }

                        int bitswidth = buf[p + 14] + buf[p + 15] * 0x100;
                        if (bitswidth != 8 && bitswidth != 16)
                        {
                            msgBox.setErrMsg(string.Format("PCMファイル:仕様(8bit/16bit)とは異なる1サンプルあたりのビット数です。({0})", bitswidth));
                            return(null);
                        }

                        is16bit = bitswidth == 16;

                        int blockalign = buf[p + 12] + buf[p + 13] * 0x100;
                        if (blockalign != (is16bit ? 2 : 1))
                        {
                            msgBox.setErrMsg(string.Format("PCMファイル:無効なデータのブロックサイズです。({0})", blockalign));
                            return(null);
                        }


                        p += size;
                    }
                    else if (buf[p + 0] == 'd' && buf[p + 1] == 'a' && buf[p + 2] == 't' && buf[p + 3] == 'a')
                    {
                        p += 4;
                        int size = buf[p + 0] + buf[p + 1] * 0x100 + buf[p + 2] * 0x10000 + buf[p + 3] * 0x1000000;
                        p += 4;

                        des = new byte[size];
                        Array.Copy(buf, p, des, 0x00, size);
                        p += size;
                    }
                    else
                    {
                        p += 4;
                        int size = buf[p + 0] + buf[p + 1] * 0x100 + buf[p + 2] * 0x10000 + buf[p + 3] * 0x1000000;
                        p += 4;

                        p += size;
                    }
                }

                // volumeの加工
                if (is16bit)
                {
                    for (int i = 0; i < des.Length; i += 2)
                    {
                        //16bitのwavファイルはsignedのデータのためそのままボリューム変更可能
                        int b = (int)((short)(des[i] | (des[i + 1] << 8)) * instPCM.vol * 0.01);
                        b          = (b > 0xffff) ? 0xffff : b;
                        des[i]     = (byte)(b & 0xff);
                        des[i + 1] = (byte)((b & 0xff00) >> 8);
                    }
                }
                else
                {
                    for (int i = 0; i < des.Length; i++)
                    {
                        //8bitのwavファイルはunsignedのデータのためsignedのデータに変更してからボリューム変更する
                        int d = des[i];
                        //signed化
                        d -= 0x80;
                        d  = (int)(d * instPCM.vol * 0.01);
                        //clip
                        d = (d > 127) ? 127 : d;
                        d = (d < -128) ? -128 : d;
                        //unsigned化
                        d += 0x80;

                        des[i] = (byte)d;
                    }
                }

                return(des);
            }
            catch
            {
                msgBox.setErrMsg("PCMファイル:不正或いは未知のチャンクを持つファイルです。");
                return(null);
            }
        }