Diff for /np2/sound/beepg.c between versions 1.3 and 1.5

version 1.3, 2003/10/20 12:08:01 version 1.5, 2004/07/03 17:25:39
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
 #include        "pccore.h"  
 #include        "sound.h"  #include        "sound.h"
 #include        "beep.h"  #include        "beep.h"
   
   
 extern  BEEPCFG         beepcfg;  extern  BEEPCFG         beepcfg;
   
   
 static void oneshot(BEEP bp, SINT32 *pcm, UINT count) {  static void oneshot(BEEP bp, SINT32 *pcm, UINT count) {
   
         SINT32  vol;          SINT32          vol;
         SINT32  samp;  const BPEVENT   *bev;
         SINT32  remain;          SINT32          clock;
         BPEVENT *bev;          int                     event;
           SINT32          remain;
           SINT32          samp;
   
         vol = beepcfg.vol;          vol = beepcfg.vol;
         bev = bp->event;          bev = bp->event;
           if (bp->events) {
                   bp->events--;
                   clock = bev->clock;
                   event = bev->enable;
                   bev++;
           }
           else {
                   clock = 0x40000000;
                   event = bp->lastenable;
           }
         do {          do {
                 remain = (1 << 16);                  remain = (1 << 16);
                 samp = 0;                  samp = 0;
                 while(remain >= bev->clock) {                  while(remain >= clock) {
                         if (--bp->events) {                          remain -= clock;
                                 remain -= bev->clock;                          if (bp->lastenable) {
                                 if (bp->lastenable) {                                  samp += clock;
                                         samp += bev->clock;                          }
                                 }                          bp->lastenable = event;
                                 bp->lastenable = bev->enable;                          if (bp->events) {
                                   bp->events--;
                                   clock = bev->clock;
                                   event = bev->enable;
                                 bev++;                                  bev++;
                         }                          }
                         else {                                                          // サンプルがぽなくなり                          else {
                                 if (bp->lastenable) {                                  clock = 0x40000000;
                                         samp += remain;  
                                         samp *= vol;  
                                         samp >>= (16 - 11);  
                                         do {  
                                                 pcm[0] += samp;  
                                                 pcm[1] += samp;  
                                                 pcm += 2;  
                                                 samp >>= 1;  
                                         } while(--count);  
                                 }  
                                 else {  
                                         samp *= vol;  
                                         samp >>= (16 - 11);  
                                         pcm[0] += samp;  
                                         pcm[1] += samp;  
                                 }  
                                 bp->lastenable = bev->enable;  
                                 return;  
                         }                          }
                 }                  }
                 bev->clock -= remain;                  clock -= remain;
                 if (bp->lastenable) {                  if (bp->lastenable) {
                         samp += remain;                          samp += remain;
                 }                  }
                 samp *= vol;                  samp *= vol;
                 samp >>= (16 - 11);                  samp >>= (16 - 10);
                 pcm[0] += samp;                  pcm[0] += samp;
                 pcm[1] += samp;                  pcm[1] += samp;
                 pcm += 2;                  pcm += 2;
         } while(--count);          } while(--count);
           bp->lastenable = event;
           bp->events = 0;
   }
   
   static void rategenerator(BEEP bp, SINT32 *pcm, UINT count) {
   
           SINT32          vol;
   const BPEVENT   *bev;
           SINT32          samp;
           SINT32          remain;
           SINT32          clock;
           int                     event;
           UINT            r;
   
           vol = beepcfg.vol;
           bev = bp->event;
           if (bp->events) {
                   bp->events--;
                   clock = bev->clock;
                   event = bev->enable;
                   bev++;
           }
           else {
                   clock = 0x40000000;
                   event = bp->lastenable;
           }
           do {
                   if (clock >= (1 << 16)) {
                           r = clock >> 16;
                           r = min(r, count);
                           clock -= r << 16;
                           count -= r;
                           if (bp->lastenable) {
                                   do {
                                           samp = (bp->cnt & 0x8000)?1:-1;
                                           bp->cnt += bp->hz;
                                           samp += (bp->cnt & 0x8000)?1:-1;
                                           bp->cnt += bp->hz;
                                           samp += (bp->cnt & 0x8000)?1:-1;
                                           bp->cnt += bp->hz;
                                           samp += (bp->cnt & 0x8000)?1:-1;
                                           bp->cnt += bp->hz;
                                           samp *= vol;
                                           samp <<= (10 - 2);
                                           pcm[0] += samp;
                                           pcm[1] += samp;
                                           pcm += 2;
                                   } while(--r);
                           }
                           else {
                                   pcm += 2 * r;
                           }
                   }
                   else {
                           remain = (1 << 16);
                           samp = 0;
                           while(remain >= clock) {
                                   remain -= clock;
                                   if (bp->lastenable) {
                                           samp += clock;
                                   }
                                   bp->lastenable = event;
                                   bp->cnt = 0;
                                   if (bp->events) {
                                           bp->events--;
                                           clock = bev->clock;
                                           event = bev->enable;
                                           bev++;
                                   }
                                   else {
                                           clock = 0x40000000;
                                   }
                           }
                           clock -= remain;
                           if (bp->lastenable) {
                                   samp += remain;
                           }
                           samp *= vol;
                           samp >>= (16 - 10);
                           pcm[0] += samp;
                           pcm[1] += samp;
                           pcm += 2;
                           count--;
                   }
           } while(count);
           bp->lastenable = event;
           bp->events = 0;
 }  }
   
 static void rategenerate(BEEP bp, SINT32 *pcm, UINT count) {  static void rategenerate(BEEP bp, SINT32 *pcm, UINT count) {
Line 92  void SOUNDCALL beep_getpcm(BEEP bp, SINT Line 173  void SOUNDCALL beep_getpcm(BEEP bp, SINT
                         }                          }
                 }                  }
                 else if (bp->mode == 1) {                  else if (bp->mode == 1) {
                         if (bp->buz) {                          rategenerator(bp, pcm, count);
                                 if (bp->hz) {  
                                         rategenerate(bp, pcm, count);  
                                 }  
                                 else {  
                                 }  
                         }  
                 }                  }
         }          }
 }  }

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


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