Diff for /np2/sound/getsnd/getwave.c between versions 1.1 and 1.5

version 1.1, 2004/01/08 16:29:56 version 1.5, 2005/02/07 14:46:13
Line 5 Line 5
 #if defined(__GNUC__)  #if defined(__GNUC__)
 typedef struct {  typedef struct {
         char    head[4];          char    head[4];
         BYTE    size[4];          UINT8   size[4];
         char    fmt[4];          char    fmt[4];
 } __attribute__ ((packed)) RIFF_HEADER;  } __attribute__ ((packed)) RIFF_HEADER;
   
 typedef struct {  typedef struct {
         char    head[4];          char    head[4];
         BYTE    size[4];          UINT8   size[4];
 } __attribute__ ((packed)) WAVE_HEADER;  } __attribute__ ((packed)) WAVE_HEADER;
   
 typedef struct {  typedef struct {
         BYTE    format[2];          UINT8   format[2];
         BYTE    channel[2];          UINT8   channel[2];
         BYTE    rate[4];          UINT8   rate[4];
         BYTE    rps[4];          UINT8   rps[4];
         BYTE    block[2];          UINT8   block[2];
         BYTE    bit[2];          UINT8   bit[2];
 } __attribute__ ((packed)) WAVE_INFOS;  } __attribute__ ((packed)) WAVE_INFOS;
   
 typedef struct {  typedef struct {
         BYTE    exsize[2];          UINT8   exsize[2];
         BYTE    spb[2];          UINT8   spb[2];
         BYTE    numcoef[2];          UINT8   numcoef[2];
 } __attribute__ ((packed)) WAVE_MSA_INFO;  } __attribute__ ((packed)) WAVE_MSA_INFO;
   
 #else /* __GNUC__ */  #else /* __GNUC__ */
