Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25613
Modified Files: Tag: desiredata d_soundfile.c Log Message: using more t_param
Index: d_soundfile.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v retrieving revision 1.4.4.11.2.10.2.24 retrieving revision 1.4.4.11.2.10.2.25 diff -C2 -d -r1.4.4.11.2.10.2.24 -r1.4.4.11.2.10.2.25 *** d_soundfile.c 20 Jul 2007 04:21:36 -0000 1.4.4.11.2.10.2.24 --- d_soundfile.c 20 Jul 2007 04:39:56 -0000 1.4.4.11.2.10.2.25 *************** *** 145,148 **** --- 145,149 ---- int nchannels; long bytelimit; + int bytesperchannel() {return bytespersample * nchannels;} };
*************** *** 1433,1442 **** int fileerror; /* slot for "errno" return */ int skipheaderbytes; /* size of header we'll skip */ ! int bytespersample; /* bytes per sample (2 or 3) */ ! int bigendian; /* true if file is big-endian */ ! int sfchannels; /* number of channels in soundfile */ float samplerate; /* sample rate of soundfile */ long onsetframes; /* number of sample frames to skip */ - long bytelimit; /* max number of data bytes to read */ int fd; /* filedesc */ int fifosize; /* buffer size appropriately rounded down */ --- 1434,1440 ---- int fileerror; /* slot for "errno" return */ int skipheaderbytes; /* size of header we'll skip */ ! t_param p; float samplerate; /* sample rate of soundfile */ long onsetframes; /* number of sample frames to skip */ int fd; /* filedesc */ int fifosize; /* buffer size appropriately rounded down */ *************** *** 1495,1503 **** p.bytelimit = 0x7fffffff; int skipheaderbytes = x->skipheaderbytes; ! p.bytespersample = x->bytespersample; ! int sfchannels = x->sfchannels; ! p.bigendian = x->bigendian; ! char *filename = x->filename; ! char *dirname = canvas_getdir(x->canvas)->name; /* alter the request code so that an ensuing "open" will get noticed. */ x->requestcode = REQUEST_BUSY; --- 1493,1498 ---- p.bytelimit = 0x7fffffff; int skipheaderbytes = x->skipheaderbytes; ! p.bytespersample = x->p.bytespersample; ! p.bigendian = x->p.bigendian; /* alter the request code so that an ensuing "open" will get noticed. */ x->requestcode = REQUEST_BUSY; *************** *** 1514,1524 **** /* open the soundfile with the mutex unlocked */ pthread_mutex_unlock(&x->mutex); ! fd = open_soundfile(dirname, filename, skipheaderbytes, &p, onsetframes); pthread_mutex_lock(&x->mutex); /* copy back into the instance structure. */ ! x->bytespersample = p.bytespersample; ! x->sfchannels = sfchannels; ! x->bigendian = p.bigendian; ! x->bytelimit = p.bytelimit; x->fd = fd; if (fd < 0) { --- 1509,1516 ---- /* open the soundfile with the mutex unlocked */ pthread_mutex_unlock(&x->mutex); ! fd = open_soundfile(canvas_getdir(x->canvas)->name, x->filename, skipheaderbytes, &p, onsetframes); pthread_mutex_lock(&x->mutex); /* copy back into the instance structure. */ ! x->p = p; x->fd = fd; if (fd < 0) { *************** *** 1533,1539 **** tick. We pessimistically assume MAXVECSIZE samples per tick since that could change. There could be a problem here if the vector size increases while a soundfile is being played... */ ! x->fifosize = x->bufsize - (x->bufsize % (x->bytespersample * x->sfchannels * MAXVECSIZE)); /* arrange for the "request" condition to be signalled 16 times per buffer */ ! x->sigcountdown = x->sigperiod = x->fifosize / (16 * x->bytespersample * x->sfchannels * x->vecsize); /* in a loop, wait for the fifo to get hungry and feed it */ while (x->requestcode == REQUEST_BUSY) { --- 1525,1531 ---- tick. We pessimistically assume MAXVECSIZE samples per tick since that could change. There could be a problem here if the vector size increases while a soundfile is being played... */ ! x->fifosize = x->bufsize - (x->bufsize % (x->p.bytesperchannel() * MAXVECSIZE)); /* arrange for the "request" condition to be signalled 16 times per buffer */ ! x->sigcountdown = x->sigperiod = x->fifosize / (16 * x->p.bytesperchannel() * x->vecsize); /* in a loop, wait for the fifo to get hungry and feed it */ while (x->requestcode == REQUEST_BUSY) { *************** *** 1545,1549 **** which isn't allowed because you can't tell a completely full buffer from an empty one. */ if (x->fifotail || (fifosize - x->fifohead > READSIZE)) { ! wantbytes = min(min(fifosize - x->fifohead, READSIZE),(int)x->bytelimit); } else { sfread_cond_signal(&x->answercondition); --- 1537,1541 ---- which isn't allowed because you can't tell a completely full buffer from an empty one. */ if (x->fifotail || (fifosize - x->fifohead > READSIZE)) { ! wantbytes = min(min(fifosize - x->fifohead, READSIZE),(int)x->p.bytelimit); } else { sfread_cond_signal(&x->answercondition); *************** *** 1559,1564 **** continue; } else wantbytes = READSIZE; ! if (wantbytes > x->bytelimit) ! wantbytes = x->bytelimit; } fd = x->fd; --- 1551,1555 ---- continue; } else wantbytes = READSIZE; ! wantbytes = min(wantbytes,(int)x->p.bytelimit); } fd = x->fd; *************** *** 1573,1578 **** else { x->fifohead += sysrtn; ! x->bytelimit -= sysrtn; ! if (x->bytelimit <= 0) {x->eof = 1; break;} if (x->fifohead == fifosize) x->fifohead = 0; } --- 1564,1569 ---- else { x->fifohead += sysrtn; ! x->p.bytelimit -= sysrtn; ! if (x->p.bytelimit <= 0) {x->eof = 1; break;} if (x->fifohead == fifosize) x->fifohead = 0; } *************** *** 1632,1637 **** x->clock = clock_new(x, (t_method)readsf_tick); x->canvas = canvas_getcurrent(); ! x->bytespersample = 2; ! x->sfchannels = 1; x->fd = -1; x->buf = buf; --- 1623,1628 ---- x->clock = clock_new(x, (t_method)readsf_tick); x->canvas = canvas_getcurrent(); ! x->p.bytespersample = 2; ! x->p.nchannels = 1; x->fd = -1; x->buf = buf; *************** *** 1646,1654 **** static t_int *readsf_perform(t_int *w) { t_readsf *x = (t_readsf *)(w[1]); ! int vecsize = x->vecsize, noutlets = x->noutlets, bytespersample = x->bytespersample, bigendian = x->bigendian; if (x->state == STATE_STREAM) { ! int wantbytes, sfchannels = x->sfchannels; pthread_mutex_lock(&x->mutex); ! wantbytes = sfchannels * vecsize * bytespersample; while (!x->eof && x->fifohead >= x->fifotail && x->fifohead < x->fifotail + wantbytes-1) { sfread_cond_signal(&x->requestcondition); --- 1637,1645 ---- static t_int *readsf_perform(t_int *w) { t_readsf *x = (t_readsf *)(w[1]); ! int vecsize = x->vecsize, noutlets = x->noutlets; if (x->state == STATE_STREAM) { ! int wantbytes; pthread_mutex_lock(&x->mutex); ! wantbytes = vecsize * x->p.bytesperchannel(); while (!x->eof && x->fifohead >= x->fifotail && x->fifohead < x->fifotail + wantbytes-1) { sfread_cond_signal(&x->requestcondition); *************** *** 1662,1669 **** x->state = STATE_IDLE; /* if there's a partial buffer left, copy it out. */ ! int xfersize = (x->fifohead - x->fifotail + 1) / (sfchannels * bytespersample); if (xfersize) { ! soundfile_xferin(sfchannels, noutlets, x->outvec, 0, ! (unsigned char *)(x->buf + x->fifotail), xfersize, bytespersample, bigendian); vecsize -= xfersize; } --- 1653,1660 ---- x->state = STATE_IDLE; /* if there's a partial buffer left, copy it out. */ ! int xfersize = (x->fifohead - x->fifotail + 1) / x->p.bytesperchannel(); if (xfersize) { ! soundfile_xferin(x->p.nchannels, noutlets, x->outvec, 0, ! (unsigned char *)(x->buf + x->fifotail), xfersize, x->p.bytespersample, x->p.bigendian); vecsize -= xfersize; } *************** *** 1677,1681 **** 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; --- 1668,1672 ---- return w+2; } ! soundfile_xferin(x->p.nchannels, noutlets, x->outvec, 0, (unsigned char *)(x->buf + x->fifotail), vecsize, x->p.bytespersample, x->p.bigendian); x->fifotail += wantbytes; if (x->fifotail >= x->fifosize) x->fifotail = 0; *************** *** 1714,1721 **** }
! /* open method. Called as: ! open filename [skipframes headersize channels bytespersample endianness] ! (if headersize is zero, header is taken to be automatically ! detected; thus, use the special "-1" to mean a truly headerless file.) */ static void readsf_open(t_readsf *x, t_symbol *s, int argc, t_atom *argv) { t_symbol *filesym = atom_getsymbolarg(0, argc, argv); --- 1705,1710 ---- }
! /* open method. Called as: open filename [skipframes headersize channels bytespersample endianness] ! (if headersize is zero, header is taken to be automatically detected; thus, use the special "-1" to mean a truly headerless file.) */ static void readsf_open(t_readsf *x, t_symbol *s, int argc, t_atom *argv) { t_symbol *filesym = atom_getsymbolarg(0, argc, argv); *************** *** 1731,1742 **** x->fifotail = 0; x->fifohead = 0; ! if (*endian->name == 'b') x->bigendian = 1; ! else if (*endian->name == 'l') x->bigendian = 0; else if (*endian->name) error("endianness neither 'b' nor 'l'"); ! else x->bigendian = garray_ambigendian(); x->onsetframes = max(long(onsetframes),0L); x->skipheaderbytes = int(headerbytes > 0 ? headerbytes : headerbytes == 0 ? -1 : 0); ! x->sfchannels = max(int(channels),1); ! x->bytespersample = max(int(bytespersample),2); x->eof = 0; x->fileerror = 0; --- 1720,1731 ---- x->fifotail = 0; x->fifohead = 0; ! if (*endian->name == 'b') x->p.bigendian = 1; ! else if (*endian->name == 'l') x->p.bigendian = 0; else if (*endian->name) error("endianness neither 'b' nor 'l'"); ! else x->p.bigendian = garray_ambigendian(); x->onsetframes = max(long(onsetframes),0L); x->skipheaderbytes = int(headerbytes > 0 ? headerbytes : headerbytes == 0 ? -1 : 0); ! x->p.nchannels = max(int(channels),1); ! x->p.bytespersample = max(int(bytespersample),2); x->eof = 0; x->fileerror = 0; *************** *** 1750,1754 **** pthread_mutex_lock(&x->mutex); x->vecsize = sp[0]->n; ! x->sigperiod = (x->fifosize / (x->bytespersample * x->sfchannels * x->vecsize)); for (i = 0; i < noutlets; i++) x->outvec[i] = sp[i]->v; pthread_mutex_unlock(&x->mutex); --- 1739,1743 ---- pthread_mutex_lock(&x->mutex); x->vecsize = sp[0]->n; ! x->sigperiod = (x->fifosize / (x->p.bytesperchannel() * x->vecsize)); for (i = 0; i < noutlets; i++) x->outvec[i] = sp[i]->v; pthread_mutex_unlock(&x->mutex); *************** *** 1811,1817 **** int fd, sysrtn, writebytes; /* copy file stuff out of the data structure so we can relinquish the mutex while we're in open_soundfile(). */ - int bytespersample = x->bytespersample; - int sfchannels = x->sfchannels; - int bigendian = x->bigendian; int filetype = x->filetype; char *filename = x->filename; --- 1800,1803 ---- *************** *** 1824,1828 **** writesf_open() calls stop if needed and then waits until we're idle. */ if (x->fd >= 0) { ! int bytesperframe = x->bytespersample * x->sfchannels; char *filename = x->filename; int fd = x->fd; --- 1810,1814 ---- writesf_open() calls stop if needed and then waits until we're idle. */ if (x->fd >= 0) { ! int bytesperframe = x->p.bytesperchannel(); char *filename = x->filename; int fd = x->fd; *************** *** 1840,1844 **** pthread_mutex_unlock(&x->mutex); fd = create_soundfile(canvas, filename, filetype, 0, ! bytespersample, bigendian, sfchannels, garray_ambigendian() != bigendian, samplerate); pthread_mutex_lock(&x->mutex); if (fd < 0) { --- 1826,1830 ---- pthread_mutex_unlock(&x->mutex); fd = create_soundfile(canvas, filename, filetype, 0, ! x->p.bytespersample, x->p.bigendian, x->p.nchannels, garray_ambigendian() != x->p.bigendian, samplerate); pthread_mutex_lock(&x->mutex); if (fd < 0) { *************** *** 1854,1858 **** x->fifotail = 0; x->itemswritten = 0; ! x->swap = garray_ambigendian() != bigendian; /* in a loop, wait for the fifo to have data and write it to disk */ while (x->requestcode == REQUEST_BUSY || (x->requestcode == REQUEST_CLOSE && x->fifohead != x->fifotail)) { --- 1840,1844 ---- x->fifotail = 0; x->itemswritten = 0; ! x->swap = garray_ambigendian() != x->p.bigendian; /* in a loop, wait for the fifo to have data and write it to disk */ while (x->requestcode == REQUEST_BUSY || (x->requestcode == REQUEST_CLOSE && x->fifohead != x->fifotail)) { *************** *** 1883,1893 **** if (x->fifotail == fifosize) x->fifotail = 0; } ! x->itemswritten += sysrtn / (x->bytespersample * x->sfchannels); ! /* signal parent in case it's waiting for data */ sfread_cond_signal(&x->answercondition); } } else if (x->requestcode == REQUEST_CLOSE || x->requestcode == REQUEST_QUIT) { if (x->fd >= 0) { ! int bytesperframe = x->bytespersample * x->sfchannels; char *filename = x->filename; int fd = x->fd; --- 1869,1879 ---- if (x->fifotail == fifosize) x->fifotail = 0; } ! x->itemswritten += sysrtn / x->p.bytesperchannel(); ! /* signal parent in case it's waiting for data */ sfread_cond_signal(&x->answercondition); } } else if (x->requestcode == REQUEST_CLOSE || x->requestcode == REQUEST_QUIT) { if (x->fd >= 0) { ! int bytesperframe = x->p.bytesperchannel(); char *filename = x->filename; int fd = x->fd; *************** *** 1924,1928 **** for (i = 1; i < nchannels; i++) inlet_new(x,x, &s_signal, &s_signal); x->f = 0; ! x->sfchannels = nchannels; pthread_mutex_init(&x->mutex, 0); pthread_cond_init(&x->requestcondition, 0); --- 1910,1914 ---- for (i = 1; i < nchannels; i++) inlet_new(x,x, &s_signal, &s_signal); x->f = 0; ! x->p.nchannels = nchannels; pthread_mutex_init(&x->mutex, 0); pthread_cond_init(&x->requestcondition, 0); *************** *** 1933,1937 **** x->clock = 0; /* no callback needed here */ x->canvas = canvas_getcurrent(); ! x->bytespersample = 2; x->fd = -1; x->buf = buf; --- 1919,1923 ---- x->clock = 0; /* no callback needed here */ x->canvas = canvas_getcurrent(); ! x->p.bytespersample = 2; x->fd = -1; x->buf = buf; *************** *** 1944,1963 **** 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; pthread_mutex_lock(&x->mutex); ! wantbytes = sfchannels * vecsize * bytespersample; while (x->fifotail > x->fifohead && x->fifotail < x->fifohead + wantbytes + 1) { sfread_cond_signal(&x->requestcondition); sfread_cond_wait(&x->answercondition, &x->mutex); /* resync local cariables -- bug fix thanks to Shahrokh */ ! vecsize = x->vecsize; ! bytespersample = x->bytespersample; ! sfchannels = x->sfchannels; ! wantbytes = sfchannels * vecsize * bytespersample; ! 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; --- 1930,1944 ---- static t_int *writesf_perform(t_int *w) { t_writesf *x = (t_writesf *)(w[1]); if (x->state == STATE_STREAM) { int wantbytes; pthread_mutex_lock(&x->mutex); ! wantbytes = x->vecsize * x->p.bytesperchannel(); while (x->fifotail > x->fifohead && x->fifotail < x->fifohead + wantbytes + 1) { sfread_cond_signal(&x->requestcondition); sfread_cond_wait(&x->answercondition, &x->mutex); /* resync local cariables -- bug fix thanks to Shahrokh */ ! wantbytes = x->vecsize * x->p.bytesperchannel(); } ! soundfile_xferout(x->p.nchannels, x->outvec, (unsigned char *)(x->buf + x->fifohead), x->vecsize, 0, x->p.bytespersample, x->p.bigendian, 1.); x->fifohead += wantbytes; if (x->fifohead >= x->fifosize) x->fifohead = 0; *************** *** 2007,2013 **** sfread_cond_wait(&x->answercondition, &x->mutex); } ! x->bytespersample = bytespersample; x->swap = swap; ! x->bigendian = bigendian; x->filename = filesym->name; x->filetype = filetype; --- 1988,1994 ---- sfread_cond_wait(&x->answercondition, &x->mutex); } ! x->p.bytespersample = max(bytespersample,2); x->swap = swap; ! x->p.bigendian = bigendian; x->filename = filesym->name; x->filetype = filetype; *************** *** 2019,2030 **** x->fileerror = 0; x->state = STATE_STARTUP; - x->bytespersample = (bytespersample > 2 ? bytespersample : 2); 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->bytespersample * x->sfchannels * MAXVECSIZE); /* arrange for the "request" condition to be signalled 16 times per buffer */ ! x->sigcountdown = x->sigperiod = x->fifosize / (16 * x->bytespersample * x->sfchannels * x->vecsize); sfread_cond_signal(&x->requestcondition); pthread_mutex_unlock(&x->mutex); --- 2000,2010 ---- 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); /* arrange for the "request" condition to be signalled 16 times per buffer */ ! x->sigcountdown = x->sigperiod = x->fifosize / (16 * x->p.bytesperchannel() * x->vecsize); sfread_cond_signal(&x->requestcondition); pthread_mutex_unlock(&x->mutex); *************** *** 2032,2039 ****
static void writesf_dsp(t_writesf *x, t_signal **sp) { ! int ninlets = x->sfchannels; pthread_mutex_lock(&x->mutex); x->vecsize = sp[0]->n; ! x->sigperiod = x->fifosize / (x->bytespersample * ninlets * x->vecsize); for (int i=0; i<ninlets; i++) x->outvec[i] = sp[i]->v; x->insamplerate = sp[0]->sr; --- 2012,2019 ----
static void writesf_dsp(t_writesf *x, t_signal **sp) { ! int ninlets = x->p.nchannels; pthread_mutex_lock(&x->mutex); x->vecsize = sp[0]->n; ! x->sigperiod = x->fifosize / (x->p.bytesperchannel() * x->vecsize); for (int i=0; i<ninlets; i++) x->outvec[i] = sp[i]->v; x->insamplerate = sp[0]->sr;