Diff for /np2/sound/opngeng.c between versions 1.3 and 1.8

version 1.3, 2003/10/18 09:02:38 version 1.8, 2004/07/26 18:52:55
Line 5 Line 5
 #include        "fmboard.h"  #include        "fmboard.h"
   
   
 extern  OPNCFG  opncfg;  #if defined(OPNGENX86)
   #error use opngen.x86
 extern  SINT32  env_curve[];                            // ver0.27  #endif
 extern  SINT32  envtable[];  
 extern  SINT32  sintable[];                                     // ver0.27  
   
   
 #define SLOTOUT(s, e, c)                                                                                                        \  extern  OPNCFG  opncfg;
                 ((sintable[(((s).freq_cnt + (c)) >> (FREQ_BITS - SIN_BITS)) &           \  
                         (SIN_ENT-1)] * envtable[(e)]) >> (ENVTBL_BIT+SINTBL_BIT-TL_BITS))  
   
 static SINT32 calcrateenvlope(OPNSLOT *slot) {  
   
         /* calcrate phage generator */  #define CALCENV(e, c, s)                                                                                                        \
         slot->freq_cnt += slot->freq_inc;          (c)->slot[(s)].freq_cnt += (c)->slot[(s)].freq_inc;                                             \
         /* calcrate envelope generator */          (c)->slot[(s)].env_cnt += (c)->slot[(s)].env_inc;                                               \
         slot->env_cnt += slot->env_inc;          if ((c)->slot[(s)].env_cnt >= (c)->slot[(s)].env_end) {                                 \
         if (slot->env_cnt >= slot->env_end) {                  switch((c)->slot[(s)].env_mode) {                                                                       \
                 switch(slot->env_mode) {                          case EM_ATTACK:                                                                                                 \
                         case EM_ATTACK:                                         // DECAY1 start                                  (c)->slot[(s)].env_mode = EM_DECAY1;                                            \
                                 slot->env_mode = EM_DECAY1;                                  (c)->slot[(s)].env_cnt = EC_DECAY;                                                      \
                                 slot->env_cnt = EC_DECAY;                                  (c)->slot[(s)].env_end = (c)->slot[(s)].decaylevel;                     \
                                 slot->env_end = slot->decaylevel;                                  (c)->slot[(s)].env_inc = (c)->slot[(s)].env_inc_decay1;         \
                                 slot->env_inc = slot->env_inc_decay1;                                  break;                                                                                                          \
                                 break;                          case EM_DECAY1:                                                                                                 \
                                   (c)->slot[(s)].env_mode = EM_DECAY2;                                            \
                                   (c)->slot[(s)].env_cnt = (c)->slot[(s)].decaylevel;                     \
                                   (c)->slot[(s)].env_end = EC_OFF;                                                        \
                                   (c)->slot[(s)].env_inc = (c)->slot[(s)].env_inc_decay2;         \
                                   break;                                                                                                          \
                           case EM_RELEASE:                                                                                                \
                                   (c)->slot[(s)].env_mode = EM_OFF;                                                       \
                           case EM_DECAY2:                                                                                                 \
                                   (c)->slot[(s)].env_cnt = EC_OFF;                                                        \
                                   (c)->slot[(s)].env_end = EC_OFF + 1;                                            \
                                   (c)->slot[(s)].env_inc = 0;                                                                     \
                                   (c)->playing &= ~(1 << (s));                                                            \
                                   break;                                                                                                          \
                   }                                                                                                                                       \
           }                                                                                                                                               \
           (e) = (c)->slot[(s)].totallevel -                                                                               \
                                           opncfg.envcurve[(c)->slot[(s)].env_cnt >> ENV_BITS];
   
                         case EM_DECAY1:                                         // DECAY2 start  #define SLOTOUT(s, e, c)                                                                                                        \
                                 slot->env_mode = EM_DECAY2;                  ((opncfg.sintable[(((s).freq_cnt + (c)) >>                                                      \
                                 slot->env_cnt = slot->decaylevel;                                                          (FREQ_BITS - SIN_BITS)) & (SIN_ENT-1)] *                \
                                 slot->env_end = EC_OFF;                                  opncfg.envtable[(e)]) >> (ENVTBL_BIT+SINTBL_BIT-TL_BITS))
                                 slot->env_inc = slot->env_inc_decay2;  
                                 break;  
   
                         case EM_RELEASE:                                        // OFF timing  
                                 slot->env_mode = EM_OFF;  
   
                         case EM_DECAY2:                                         // DECAY end  
                                 slot->env_cnt = EC_OFF;  
                                 slot->env_end = EC_OFF + 1;  
                                 slot->env_inc = 0;  
                                 break;  
                 }  
         }  
         return(slot->totallevel - env_curve[slot->env_cnt >> ENV_BITS]);  
 }  
   
 static void calcratechannel(OPNCH *ch) {  static void calcratechannel(OPNCH *ch) {
   
Line 61  static void calcratechannel(OPNCH *ch) { Line 59  static void calcratechannel(OPNCH *ch) {
         opngen.feedback4 = 0;          opngen.feedback4 = 0;
   
         /* SLOT 1 */          /* SLOT 1 */
         envout = calcrateenvlope(ch->slot + 0);          CALCENV(envout, ch, 0);
         if (envout > 0) {          if (envout > 0) {
                 if (ch->feedback) {                  if (ch->feedback) {
                         /* with self feed back */                          /* with self feed back */
Line 83  static void calcratechannel(OPNCH *ch) { Line 81  static void calcratechannel(OPNCH *ch) {
                 }                  }
         }          }
         /* SLOT 2 */          /* SLOT 2 */
         envout = calcrateenvlope(ch->slot + 1);          CALCENV(envout, ch, 1);
         if (envout > 0) {          if (envout > 0) {
                 *ch->connect2 += SLOTOUT(ch->slot[1], envout, opngen.feedback2);                  *ch->connect2 += SLOTOUT(ch->slot[1], envout, opngen.feedback2);
         }          }
         /* SLOT 3 */          /* SLOT 3 */
         envout = calcrateenvlope(ch->slot + 2);          CALCENV(envout, ch, 2);
         if (envout > 0) {          if (envout > 0) {
                 *ch->connect3 += SLOTOUT(ch->slot[2], envout, opngen.feedback3);                  *ch->connect3 += SLOTOUT(ch->slot[2], envout, opngen.feedback3);
         }          }
         /* SLOT 4 */          /* SLOT 4 */
         envout = calcrateenvlope(ch->slot + 3);          CALCENV(envout, ch, 3);
         if (envout > 0) {          if (envout > 0) {
                 *ch->connect4 += SLOTOUT(ch->slot[3], envout, opngen.feedback4);                  *ch->connect4 += SLOTOUT(ch->slot[3], envout, opngen.feedback4);
         }          }
Line 103  void SOUNDCALL opngen_getpcm(void *hdl,  Line 101  void SOUNDCALL opngen_getpcm(void *hdl, 
   
         OPNCH   *fm;          OPNCH   *fm;
         UINT    i;          UINT    i;
           UINT    playing;
         SINT32  samp_l;          SINT32  samp_l;
         SINT32  samp_r;          SINT32  samp_r;
   
           if ((!opngen.playing) || (!count)) {
                   return;
           }
         fm = opnch;          fm = opnch;
         while(count--) {          do {
                 samp_l = opngen.outdl * (opngen.calcremain * -1);                  samp_l = opngen.outdl * (opngen.calcremain * -1);
                 samp_r = opngen.outdr * (opngen.calcremain * -1);                  samp_r = opngen.outdr * (opngen.calcremain * -1);
                 opngen.calcremain += FMDIV_ENT;                  opngen.calcremain += FMDIV_ENT;
Line 115  void SOUNDCALL opngen_getpcm(void *hdl,  Line 117  void SOUNDCALL opngen_getpcm(void *hdl, 
                         opngen.outdc = 0;                          opngen.outdc = 0;
                         opngen.outdl = 0;                          opngen.outdl = 0;
                         opngen.outdr = 0;                          opngen.outdr = 0;
                           playing = 0;
                         for (i=0; i<opngen.playchannels; i++) {                          for (i=0; i<opngen.playchannels; i++) {
                                 calcratechannel(fm + i);                                  if (fm[i].playing & fm[i].outslot) {
                                           calcratechannel(fm + i);
                                           playing++;
                                   }
                         }                          }
                         opngen.outdl += opngen.outdc;                          opngen.outdl += opngen.outdc;
                         opngen.outdr += opngen.outdc;                          opngen.outdr += opngen.outdc;
Line 143  void SOUNDCALL opngen_getpcm(void *hdl,  Line 149  void SOUNDCALL opngen_getpcm(void *hdl, 
                 pcm[1] += samp_r;                  pcm[1] += samp_r;
                 opngen.calcremain -= opncfg.calc1024;                  opngen.calcremain -= opncfg.calc1024;
                 pcm += 2;                  pcm += 2;
         }          } while(--count);
           opngen.playing = playing;
         (void)hdl;          (void)hdl;
 }  }
   
Line 193  void SOUNDCALL opngen_getpcmvr(void *hdl Line 200  void SOUNDCALL opngen_getpcmvr(void *hdl
                 samp_l >>= (OPM_OUTSB + FMDIV_BITS + 1 + 6 - FMVOL_SFTBIT - 8);                  samp_l >>= (OPM_OUTSB + FMDIV_BITS + 1 + 6 - FMVOL_SFTBIT - 8);
                 pcm[0] += samp_l;                  pcm[0] += samp_l;
                 samp_r += opngen.outdr * opngen.calcremain;                  samp_r += opngen.outdr * opngen.calcremain;
                 samp_r >>= FMDIV_BITS;                  samp_r >>= 8;
                 samp_r *= opncfg.fmvol;                  samp_r *= opncfg.fmvol;
                 samp_r >>= (OPM_OUTSB + FMDIV_BITS + 1 + 6 - FMVOL_SFTBIT - 8);                  samp_r >>= (OPM_OUTSB + FMDIV_BITS + 1 + 6 - FMVOL_SFTBIT - 8);
                 pcm[1] += samp_r;                  pcm[1] += samp_r;

Removed from v.1.3  
changed lines
  Added in v.1.8


RetroPC.NET-CVS <cvs@retropc.net>