Diff for /np2/sound/beepg.c between versions 1.2 and 1.7

version 1.2, 2003/10/19 16:54:51 version 1.7, 2011/01/15 18:04:43
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          clk;
         BPEVENT *bev;          int                     event;
           SINT32          remain;
           SINT32          samp;
   
         vol = beepcfg.vol << 11;          vol = beepcfg.vol;
         bev = bp->event;          bev = bp->event;
           if (bp->events) {
                   bp->events--;
                   clk = bev->clock;
                   event = bev->enable;
                   bev++;
           }
           else {
                   clk = 0x40000000;
                   event = bp->lastenable;
           }
         do {          do {
                 remain = beepcfg.sampleclock;                  remain = (1 << 16);
                 samp = 0;                  samp = 0;
                 while(remain >= bev->clock) {                  while(remain >= clk) {
                         if (--bp->events) {                          remain -= clk;
                                 remain -= bev->clock;                          if (bp->lastenable) {
                                 if (bp->lastenable) {                                  samp += clk;
                                         samp += bev->clock;                          }
                                 }                          bp->lastenable = event;
                                 bp->lastenable = bev->enable;                          if (bp->events) {
                                   bp->events--;
                                   clk = bev->clock;
                                   event = bev->enable;
                                 bev++;                                  bev++;
                         }                          }
                         else {                                                          // サンプルがぽなくなり                          else {
                                 if (bp->lastenable) {                                  clk = 0x40000000;
                                         samp += remain;  
                                         samp *= vol;  
                                         samp /= beepcfg.sampleclock;  
                                         do {  
                                                 pcm[0] += samp;  
                                                 pcm[1] += samp;  
                                                 pcm += 2;  
                                                 samp >>= 1;  
                                         } while(--count);  
                                 }  
                                 else {  
                                         samp *= vol;  
                                         samp /= beepcfg.sampleclock;  
                                         pcm[0] += samp;  
                                         pcm[1] += samp;  
                                 }  
                                 bp->lastenable = bev->enable;  
                                 return;  
                         }                          }
                 }                  }
                 bev->clock -= remain;                  clk -= remain;
                 if (bp->lastenable) {                  if (bp->lastenable) {
                         samp += remain;                          samp += remain;
                 }                  }
                 samp *= vol;                  samp *= vol;
                 samp /= beepcfg.sampleclock;                  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 rategenerate(BEEP bp, SINT32 *pcm, UINT count) {  static void rategenerator(BEEP bp, SINT32 *pcm, UINT count) {
   
         UINT    vol;          SINT32          vol;
         SINT32  samp;  const BPEVENT   *bev;
         UINT    r;          SINT32          samp;
           SINT32          remain;
           SINT32          clk;
           int                     event;
           UINT            r;
   
         vol = beepcfg.vol << 8;          vol = beepcfg.vol;
           bev = bp->event;
           if (bp->events) {
                   bp->events--;
                   clk = bev->clock;
                   event = bev->enable;
                   bev++;
           }
           else {
                   clk = 0x40000000;
                   event = bp->lastenable;
           }
         do {          do {
                 samp = 0;                  if (clk >= (1 << 16)) {
                 r = 4;                          r = clk >> 16;
                 do {                          r = min(r, count);
                         bp->cnt += bp->hz;                          clk -= r << 16;
                         samp += vol * ((bp->cnt & 0x8000)?1:-1);                          count -= r;
                 } while(--r);                          if (bp->lastenable) {
                 pcm[0] += samp;                                  do {
                 pcm[1] += samp;                                          samp = (bp->cnt & 0x8000)?1:-1;
                 pcm += 2;                                          bp->cnt += bp->hz;
         } while(--count);                                          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 >= clk) {
                                   remain -= clk;
                                   if (bp->lastenable) {
                                           samp += clk;
                                   }
                                   bp->lastenable = event;
                                   bp->cnt = 0;
                                   if (bp->events) {
                                           bp->events--;
                                           clk = bev->clock;
                                           event = bev->enable;
                                           bev++;
                                   }
                                   else {
                                           clk = 0x40000000;
                                   }
                           }
                           clk -= 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;
 }  }
   
 void SOUNDCALL beep_getpcm(BEEP bp, SINT32 *pcm, UINT count) {  void SOUNDCALL beep_getpcm(BEEP bp, SINT32 *pcm, UINT count) {
   
         if ((count) && (beepcfg.vol)) {          if ((count) && (beepcfg.vol)) {
                 if (bp->mode == 0) {                  if (bp->mode == 0) {
                         if ((bp->events) && (beepcfg.sampleclock)) {                          if (bp->events) {
                                 oneshot(bp, pcm, count);                                  oneshot(bp, pcm, count);
                         }                          }
                 }                  }
                 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.2  
changed lines
  Added in v.1.7


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