Line 34  typedef struct { Line 34  typedef struct {
 #pragma pack(push, 1)  #pragma pack(push, 1)
 typedef struct {  typedef struct {
         char    head[4];          char    head[4];
         BYTE    size[4];          UINT8   size[4];
         char    fmt[4];          char    fmt[4];
 } RIFF_HEADER;  } RIFF_HEADER;
   
 typedef struct {  typedef struct {
         char    head[4];          char    head[4];
         BYTE    size[4];          UINT8   size[4];
 } WAVE_HEADER;  } WAVE_HEADER;
   
 typedef struct {  typedef struct {
         BYTE    format[2];          UINT8   format[2];
         BYTE    channel[2];          UINT8   channel[2];
         BYTE    rate[4];          UINT8   rate[4];
         BYTE    rps[4];          UINT8   rps[4];
         BYTE    block[2];          UINT8   block[2];
         BYTE    bit[2];          UINT8   bit[2];
 } WAVE_INFOS;  } WAVE_INFOS;
   
 typedef struct {  typedef struct {
         BYTE    exsize[2];          UINT8   exsize[2];
         BYTE    spb[2];          UINT8   spb[2];
         BYTE    numcoef[2];          UINT8   numcoef[2];
 } WAVE_MSA_INFO;  } WAVE_MSA_INFO;
 #pragma pack(pop)  #pragma pack(pop)
   
Line 85  static UINT pcm_dec(GETSND snd, void *ds Line 85  static UINT pcm_dec(GETSND snd, void *ds
         return(size);          return(size);
 }  }
 #elif defined(BYTESEX_BIG)  #elif defined(BYTESEX_BIG)
 static UINT pcm_dec(SMIXTRACK *trk, short *dst) {  static UINT pcm_dec(GETSND snd, UINT8 *dst) {
   
 #error pcm_dec: unsupported          UINT    size;
         return(0);          UINT    cnt;
           UINT8   *src;
   
           size = min(snd->blocksize, snd->datsize);
           if (size) {
                   if (snd->bit == 16) {
                           cnt = size >> 1;
                           src = snd->datptr;
                           while(cnt) {
                                   cnt--;
                                   dst[0] = src[1];
                                   dst[1] = src[0];
                                   src += 2;
                                   dst += 2;
                           }
                   }
                   else {
                           CopyMemory(dst, snd->datptr, size);
                   }
                   snd->datptr += size;
                   snd->datsize -= size;
                   size >>= (int)(long)snd->snd;
           }
           return(size);
 }  }
 #endif  #endif
   
 static const BYTE abits[4] = {0, 1, 0, 2};  static const UINT8 abits[4] = {0, 1, 0, 2};
   
 static BOOL pcm_open(GETSND snd) {  static BOOL pcm_open(GETSND snd) {
   
Line 108  static BOOL pcm_open(GETSND snd) { Line 131  static BOOL pcm_open(GETSND snd) {
         snd->blocksamples = 0x800;                                      // 適当に。          snd->blocksamples = 0x800;                                      // 適当に。
         snd->blocksize *= snd->blocksamples;          snd->blocksize *= snd->blocksamples;
         snd->snd = (void *)(long)abits[align - 1];          snd->snd = (void *)(long)abits[align - 1];
         snd->dec = pcm_dec;          snd->dec = (GSDEC)pcm_dec;
         return(SUCCESS);          return(SUCCESS);
   
 pcmopn_err:  pcmopn_err:
Line 119  pcmopn_err: Line 142  pcmopn_err:
 // ---- MS-ADPCM  // ---- MS-ADPCM
   
 typedef struct {  typedef struct {
         short Coef1;          SINT16  Coef1;
         short Coef2;          SINT16  Coef2;
 } __COEFPAIR;  } __COEFPAIR;
   
 static const int MSADPCMTable[16] = {  static const int MSADPCMTable[16] = {
Line 128  static const int MSADPCMTable[16] = { Line 151  static const int MSADPCMTable[16] = {
         768, 614, 512, 409, 307, 230, 230, 230           768, 614, 512, 409, 307, 230, 230, 230 
 };  };
   
 static UINT msa_dec(GETSND snd, short *dst) {  static UINT msa_dec(GETSND snd, SINT16 *dst) {
   
         BYTE            *buf;          UINT8           *buf;
         UINT            size;          UINT            size;
         UINT            outsamples;          UINT            outsamples;
         int                     pred[2], delta[2], nibble;          int                     pred[2], delta[2], nibble;
         UINT            i;          UINT            i;
         BYTE            indata;          UINT8           indata;
         __COEFPAIR      *coef;          __COEFPAIR      *coef;
         UINT            ch;          UINT            ch;
         long            outdata;          SINT32          outdata;
   
         buf = snd->datptr;                                              // ワーク使ってません。          buf = snd->datptr;                                              // ワーク使ってません。
         size = min(snd->datsize, snd->blocksize);          size = min(snd->datsize, snd->blocksize);
Line 152  static UINT msa_dec(GETSND snd, short *d Line 175  static UINT msa_dec(GETSND snd, short *d
                         pred[1]  = 0;                          pred[1]  = 0;
                         delta[0] = LOADINTELWORD(buf+1);                          delta[0] = LOADINTELWORD(buf+1);
                         delta[1] = 0;                          delta[1] = 0;
                         *dst++   = (short)LOADINTELWORD(buf+5);                          *dst++   = (SINT16)LOADINTELWORD(buf+5);
                         *dst++   = (short)LOADINTELWORD(buf+3);                          *dst++   = (SINT16)LOADINTELWORD(buf+3);
                         buf += 7;                          buf += 7;
                         outsamples = 2 + ((size - 7) * 2);                          outsamples = 2 + ((size - 7) * 2);
                 }                  }
Line 164  static UINT msa_dec(GETSND snd, short *d Line 187  static UINT msa_dec(GETSND snd, short *d
                         pred[1]  = buf[1];                          pred[1]  = buf[1];
                         delta[0] = LOADINTELWORD(buf+2);                          delta[0] = LOADINTELWORD(buf+2);
                         delta[1] = LOADINTELWORD(buf+4);                          delta[1] = LOADINTELWORD(buf+4);
                         *dst++   = (short)LOADINTELWORD(buf+10);                          *dst++   = (SINT16)LOADINTELWORD(buf+10);
                         *dst++   = (short)LOADINTELWORD(buf+12);                          *dst++   = (SINT16)LOADINTELWORD(buf+12);
                         *dst++   = (short)LOADINTELWORD(buf+6);                          *dst++   = (SINT16)LOADINTELWORD(buf+6);
                         *dst++   = (short)LOADINTELWORD(buf+8);                          *dst++   = (SINT16)LOADINTELWORD(buf+8);
                         buf += 14;                          buf += 14;
                         outsamples = 2 + (size - 14);                          outsamples = 2 + (size - 14);
                 }                  }
Line 200  static UINT msa_dec(GETSND snd, short *d Line 223  static UINT msa_dec(GETSND snd, short *d
                         else if (outdata < -32768) {                          else if (outdata < -32768) {
                                 outdata = -32768;                                  outdata = -32768;
                         }                          }
                         *dst++ = (short)outdata;                          *dst++ = (SINT16)outdata;
                 }                  }
         }          }
         return(outsamples);          return(outsamples);
Line 219  static BOOL msa_open(GETSND snd, WAVE_IN Line 242  static BOOL msa_open(GETSND snd, WAVE_IN
         UINT                    spb;          UINT                    spb;
         UINT                    blk;          UINT                    blk;
         __COEFPAIR              *coef;          __COEFPAIR              *coef;
         BYTE                    *p;          UINT8                   *p;
   
         if (snd->bit != 4) {          if ((snd->bit != 4) ||
                   (headsize < (sizeof(WAVE_INFOS) + sizeof(WAVE_MSA_INFO)))) {
                 goto msaopn_err;                  goto msaopn_err;
         }          }
         info = (WAVE_MSA_INFO *)(wavehead + 1);          info = (WAVE_MSA_INFO *)(wavehead + 1);
         headsize -= sizeof(WAVE_INFOS);          headsize -= sizeof(WAVE_INFOS);
         headsize -= sizeof(WAVE_MSA_INFO);          headsize -= sizeof(WAVE_MSA_INFO);
         if ((signed long)headsize < 0) {  
                 goto msaopn_err;  
         }  
         exsize = LOADINTELWORD(info->exsize);          exsize = LOADINTELWORD(info->exsize);
         spb = LOADINTELWORD(info->spb);          spb = LOADINTELWORD(info->spb);
         numcoef = LOADINTELWORD(info->numcoef);          numcoef = LOADINTELWORD(info->numcoef);
Line 264  static BOOL msa_open(GETSND snd, WAVE_IN Line 285  static BOOL msa_open(GETSND snd, WAVE_IN
         snd->decend = msa_decend;          snd->decend = msa_decend;
         snd->snd = (void *)coef;          snd->snd = (void *)coef;
   
         p = (BYTE *)(info + 1);          p = (UINT8 *)(info + 1);
         do {          do {
                 coef->Coef1 = LOADINTELWORD(p + 0);                  coef->Coef1 = LOADINTELWORD(p + 0);
                 coef->Coef2 = LOADINTELWORD(p + 2);                  coef->Coef2 = LOADINTELWORD(p + 2);
Line 283  msaopn_err: Line 304  msaopn_err:
 #define IMA_MAXSTEP             89  #define IMA_MAXSTEP             89
   
 static  BOOL    ima_init = FALSE;  static  BOOL    ima_init = FALSE;
 static  BYTE    ima_statetbl[IMA_MAXSTEP][8];  static  UINT8   ima_statetbl[IMA_MAXSTEP][8];
   
 static const int ima_stateadj[8] = {-1, -1, -1, -1, 2, 4, 6, 8};  static const int ima_stateadj[8] = {-1, -1, -1, -1, 2, 4, 6, 8};
   
Line 310  static void ima_inittable(void) { Line 331  static void ima_inittable(void) {
                         else if (k >= IMA_MAXSTEP) {                          else if (k >= IMA_MAXSTEP) {
                                 k = IMA_MAXSTEP - 1;                                  k = IMA_MAXSTEP - 1;
                         }                          }
                         ima_statetbl[i][j] = (BYTE)k;                          ima_statetbl[i][j] = (UINT8)k;
                 }                  }
         }          }
 }  }
   
 static UINT ima_dec(GETSND snd, short *dst) {  static UINT ima_dec(GETSND snd, SINT16 *dst) {
   
         UINT    c;          UINT    c;
         int             val[2], state[2];          SINT32  val[2];
         BYTE    *src;          int             state[2];
           UINT8   *src;
         UINT    blk;          UINT    blk;
   
         if (snd->blocksize > snd->datsize) {          if (snd->blocksize > snd->datsize) {
Line 331  static UINT ima_dec(GETSND snd, short *d Line 353  static UINT ima_dec(GETSND snd, short *d
   
         blk = snd->blocksamples;          blk = snd->blocksamples;
         for (c=0; c<snd->channels; c++) {          for (c=0; c<snd->channels; c++) {
                 short tmp;                  SINT16 tmp;
                 tmp = LOADINTELWORD(src);                  tmp = LOADINTELWORD(src);
                 val[c] = tmp;                  val[c] = tmp;
                 *dst++ = (short)val[c];                  *dst++ = (SINT16)val[c];
                 state[c] = src[2];                  state[c] = src[2];
                 if (state[c] >= IMA_MAXSTEP) {                  if (state[c] >= IMA_MAXSTEP) {
                         state[c] = 0;                          state[c] = 0;
Line 372  static UINT ima_dec(GETSND snd, short *d Line 394  static UINT ima_dec(GETSND snd, short *d
                                                 val[c] = -32768;                                                  val[c] = -32768;
                                         }                                          }
                                 }                                  }
                                 *dst = (short)val[c];                                  *dst = (SINT16)val[c];
                                 dst += snd->channels;                                  dst += snd->channels;
                         } while(--r);                          } while(--r);
                         dst -= (8 * snd->channels);                          dst -= (8 * snd->channels);
Line 418  imaopn_err: Line 440  imaopn_err:
 // ---- MP3  // ---- MP3
   
 #if defined(SUPPORT_MP3)  #if defined(SUPPORT_MP3)
 extern BOOL __mp3_open(GETSND snd, BYTE *ptr, UINT size);  extern BOOL __mp3_open(GETSND snd, UINT8 *ptr, UINT size);
 #endif  #endif
   
   
 // ----  // ----
   
 BOOL getwave_open(GETSND snd, BYTE *ptr, UINT size) {  BOOL getwave_open(GETSND snd, UINT8 *ptr, UINT size) {
   
         RIFF_HEADER             *riff;          RIFF_HEADER             *riff;
         WAVE_HEADER             *head;          WAVE_HEADER             *head;
Line 441  BOOL getwave_open(GETSND snd, BYTE *ptr, Line 463  BOOL getwave_open(GETSND snd, BYTE *ptr,
         riff = (RIFF_HEADER *)ptr;          riff = (RIFF_HEADER *)ptr;
         pos = sizeof(RIFF_HEADER);          pos = sizeof(RIFF_HEADER);
         if (size < pos) {          if (size < pos) {
                   TRACEOUT(("wav: error RIFF header"));
                 goto gwopn_err;                  goto gwopn_err;
         }          }
         if (memcmp(riff->head, fmt_riff, 4)) {          if (memcmp(riff->head, fmt_riff, 4)) {
Line 452  BOOL getwave_open(GETSND snd, BYTE *ptr, Line 475  BOOL getwave_open(GETSND snd, BYTE *ptr,
                 head = (WAVE_HEADER *)(ptr + pos);                  head = (WAVE_HEADER *)(ptr + pos);
                 pos += sizeof(WAVE_HEADER);                  pos += sizeof(WAVE_HEADER);
                 if (size < pos) {                  if (size < pos) {
                           TRACEOUT(("wav: error fmt header"));
                         goto gwopn_err;                          goto gwopn_err;
                 }                  }
                 if (memcmp(head->head, chunk_fmt, 4)) {                  if (memcmp(head->head, chunk_fmt, 4)) {
Line 544  BOOL getwave_open(GETSND snd, BYTE *ptr, Line 568  BOOL getwave_open(GETSND snd, BYTE *ptr,
         // 登録〜          // 登録〜
         snd->datptr = ptr;          snd->datptr = ptr;
         snd->datsize = size;          snd->datsize = size;
         TRACEOUT(("ok"));  
         return(SUCCESS);          return(SUCCESS);
   
 gwopn_err:  gwopn_err:
         TRACEOUT(("err"));  
         return(FAILURE);          return(FAILURE);
 }  }
   

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


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