Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10311
Modified Files: Tag: desiredata d_soundfile.c Log Message: cleanup
Index: d_soundfile.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v retrieving revision 1.4.4.11.2.10.2.12 retrieving revision 1.4.4.11.2.10.2.13 diff -C2 -d -r1.4.4.11.2.10.2.12 -r1.4.4.11.2.10.2.13 *** d_soundfile.c 9 Jul 2007 20:08:58 -0000 1.4.4.11.2.10.2.12 --- d_soundfile.c 10 Jul 2007 05:50:22 -0000 1.4.4.11.2.10.2.13 *************** *** 153,158 ****
/* this routine returns 1 if the high order byte comes at the lower ! address on our architecture (big-endianness.). It's 1 for Motorola, ! 0 for Intel: */
extern int garray_ambigendian(); --- 153,157 ----
/* this routine returns 1 if the high order byte comes at the lower ! address on our architecture (big-endianness.). It's 1 for Motorola, 0 for Intel: */
extern int garray_ambigendian(); *************** *** 187,194 **** */
! int open_soundfile_via_fd(int fd, int headersize, ! int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, ! long skipframes) ! { int nchannels, bigendian, bytespersamp, swap, sysrtn; long bytelimit = 0x7fffffff; --- 186,191 ---- */
! int open_soundfile_via_fd(int fd, int headersize, int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, ! long skipframes) { int nchannels, bigendian, bytespersamp, swap, sysrtn; long bytelimit = 0x7fffffff; *************** *** 241,246 **** /* read chunks in loop until we get to the data chunk */ while (strncmp(((t_wavechunk *)buf)->id, "data", 4)) { ! long chunksize = swap4(((t_wavechunk *)buf)->size, swap), ! seekto = headersize + chunksize + 8, seekout; if (!strncmp(((t_wavechunk *)buf)->id, "fmt ", 4)) { long commblockonset = headersize + 8; --- 238,242 ---- /* read chunks in loop until we get to the data chunk */ while (strncmp(((t_wavechunk *)buf)->id, "data", 4)) { ! long chunksize = swap4(((t_wavechunk *)buf)->size, swap), seekto = headersize + chunksize + 8, seekout; if (!strncmp(((t_wavechunk *)buf)->id, "fmt ", 4)) { long commblockonset = headersize + 8; *************** *** 393,403 **** arguments shouldn't be set but the calling routine flags this. */ static int soundfiler_writeargparse(void *obj, int *p_argc, t_atom **p_argv, t_symbol **p_filesym, ! int *p_filetype, int *p_bytespersamp, int *p_swap, int *p_bigendian, ! int *p_normalize, long *p_onset, long *p_nframes, float *p_rate) ! { int argc = *p_argc; t_atom *argv = *p_argv; ! int bytespersamp = 2, bigendian = 0, ! endianness = -1, swap, filetype = -1, normalize = 0; long onset = 0, nframes = 0x7fffffff; t_symbol *filesym; --- 389,397 ---- arguments shouldn't be set but the calling routine flags this. */ static int soundfiler_writeargparse(void *obj, int *p_argc, t_atom **p_argv, t_symbol **p_filesym, ! int *p_filetype, int *p_bytespersamp, int *p_swap, int *p_bigendian, ! int *p_normalize, long *p_onset, long *p_nframes, float *p_rate) { int argc = *p_argc; t_atom *argv = *p_argv; ! int bytespersamp = 2, bigendian = 0, endianness = -1, swap, filetype = -1, normalize = 0; long onset = 0, nframes = 0x7fffffff; t_symbol *filesym; *************** *** 471,478 **** }
! static int create_soundfile(t_canvas *canvas, const char *filename, ! int filetype, int nframes, int bytespersamp, ! int bigendian, int nchannels, int swap, float samplerate) ! { char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING]; char headerbuf[WRITEHDRSIZE]; --- 465,470 ---- }
! static int create_soundfile(t_canvas *canvas, const char *filename, int filetype, int nframes, int bytespersamp, ! int bigendian, int nchannels, int swap, float samplerate) { char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING]; char headerbuf[WRITEHDRSIZE]; *************** *** 483,487 **** strncpy(filenamebuf, filename, MAXPDSTRING-10); filenamebuf[MAXPDSTRING-10] = 0; - if (filetype == FORMAT_NEXT) { if (strcasecmp(filenamebuf + strlen(filenamebuf)-4, ".snd")) strcat(filenamebuf, ".snd"); --- 475,478 ---- *************** *** 551,556 ****
static void soundfile_finishwrite(void *obj, char *filename, int fd, ! int filetype, long nframes, long itemswritten, int bytesperframe, int swap) ! { if (itemswritten < nframes) { if (nframes < 0x7fffffff) --- 542,546 ----
static void soundfile_finishwrite(void *obj, char *filename, int fd, ! int filetype, long nframes, long itemswritten, int bytesperframe, int swap) { if (itemswritten < nframes) { if (nframes < 0x7fffffff) *************** *** 590,597 **** }
! static void soundfile_xferout(int nchannels, float **vecs, ! unsigned char *buf, int nitems, long onset, int bytespersamp, ! int bigendian, float normalfactor) ! { int i, j; unsigned char *sp, *sp2; --- 580,585 ---- }
! static void soundfile_xferout(int nchannels, float **vecs, unsigned char *buf, int nitems, long onset, int bytespersamp, ! int bigendian, float normalfactor) { int i, j; unsigned char *sp, *sp2; *************** *** 883,891 **** finalsize = vecsize[i]; } ! fd = open_soundfile(canvas_getdir(x->canvas)->s_name, filename, ! headersize, &bytespersamp, &bigendian, &channels, &bytelimit, skipframes); if (fd < 0) { ! pd_error(x, "soundfiler_read: %s: %s", filename, (errno == EIO ? ! "unknown or bad header format" : strerror(errno))); goto done; } --- 871,877 ---- finalsize = vecsize[i]; } ! fd = open_soundfile(canvas_getdir(x->canvas)->s_name, filename, headersize, &bytespersamp, &bigendian, &channels, &bytelimit, skipframes); if (fd < 0) { ! pd_error(x, "soundfiler_read: %s: %s", filename, (errno == EIO ? "unknown or bad header format" : strerror(errno))); goto done; } *************** *** 952,957 **** nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); if (nitems <= 0) break; ! soundfile_xferin(channels, argc, nvecs, itemsread, ! (unsigned char *)sampbuf, nitems, bytespersamp, bigendian); itemsread += nitems; } --- 938,942 ---- nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); if (nitems <= 0) break; ! soundfile_xferin(channels, argc, nvecs, itemsread, (unsigned char *)sampbuf, nitems, bytespersamp, bigendian); itemsread += nitems; } *************** *** 1052,1058 ****
if (soundfiler_writeargparse(obj, &argc, &argv, &filesym, &filetype, ! &bytespersamp, &swap, &bigendian, &normalize, &onset, &nframes, ! &samplerate)) ! goto usage; nchannels = argc; if (nchannels < 1 || nchannels > MAXSFCHANS) goto usage; --- 1037,1042 ----
if (soundfiler_writeargparse(obj, &argc, &argv, &filesym, &filetype, ! &bytespersamp, &swap, &bigendian, &normalize, &onset, &nframes, &samplerate)) ! goto usage; nchannels = argc; if (nchannels < 1 || nchannels > MAXSFCHANS) goto usage; *************** *** 1078,1083 **** goto fail; } ! if ((fd = create_soundfile(canvas, filesym->s_name, filetype, ! nframes, bytespersamp, bigendian, nchannels, swap, samplerate)) < 0) { post("%s: %s\n", filesym->s_name, strerror(errno)); goto fail; --- 1062,1066 ---- goto fail; } ! if ((fd = create_soundfile(canvas, filesym->s_name, filetype, nframes, bytespersamp, bigendian, nchannels, swap, samplerate)) < 0) { post("%s: %s\n", filesym->s_name, strerror(errno)); goto fail; *************** *** 1095,1100 **** int thiswrite = nframes - itemswritten, nbytes; thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); ! soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite, ! onset, bytespersamp, bigendian, normfactor); nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); if (nbytes < nchannels * bytespersamp * thiswrite) { --- 1078,1082 ---- int thiswrite = nframes - itemswritten, nbytes; thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); ! soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite, onset, bytespersamp, bigendian, normfactor); nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); if (nbytes < nchannels * bytespersamp * thiswrite) { *************** *** 1107,1112 **** } if (fd >= 0) { ! soundfile_finishwrite(obj, filesym->s_name, fd, ! filetype, nframes, itemswritten, nchannels * bytespersamp, swap); close (fd); } --- 1089,1093 ---- } if (fd >= 0) { ! soundfile_finishwrite(obj, filesym->s_name, fd, filetype, nframes, itemswritten, nchannels * bytespersamp, swap); close (fd); } *************** *** 1284,1289 **** static void soundfiler_read(t_soundfiler *x, t_symbol *s, int argc, t_atom *argv) { int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0, resize = 0, i, j; ! long skipframes = 0, nframes = 0, finalsize = 0, maxsize = DEFMAXSIZE, itemsread = 0, ! bytelimit = 0x7fffffff; int fd = -1; char endianness, *filename; --- 1265,1269 ---- static void soundfiler_read(t_soundfiler *x, t_symbol *s, int argc, t_atom *argv) { int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0, resize = 0, i, j; ! long skipframes = 0, nframes = 0, finalsize = 0, maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff; int fd = -1; char endianness, *filename; *************** *** 1383,1388 **** nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); if (nitems <= 0) break; ! soundfile_xferin(channels, argc, vecs, itemsread, ! (unsigned char *)sampbuf, nitems, bytespersamp, bigendian); itemsread += nitems; } --- 1363,1367 ---- nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); if (nitems <= 0) break; ! soundfile_xferin(channels, argc, vecs, itemsread, (unsigned char *)sampbuf, nitems, bytespersamp, bigendian); itemsread += nitems; } *************** *** 1454,1459 **** goto fail; } ! if ((fd = create_soundfile(canvas, filesym->s_name, filetype, ! nframes, bytespersamp, bigendian, nchannels, swap, samplerate)) < 0) { post("%s: %s\n", filesym->s_name, strerror(errno)); goto fail; --- 1433,1437 ---- goto fail; } ! if ((fd = create_soundfile(canvas, filesym->s_name, filetype, nframes, bytespersamp, bigendian, nchannels, swap, samplerate)) < 0) { post("%s: %s\n", filesym->s_name, strerror(errno)); goto fail; *************** *** 1470,1475 **** int thiswrite = nframes - itemswritten, nbytes; thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); ! soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite, ! onset, bytespersamp, bigendian, normfactor); nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); if (nbytes < nchannels * bytespersamp * thiswrite) { --- 1448,1452 ---- int thiswrite = nframes - itemswritten, nbytes; thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); ! soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite, onset, bytespersamp, bigendian, normfactor); nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); if (nbytes < nchannels * bytespersamp * thiswrite) { *************** *** 1482,1487 **** } if (fd >= 0) { ! soundfile_finishwrite(obj, filesym->s_name, fd, ! filetype, nframes, itemswritten, nchannels * bytespersamp, swap); close (fd); } --- 1459,1463 ---- } if (fd >= 0) { ! soundfile_finishwrite(obj, filesym->s_name, fd, filetype, nframes, itemswritten, nchannels * bytespersamp, swap); close (fd); } *************** *** 1638,1643 **** x->fileerror = 0; /* if there's already a file open, close it */ ! if (x->fd >= 0) ! { fd = x->fd; pthread_mutex_unlock(&x->mutex); --- 1614,1618 ---- x->fileerror = 0; /* if there's already a file open, close it */ ! if (x->fd >= 0) { fd = x->fd; pthread_mutex_unlock(&x->mutex); *************** *** 1645,1656 **** pthread_mutex_lock(&x->mutex); x->fd = -1; ! if (x->requestcode != REQUEST_BUSY) ! goto lost; } /* open the soundfile with the mutex unlocked */ pthread_mutex_unlock(&x->mutex); ! fd = open_soundfile(dirname, filename, ! skipheaderbytes, &bytespersample, &bigendian, ! &sfchannels, &bytelimit, onsetframes); pthread_mutex_lock(&x->mutex);
--- 1620,1628 ---- pthread_mutex_lock(&x->mutex); x->fd = -1; ! if (x->requestcode != REQUEST_BUSY) goto lost; } /* open the soundfile with the mutex unlocked */ pthread_mutex_unlock(&x->mutex); ! fd = open_soundfile(dirname, filename, skipheaderbytes, &bytespersample, &bigendian, &sfchannels, &bytelimit, onsetframes); pthread_mutex_lock(&x->mutex);
*************** *** 1796,1802 **** static t_int *readsf_perform(t_int *w) { t_readsf *x = (t_readsf *)(w[1]); ! int vecsize = x->vecsize, noutlets = x->noutlets, i, j, ! bytespersample = x->bytespersample, ! bigendian = x->bigendian; float *fp; if (x->state == STATE_STREAM) { --- 1768,1772 ---- static t_int *readsf_perform(t_int *w) { t_readsf *x = (t_readsf *)(w[1]); ! int vecsize = x->vecsize, noutlets = x->noutlets, i, j, bytespersample = x->bytespersample, bigendian = x->bigendian; float *fp; if (x->state == STATE_STREAM) { *************** *** 1824,1828 **** } /* then zero out the (rest of the) output */ ! for (i = 0; i < noutlets; i++) for (j = vecsize, fp = x->outvec[i] + xfersize; j--; ) *fp++ = 0; --- 1794,1798 ---- } /* then zero out the (rest of the) output */ ! for (int i=0; i<noutlets; i++) for (j = vecsize, fp = x->outvec[i] + xfersize; j--; ) *fp++ = 0; *************** *** 1831,1836 **** return w+2; } ! soundfile_xferin(sfchannels, noutlets, x->outvec, 0, ! (unsigned char *)(x->buf + x->fifotail), vecsize, bytespersample, bigendian); x->fifotail += wantbytes; if (x->fifotail >= x->fifosize) x->fifotail = 0; --- 1801,1805 ---- return w+2; } ! soundfile_xferin(sfchannels, noutlets, x->outvec, 0, (unsigned char *)(x->buf + x->fifotail), vecsize, bytespersample, bigendian); x->fifotail += wantbytes; if (x->fifotail >= x->fifosize) x->fifotail = 0; *************** *** 1939,1944 ****
static void readsf_setup() { ! readsf_class = class_new(gensym("readsf~"), (t_newmethod)readsf_new, ! (t_method)readsf_free, sizeof(t_readsf), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(readsf_class, (t_method)readsf_float); class_addmethod(readsf_class, (t_method)readsf_start, gensym("start"), 0); --- 1908,1912 ----
static void readsf_setup() { ! readsf_class = class_new(gensym("readsf~"), (t_newmethod)readsf_new, (t_method)readsf_free, sizeof(t_readsf), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(readsf_class, (t_method)readsf_float); class_addmethod(readsf_class, (t_method)readsf_start, gensym("start"), 0); *************** *** 2022,2034 **** buffer */ if (x->fifohead < x->fifotail || x->fifohead >= x->fifotail + WRITESIZE ! || (x->requestcode == REQUEST_CLOSE && x->fifohead != x->fifotail)) ! { writebytes = (x->fifohead < x->fifotail ? fifosize : x->fifohead) - x->fifotail; ! if (writebytes > READSIZE) ! writebytes = READSIZE; } else { sfread_cond_signal(&x->answercondition); ! sfread_cond_wait(&x->requestcondition, ! &x->mutex); continue; } --- 1990,1999 ---- buffer */ if (x->fifohead < x->fifotail || x->fifohead >= x->fifotail + WRITESIZE ! || (x->requestcode == REQUEST_CLOSE && x->fifohead != x->fifotail)) { writebytes = (x->fifohead < x->fifotail ? fifosize : x->fifohead) - x->fifotail; ! if (writebytes > READSIZE) writebytes = READSIZE; } else { sfread_cond_signal(&x->answercondition); ! sfread_cond_wait(&x->requestcondition,&x->mutex); continue; } *************** *** 2107,2112 **** static t_int *writesf_perform(t_int *w) { t_writesf *x = (t_writesf *)(w[1]); ! int vecsize = x->vecsize, sfchannels = x->sfchannels, bytespersample = x->bytespersample, ! bigendian = x->bigendian; if (x->state == STATE_STREAM) { int wantbytes; --- 2072,2076 ---- static t_int *writesf_perform(t_int *w) { t_writesf *x = (t_writesf *)(w[1]); ! int vecsize = x->vecsize, sfchannels = x->sfchannels, bytespersample = x->bytespersample, bigendian = x->bigendian; if (x->state == STATE_STREAM) { int wantbytes; *************** *** 2123,2128 **** bigendian = x->bigendian; } ! soundfile_xferout(sfchannels, x->outvec, ! (unsigned char *)(x->buf + x->fifohead), vecsize, 0, bytespersample, bigendian, 1.); x->fifohead += wantbytes; if (x->fifohead >= x->fifosize) x->fifohead = 0; --- 2087,2091 ---- bigendian = x->bigendian; } ! soundfile_xferout(sfchannels, x->outvec, (unsigned char *)(x->buf + x->fifohead), vecsize, 0, bytespersample, bigendian, 1.); x->fifohead += wantbytes; if (x->fifohead >= x->fifosize) x->fifohead = 0;