Diff for /np2/sound/sound.c between versions 1.14 and 1.15

version 1.14, 2004/02/18 20:11:37 version 1.15, 2004/03/24 06:07:57
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
   #include        "wavefile.h"
 #include        "dosio.h"  #include        "dosio.h"
 #include        "soundmng.h"  #include        "soundmng.h"
 #include        "cpucore.h"  #include        "cpucore.h"
Line 26  typedef struct { Line 27  typedef struct {
         UINT    samples;          UINT    samples;
         UINT    reserve;          UINT    reserve;
         UINT    remain;          UINT    remain;
   #if defined(SUPPORT_WAVEREC)
           WAVEWR  rec;
   #endif
         CBTBL   *cbreg;          CBTBL   *cbreg;
         CBTBL   cb[STREAM_CBMAX];          CBTBL   cb[STREAM_CBMAX];
 } SNDSTREAM;  } SNDSTREAM;
Line 61  static void streamprepare(UINT samples)  Line 65  static void streamprepare(UINT samples) 
 }  }
   
   
   #if defined(SUPPORT_WAVEREC)
   // ---- wave rec
   
   BOOL sound_recstart(const char *filename) {
   
           WAVEWR  rec;
   
           sound_recstop();
           if (sndstream.buffer == NULL) {
                   return(FAILURE);
           }
           rec = wavewr_open(filename, soundcfg.rate, 16, 2);
           sndstream.rec = rec;
           if (rec) {
                   return(SUCCESS);
           }
           return(FAILURE);
   }
   
   void sound_recstop(void) {
   
           WAVEWR  rec;
   
           rec = sndstream.rec;
           sndstream.rec = NULL;
           wavewr_close(rec);
   }
   
   static void streamfilewrite(UINT samples) {
   
           CBTBL   *cb;
           UINT    count;
           SINT32  buf32[2*512];
           BYTE    buf[2*2*512];
           UINT    i;
           SINT32  samp;
   
           while(samples) {
                   count = min(samples, 512);
                   ZeroMemory(buf32, count * 2 * sizeof(SINT32));
                   cb = sndstream.cb;
                   while(cb < sndstream.cbreg) {
                           cb->cbfn(cb->hdl, buf32, count);
                           cb++;
                   }
                   for (i=0; i<count*2; i++) {
                           samp = buf32[i];
                           if (samp > 32767) {
                                   samp = 32767;
                           }
                           else if (samp < -32768) {
                                   samp = -32768;
                           }
                           // little endianなので satuation_s16は使えない
                           buf[i*2+0] = (BYTE)samp;
                           buf[i*2+1] = (BYTE)(samp >> 8);
                   }
                   wavewr_write(sndstream.rec, buf, count * 4);
                   samples -= count;
           }
   }
   #endif
   
   
 // ----  // ----
   
 BOOL sound_create(UINT rate, UINT ms) {  BOOL sound_create(UINT rate, UINT ms) {
Line 114  scre_err1: Line 182  scre_err1:
 void sound_destroy(void) {  void sound_destroy(void) {
   
         if (sndstream.buffer) {          if (sndstream.buffer) {
   #if defined(SUPPORT_WAVEREC)
                   sound_recstop();
   #endif
                 soundmng_stop();                  soundmng_stop();
                 streamreset();                  streamreset();
                 soundmng_destroy();                  soundmng_destroy();
Line 190  void sound_sync(void) { Line 261  void sound_sync(void) {
         if (length == 0) {          if (length == 0) {
                 return;                  return;
         }          }
   #if defined(SUPPORT_WAVEREC)
           if (sndstream.rec) {
                   streamfilewrite(length);
                   soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase;
                   beep_eventreset();
                   return;
           }
   #endif
         SNDCSEC_ENTER;          SNDCSEC_ENTER;
         streamprepare(length);          streamprepare(length);
         soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase;          soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase;
Line 209  const SINT32 *sound_pcmlock(void) { Line 288  const SINT32 *sound_pcmlock(void) {
   
 const SINT32 *ret;  const SINT32 *ret;
   
   #if defined(SUPPORT_WAVEREC)
           if (sndstream.rec) {
                   return(NULL);
           }
   #endif
         if (locks) {          if (locks) {
                 TRACEOUT(("sound pcm lock: already locked"));                  TRACEOUT(("sound pcm lock: already locked"));
                 return(NULL);                  return(NULL);
Line 249  void sound_pcmunlock(const SINT32 *hdl)  Line 333  void sound_pcmunlock(const SINT32 *hdl) 
 }  }
   
   
 // ----  // ---- pcmmix
   
 BOOL pcmmix_regist(PMIXDAT *dat, void *datptr, UINT datsize, UINT rate) {  BOOL pcmmix_regist(PMIXDAT *dat, void *datptr, UINT datsize, UINT rate) {
   

Removed from v.1.14  
changed lines
  Added in v.1.15


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