OSDN Git Service

[VM][FMGEN] Update implemantation of YM2612 (OPN2).
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 19 Jan 2020 19:37:55 +0000 (04:37 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 19 Jan 2020 19:37:55 +0000 (04:37 +0900)
[VM][FMGEN] libCSPfmgen : Update SOVERSION.

source/src/vm/fmgen/CMakeLists.txt
source/src/vm/fmgen/opna.cpp
source/src/vm/fmgen/opna.h

index 79e26ea..81273ab 100644 (file)
@@ -1,7 +1,7 @@
 cmake_minimum_required (VERSION 2.6)
 
 message("* vm/fmgen")
-SET(THIS_LIB_VERSION 1.5.0)
+SET(THIS_LIB_VERSION 1.6.0)
 add_definitions(-D__LIBFMGEN_VERSION=\"libCSPfmgen.${THIS_LIB_VERSION}\")
 
 SET(s_vm_fmgen_srcs
index c753560..6b11125 100644 (file)
@@ -2241,6 +2241,8 @@ void OPN2Base::Reset()
        statusnext = 0;
        lfocount = 0;
        status = 0;
+       dac_enabled = false;
+       dac_data = 0;
        UpdateStatus();
 }
 
@@ -2446,7 +2448,13 @@ void OPN2Base::MixSubSL(int activech, ISample** dest)
        if (activech & 0x010) (*dest[2] += ch[2].CalcL());
        if (activech & 0x040) (*dest[3] += ch[3].CalcL());
        if (activech & 0x100) (*dest[4] += ch[4].CalcL());
-       if (activech & 0x400) (*dest[5] += ch[5].CalcL());
+       if (activech & 0x400) {
+               if ((dac_enabled)) {
+                       (*dest[5] += dac_data);
+               } else {
+                       (*dest[5] += ch[5].CalcL());
+               }
+       }
 }
 
 inline void OPN2Base::MixSubS(int activech, ISample** dest)
@@ -2456,7 +2464,13 @@ inline void OPN2Base::MixSubS(int activech, ISample** dest)
        if (activech & 0x010) (*dest[2] += ch[2].Calc());
        if (activech & 0x040) (*dest[3] += ch[3].Calc());
        if (activech & 0x100) (*dest[4] += ch[4].Calc());
-       if (activech & 0x400) (*dest[5] += ch[5].Calc());
+       if (activech & 0x400) {
+               if ((dac_enabled)) {
+                       (*dest[5] += dac_data);
+               } else {
+                       (*dest[5] += ch[5].Calc());
+               }
+       }
 }
 
 // ---------------------------------------------------------------------------
@@ -2510,7 +2524,6 @@ void OPN2Base::Mix6(Sample* buffer, int nsamples, int activech)
        idest[3] = &ibuf[pan[3]];
        idest[4] = &ibuf[pan[4]];
        idest[5] = &ibuf[pan[5]];
-
        Sample* limit = buffer + nsamples * 2;
        for (Sample* dest = buffer; dest < limit; dest+=2)
        {
@@ -2636,7 +2649,17 @@ void OPN2::SetReg(uint addr, uint data)
                reg29 = data;
 //             UpdateStatus(); //?
                break;
-       
+       case 0x2a:
+               {
+                       int32 tmp;
+                       data &= 0xff;
+                       tmp = (data >= 0x80) ? (-(0x100 - data)) : data;
+                       dac_data = tmp << 6;
+               }
+               break;
+       case 0x2b:
+               dac_enabled = ((data & 0x80) != 0);
+               break;
        default:
                OPN2Base::SetReg(addr, data);
                break;
index f72d379..8a90e13 100644 (file)
@@ -294,6 +294,8 @@ namespace FM
                uint    fnum3[3];
                
                Channel4 ch[6];
+               int32   dac_data;
+               bool    dac_enabled;
 
                static void     BuildLFOTable();
                static int amtable[FM_LFOENTS];
@@ -476,7 +478,6 @@ namespace FM
                //void  ResetStatus(uint bit);
        // \90ü\8c`\95â\8aÔ\97p\83\8f\81[\83N
                int32   mixc, mixc1;
-               
        };
 }