Diff for /np2/sound/sound.c between versions 1.4 and 1.7

version 1.4, 2003/10/20 06:36:33 version 1.7, 2003/10/25 19:10:37
Line 22  typedef struct { Line 22  typedef struct {
         SINT32  *buffer;          SINT32  *buffer;
         SINT32  *ptr;          SINT32  *ptr;
         UINT    samples;          UINT    samples;
           UINT    reserve;
         UINT    remain;          UINT    remain;
         CBTBL   *cbreg;          CBTBL   *cbreg;
         CBTBL   cb[STREAM_CBMAX];          CBTBL   cb[STREAM_CBMAX];
Line 32  static SNDSTREAM sndstream; Line 33  static SNDSTREAM sndstream;
   
 static void streamreset(void) {  static void streamreset(void) {
   
           SNDCSEC_ENTER;
         sndstream.ptr = sndstream.buffer;          sndstream.ptr = sndstream.buffer;
         sndstream.remain = sndstream.samples;          sndstream.remain = sndstream.samples + sndstream.reserve;
         sndstream.cbreg = sndstream.cb;          sndstream.cbreg = sndstream.cb;
           SNDCSEC_TERM;
 }  }
   
 static void streamprepare(UINT samples) {  static void streamprepare(UINT samples) {
Line 61  static void streamprepare(UINT samples)  Line 64  static void streamprepare(UINT samples) 
 BOOL sound_create(UINT rate, UINT ms) {  BOOL sound_create(UINT rate, UINT ms) {
   
         UINT    samples;          UINT    samples;
           UINT    reserve;
   
         ZeroMemory(&sndstream, sizeof(sndstream));          ZeroMemory(&sndstream, sizeof(sndstream));
         switch(rate) {          switch(rate) {
Line 81  BOOL sound_create(UINT rate, UINT ms) { Line 85  BOOL sound_create(UINT rate, UINT ms) {
         soundcfg.rate = rate;          soundcfg.rate = rate;
         sound_changeclock();          sound_changeclock();
   
         sndstream.buffer = (SINT32 *)_MALLOC(samples * 2 * sizeof(SINT32),  #if defined(SOUNDRESERVE)
                                                                                                                                 "stream");          reserve = rate * SOUNDRESERVE / 1000;
   #else
           reserve = 0;
   #endif
           sndstream.buffer = (SINT32 *)_MALLOC((samples + reserve) * 2 
                                                                                                   * sizeof(SINT32), "stream");
         if (sndstream.buffer == NULL) {          if (sndstream.buffer == NULL) {
                 goto scre_err2;                  goto scre_err2;
         }          }
         sndstream.samples = samples;          sndstream.samples = samples;
         streamreset();          sndstream.reserve = reserve;
   
         SNDCSEC_INIT;          SNDCSEC_INIT;
           streamreset();
         return(SUCCESS);          return(SUCCESS);
   
 scre_err2:  scre_err2:
Line 102  scre_err1: Line 112  scre_err1:
 void sound_destroy(void) {  void sound_destroy(void) {
   
         if (sndstream.buffer) {          if (sndstream.buffer) {
                 SNDCSEC_TERM;  
   
                 soundmng_stop();                  soundmng_stop();
                   streamreset();
                 soundmng_destroy();                  soundmng_destroy();
                   SNDCSEC_TERM;
                 _MFREE(sndstream.buffer);                  _MFREE(sndstream.buffer);
                 sndstream.buffer = NULL;                  sndstream.buffer = NULL;
         }          }
Line 180  void sound_sync(void) { Line 190  void sound_sync(void) {
         }          }
         SNDCSEC_ENTER;          SNDCSEC_ENTER;
         streamprepare(length);          streamprepare(length);
         SNDCSEC_LEAVE;  
         soundcfg.writecount += length;  
         soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase;          soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase;
         beep_eventreset();          beep_eventreset();
           SNDCSEC_LEAVE;
   
           soundcfg.writecount += length;
         if (soundcfg.writecount >= 100) {          if (soundcfg.writecount >= 100) {
                 soundcfg.writecount = 0;                  soundcfg.writecount = 0;
                 soundmng_sync();                  soundmng_sync();
         }          }
 }  }
   
   static volatile int locks = 0;
   
 const SINT32 *sound_pcmlock(void) {  const SINT32 *sound_pcmlock(void) {
   
 const SINT32 *ret;  const SINT32 *ret;
   
           if (locks) {
                   return(NULL);
           }
           locks++;
         ret = sndstream.buffer;          ret = sndstream.buffer;
         if (ret) {          if (ret) {
                 SNDCSEC_ENTER;                  SNDCSEC_ENTER;
                 if (sndstream.remain) {                  if (sndstream.remain > sndstream.reserve) {
                         streamprepare(sndstream.remain);                          streamprepare(sndstream.remain - sndstream.reserve);
                         soundcfg.lastclock = I286_CLOCK + I286_BASECLOCK - I286_REMCLOCK;                          soundcfg.lastclock = I286_CLOCK + I286_BASECLOCK - I286_REMCLOCK;
                         beep_eventreset();                          beep_eventreset();
                 }                  }
Line 209  const SINT32 *ret; Line 225  const SINT32 *ret;
   
 void sound_pcmunlock(const SINT32 *hdl) {  void sound_pcmunlock(const SINT32 *hdl) {
   
           int             leng;
   
         if (hdl) {          if (hdl) {
                 sndstream.ptr = sndstream.buffer;                  leng = sndstream.reserve - sndstream.remain;
                 sndstream.remain = sndstream.samples;                  if (leng > 0) {
                           CopyMemory(sndstream.buffer,
                                                   sndstream.buffer + (sndstream.samples * 2),
                                                                                                   leng * 2 * sizeof(SINT32));
                   }
                   sndstream.ptr = sndstream.buffer + (leng * 2);
                   sndstream.remain = sndstream.samples + sndstream.reserve - leng;
   //              sndstream.remain += sndstream.samples;
                 SNDCSEC_LEAVE;                  SNDCSEC_LEAVE;
                   locks--;
         }          }
 }  }
   

Removed from v.1.4  
changed lines
  Added in v.1.7


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