[PD-cvs] pd/src d_soundfile.c, 1.4.4.11.2.10.2.25, 1.4.4.11.2.10.2.26

Mathieu Bouchard matju at users.sourceforge.net
Fri Jul 20 07:08:18 CEST 2007


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3778

Modified Files:
      Tag: desiredata
	d_soundfile.c 
Log Message:
using more t_param (again)


Index: d_soundfile.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v
retrieving revision 1.4.4.11.2.10.2.25
retrieving revision 1.4.4.11.2.10.2.26
diff -C2 -d -r1.4.4.11.2.10.2.25 -r1.4.4.11.2.10.2.26
*** d_soundfile.c	20 Jul 2007 04:39:56 -0000	1.4.4.11.2.10.2.25
--- d_soundfile.c	20 Jul 2007 05:08:16 -0000	1.4.4.11.2.10.2.26
***************
*** 197,208 ****
  
  int open_soundfile_via_fd(int fd, int headersize, t_param *p, long skipframes) {
!     int nchannels, bigendian, bytespersample, swap, sysrtn;
!     long bytelimit = 0x7fffffff;
      errno = 0;
      if (headersize >= 0) { /* header detection overridden */
!         bigendian    = p->bigendian;
!         nchannels    = p->nchannels;
!         bytespersample = p->bytespersample;
!         bytelimit    = p->bytelimit;
      } else {
          char buf[MAXPDSTRING];
--- 197,209 ----
  
  int open_soundfile_via_fd(int fd, int headersize, t_param *p, long skipframes) {
!     int swap, sysrtn;
      errno = 0;
+     t_param q;
+     q.bytelimit = 0x7fffffff;
      if (headersize >= 0) { /* header detection overridden */
!         q.bigendian      = p->bigendian;
!         q.nchannels      = p->nchannels;
!         q.bytespersample = p->bytespersample;
!         q.bytelimit      = p->bytelimit;
      } else {
          char buf[MAXPDSTRING];
***************
*** 211,235 ****
          if (bytesread < 4)
              goto badheader;
!         if (!strncmp(buf, ".snd", 4))      format = FORMAT_NEXT, bigendian = 1;
!         else if (!strncmp(buf, "dns.", 4)) format = FORMAT_NEXT, bigendian = 0;
          else if (!strncmp(buf, "RIFF", 4)) {
              if (bytesread < 12 || strncmp(buf + 8, "WAVE", 4)) goto badheader;
!             format = FORMAT_WAVE, bigendian = 0;
          }
          else if (!strncmp(buf, "FORM", 4)) {
              if (bytesread < 12 || strncmp(buf + 8, "AIFF", 4)) goto badheader;
!             format = FORMAT_AIFF, bigendian = 1;
          } else goto badheader;
!         swap = (bigendian != garray_ambigendian());
          if (format == FORMAT_NEXT) {  /* nextstep header */
              if (bytesread < (int)sizeof(t_nextstep)) goto badheader;
!             nchannels = swap4(((t_nextstep *)buf)->nchans, swap);
              format = swap4(((t_nextstep *)buf)->format, swap);
              headersize = swap4(((t_nextstep *)buf)->onset, swap);
!             if      (format == NS_FORMAT_LINEAR_16) bytespersample = 2;
!             else if (format == NS_FORMAT_LINEAR_24) bytespersample = 3;
!             else if (format == NS_FORMAT_FLOAT)     bytespersample = 4;
              else goto badheader;
!             bytelimit = 0x7fffffff;
          } else if (format == FORMAT_WAVE) {    /* wave header */
              /* This is awful.  You have to skip over chunks,
--- 212,236 ----
          if (bytesread < 4)
              goto badheader;
!         if (!strncmp(buf, ".snd", 4))      {format = FORMAT_NEXT; q.bigendian = 1;}
!         else if (!strncmp(buf, "dns.", 4)) {format = FORMAT_NEXT; q.bigendian = 0;}
          else if (!strncmp(buf, "RIFF", 4)) {
              if (bytesread < 12 || strncmp(buf + 8, "WAVE", 4)) goto badheader;
!             format = FORMAT_WAVE; q.bigendian = 0;
          }
          else if (!strncmp(buf, "FORM", 4)) {
              if (bytesread < 12 || strncmp(buf + 8, "AIFF", 4)) goto badheader;
!             format = FORMAT_AIFF; q.bigendian = 1;
          } else goto badheader;
!         swap = (q.bigendian != garray_ambigendian());
          if (format == FORMAT_NEXT) {  /* nextstep header */
              if (bytesread < (int)sizeof(t_nextstep)) goto badheader;
!             q.nchannels = swap4(((t_nextstep *)buf)->nchans, swap);
              format = swap4(((t_nextstep *)buf)->format, swap);
              headersize = swap4(((t_nextstep *)buf)->onset, swap);
!             if      (format == NS_FORMAT_LINEAR_16) q.bytespersample = 2;
!             else if (format == NS_FORMAT_LINEAR_24) q.bytespersample = 3;
!             else if (format == NS_FORMAT_FLOAT)     q.bytespersample = 4;
              else goto badheader;
!             q.bytelimit = 0x7fffffff;
          } else if (format == FORMAT_WAVE) {    /* wave header */
              /* This is awful.  You have to skip over chunks,
***************
*** 241,246 ****
              /* First we guess a number of channels, etc., in case there's
                 no "fmt" chunk to follow. */
!             nchannels = 1;
!             bytespersample = 2;
              /* copy the first chunk header to beginnning of buffer. */
              memcpy(buf, buf + headersize, sizeof(t_wavechunk));
--- 242,247 ----
              /* First we guess a number of channels, etc., in case there's
                 no "fmt" chunk to follow. */
!             q.nchannels = 1;
!             q.bytespersample = 2;
              /* copy the first chunk header to beginnning of buffer. */
              memcpy(buf, buf + headersize, sizeof(t_wavechunk));
***************
*** 253,261 ****
                      if (seekout != commblockonset) goto badheader;
                      if (read(fd, buf, sizeof(t_fmt)) < (int) sizeof(t_fmt)) goto badheader;
!                     nchannels = swap2(((t_fmt *)buf)->nchannels, swap);
                      format = swap2(((t_fmt *)buf)->nbitspersample, swap);
!                     if (format == 16)      bytespersample = 2;
!                     else if (format == 24) bytespersample = 3;
!                     else if (format == 32) bytespersample = 4;
                      else goto badheader;
                  }
--- 254,262 ----
                      if (seekout != commblockonset) goto badheader;
                      if (read(fd, buf, sizeof(t_fmt)) < (int) sizeof(t_fmt)) goto badheader;
!                     q.nchannels = swap2(((t_fmt *)buf)->nchannels, swap);
                      format = swap2(((t_fmt *)buf)->nbitspersample, swap);
!                     if (format == 16)      q.bytespersample = 2;
!                     else if (format == 24) q.bytespersample = 3;
!                     else if (format == 32) q.bytespersample = 4;
                      else goto badheader;
                  }
***************
*** 265,269 ****
                  headersize = seekto;
              }
!             bytelimit = swap4(((t_wavechunk *)buf)->size, swap);
              headersize += 8;
          } else {
--- 266,270 ----
                  headersize = seekto;
              }
!             q.bytelimit = swap4(((t_wavechunk *)buf)->size, swap);
              headersize += 8;
          } else {
***************
*** 272,277 ****
              if (bytesread < 20) goto badheader;
              /* First we guess a number of channels, etc., in case there's no COMM block to follow. */
!             nchannels = 1;
!             bytespersample = 2;
              /* copy the first chunk header to beginnning of buffer. */
              memcpy(buf, buf + headersize, sizeof(t_datachunk));
--- 273,278 ----
              if (bytesread < 20) goto badheader;
              /* First we guess a number of channels, etc., in case there's no COMM block to follow. */
!             q.nchannels = 1;
!             q.bytespersample = 2;
              /* copy the first chunk header to beginnning of buffer. */
              memcpy(buf, buf + headersize, sizeof(t_datachunk));
***************
*** 284,291 ****
                      if (seekout != commblockonset) goto badheader;
                      if (read(fd, buf, sizeof(t_comm)) < (int) sizeof(t_comm)) goto badheader;
!                     nchannels = swap2(((t_comm *)buf)->nchannels, swap);
                      format = swap2(((t_comm *)buf)->bitspersamp, swap);
!                     if (format == 16)      bytespersample = 2;
!                     else if (format == 24) bytespersample = 3;
                      else goto badheader;
                  }
--- 285,292 ----
                      if (seekout != commblockonset) goto badheader;
                      if (read(fd, buf, sizeof(t_comm)) < (int) sizeof(t_comm)) goto badheader;
!                     q.nchannels = swap2(((t_comm *)buf)->nchannels, swap);
                      format = swap2(((t_comm *)buf)->bitspersamp, swap);
!                     if      (format == 16) q.bytespersample = 2;
!                     else if (format == 24) q.bytespersample = 3;
                      else goto badheader;
                  }
***************
*** 295,312 ****
                  headersize = seekto;
              }
!             bytelimit = swap4(((t_datachunk *)buf)->size, swap);
              headersize += 8;
          }
      }
      /* seek past header and any sample frames to skip */
!     sysrtn = lseek(fd, nchannels * bytespersample * skipframes + headersize, 0);
!     if (sysrtn != nchannels * bytespersample * skipframes + headersize) return -1;
!     bytelimit -= nchannels * bytespersample * skipframes;
!     if (bytelimit < 0) bytelimit = 0;
      /* copy sample format back to caller */
!     p->bigendian    = bigendian;
!     p->nchannels    = nchannels;
!     p->bytespersample = bytespersample;
!     p->bytelimit    = bytelimit;
      return fd;
  badheader:
--- 296,313 ----
                  headersize = seekto;
              }
!             q.bytelimit = swap4(((t_datachunk *)buf)->size, swap);
              headersize += 8;
          }
      }
      /* seek past header and any sample frames to skip */
!     sysrtn = lseek(fd, q.bytesperchannel() * skipframes + headersize, 0);
!     if (sysrtn != q.bytesperchannel() * skipframes + headersize) return -1;
!     q.bytelimit -= q.bytesperchannel() * skipframes;
!     if (q.bytelimit < 0) q.bytelimit = 0;
      /* copy sample format back to caller */
!     p->bigendian      = q.bigendian;
!     p->nchannels      = q.nchannels;
!     p->bytespersample = q.bytespersample;
!     p->bytelimit      = q.bytelimit;
      return fd;
  badheader:
***************
*** 2000,2006 ****
      x->fileerror = 0;
      x->state = STATE_STARTUP;
!     if (samplerate > 0) x->samplerate = samplerate;
!     else if (x->insamplerate > 0) x->samplerate = x->insamplerate;
!     else x->samplerate = sys_getsr();
      /* set fifosize from bufsize.  fifosize must be a multiple of the number of bytes eaten for each DSP tick.  */
      x->fifosize = x->bufsize - x->bufsize % (x->p.bytesperchannel() * MAXVECSIZE);
--- 2001,2005 ----
      x->fileerror = 0;
      x->state = STATE_STARTUP;
!     x->samplerate = samplerate>0 ? samplerate : x->insamplerate>0 ? x->insamplerate : sys_getsr();
      /* set fifosize from bufsize.  fifosize must be a multiple of the number of bytes eaten for each DSP tick.  */
      x->fifosize = x->bufsize - x->bufsize % (x->p.bytesperchannel() * MAXVECSIZE);





More information about the Pd-cvs mailing list