Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1572
Modified Files:
Tag: devel_0_37
d_soundfile.c configure.in configure
Log Message:
finally the threaded soundfiler should be working
Index: configure
===================================================================
RCS file: /cvsroot/pure-data/pd/src/configure,v
retrieving revision 1.1.1.4.2.17
retrieving revision 1.1.1.4.2.18
diff -C2 -d -r1.1.1.4.2.17 -r1.1.1.4.2.18
*** configure 23 May 2004 19:15:52 -0000 1.1.1.4.2.17
--- configure 30 May 2004 17:18:07 -0000 1.1.1.4.2.18
***************
*** 31,35 ****
--enable-threadedgui use yves degoyon's threaded gui patch"
ac_help="$ac_help
! --enable-threadedsf use threaded soundfiler (EXPERIMENTAL)"
ac_help="$ac_help
--enable-gathreadlocks t_garray threadlocks (EXPERIMENTAL)"
--- 31,35 ----
--enable-threadedgui use yves degoyon's threaded gui patch"
ac_help="$ac_help
! --enable-threadedsf use threaded soundfiler (EXPERIMENTAL, implies --enable-gathreadlocks)"
ac_help="$ac_help
--enable-gathreadlocks t_garray threadlocks (EXPERIMENTAL)"
***************
*** 2809,2813 ****
if test "$threadedsf" == "yes";
then
! MORECFLAGS=$MORECFLAGS" -DTHREADED_SF"
fi
--- 2809,2813 ----
if test "$threadedsf" == "yes";
then
! MORECFLAGS=$MORECFLAGS" -DTHREADED_SF -DGARRAY_THREAD_LOCK -D_GNU_SOURCE"
fi
Index: d_soundfile.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v
retrieving revision 1.1.1.2.2.5
retrieving revision 1.1.1.2.2.6
diff -C2 -d -r1.1.1.2.2.5 -r1.1.1.2.2.6
*** d_soundfile.c 27 May 2004 18:27:42 -0000 1.1.1.2.2.5
--- d_soundfile.c 30 May 2004 17:18:07 -0000 1.1.1.2.2.6
***************
*** 28,31 ****
--- 28,32 ----
#include "m_pd.h"
+ #include "g_canvas.h"
#define MAXSFCHANS 64
***************
*** 873,878 ****
#define SAMPBUFSIZE 1024
- #include <string.h>
-
typedef struct _soundfiler
{
--- 874,877 ----
***************
*** 886,890 ****
#ifdef THREADED_SF
- //#define DEBUG
#include <sched.h>
--- 885,888 ----
***************
*** 935,939 ****
if ( (largv+i)->a_type == A_SYMBOL)
{
! /* we'll have to free these again!!! */
t_symbol * sym1 = getbytes(sizeof(t_symbol));
sym1->s_name = copybytes((largv+i)->a_w.w_symbol->s_name,
--- 933,937 ----
if ( (largv+i)->a_type == A_SYMBOL)
{
! /* we'll free these after they are processed */
t_symbol * sym1 = getbytes(sizeof(t_symbol));
sym1->s_name = copybytes((largv+i)->a_w.w_symbol->s_name,
***************
*** 1163,1166 ****
--- 1161,1166 ----
-resize
-maxsize <max-size>
+
+ TB: adapted for threaded use
*/
***************
*** 1170,1179 ****
int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0,
resize = 0, i, j;
! long skipframes = 0, nframes = 0, finalsize = 0, itemsleft,
! maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff;
int fd = -1;
char endianness, *filename;
t_garray *garrays[MAXSFCHANS];
! t_float *vecs[MAXSFCHANS];
char sampbuf[SAMPBUFSIZE];
int bufframes, nitems;
--- 1170,1186 ----
int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0,
resize = 0, i, j;
! long skipframes = 0,
! nframes = 0,
! finalsize = 0, /* new size */
! itemsleft,
! maxsize = DEFMAXSIZE,
! itemsread = 0,
! bytelimit = 0x7fffffff;
int fd = -1;
char endianness, *filename;
t_garray *garrays[MAXSFCHANS];
! t_float *vecs[MAXSFCHANS]; /* the old array */
! t_float *nvecs[MAXSFCHANS]; /* the new array */
! int vecsize[MAXSFCHANS]; /* the old array size */
char sampbuf[SAMPBUFSIZE];
int bufframes, nitems;
***************
*** 1243,1251 ****
for (i = 0; i < argc; i++)
{
- int vecsize;
- //syntax correct?
if (argv[i].a_type != A_SYMBOL)
goto usage;
- //find table
if (!(garrays[i] =
(t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class)))
--- 1250,1255 ----
***************
*** 1254,1266 ****
goto done;
}
! else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
error("%s: bad template for tabwrite",
argv[i].a_w.w_symbol->s_name);
! if (finalsize && finalsize != vecsize && !resize)
{
post("soundfiler_read: arrays have different lengths; resizing...");
resize = 1;
}
! finalsize = vecsize;
}
fd = open_soundfile(canvas_getdir(x->x_canvas)->s_name, filename,
--- 1258,1270 ----
goto done;
}
! else if (!garray_getfloatarray(garrays[i], &vecsize[i], &vecs[i]))
error("%s: bad template for tabwrite",
argv[i].a_w.w_symbol->s_name);
! if (finalsize && finalsize != vecsize[i] && !resize)
{
post("soundfiler_read: arrays have different lengths; resizing...");
resize = 1;
}
! finalsize = vecsize[i];
}
fd = open_soundfile(canvas_getdir(x->x_canvas)->s_name, filename,
***************
*** 1297,1318 ****
framesinfile = bytelimit / (channels * bytespersamp);
finalsize = framesinfile;
- for (i = 0; i < argc; i++)
- {
- int vecsize;
-
- sys_lock();
- garray_resize(garrays[i], finalsize);
- sys_unlock();
- /* for sanity's sake let's clear the save-in-patch flag here */
- garray_setsaveit(garrays[i], 0);
- garray_getfloatarray(garrays[i], &vecsize, &vecs[i]);
- /* if the resize failed, garray_resize reported the error */
- if (vecsize != framesinfile)
- {
- pd_error(x, "resize failed");
- goto done;
- }
- }
}
if (!finalsize) finalsize = 0x7fffffff;
--- 1301,1305 ----
***************
*** 1322,1326 ****
bufframes = SAMPBUFSIZE / (channels * bytespersamp);
! sys_lock();
for (itemsread = 0; itemsread < finalsize; )
{
--- 1309,1345 ----
bufframes = SAMPBUFSIZE / (channels * bytespersamp);
! /* allocate memory for new array */
! if (resize)
! for (i = 0; i < argc; i++)
! {
! nvecs[i]=getbytes (finalsize * sizeof(t_float));
! /* if we are out of memory, free it again and quit */
! if (nvecs[i]==0)
! {
! pd_error(x, "resize failed");
! int j;
! for (j=0; j!=i;++j)
! /* if the resizing fails, we'll have to free all arrays again */
! freebytes (nvecs[i],finalsize * sizeof(t_float));
! goto done;
! }
! }
! else
! for (i = 0; i < argc; i++)
! {
! nvecs[i] = getbytes (vecsize[i] * sizeof(t_float));
! /* if we are out of memory, free it again and quit */
! if (nvecs[i]==0)
! {
! pd_error(x, "resize failed");
! int j;
! for (j=0; j!=i;++j)
! /* if the resizing fails, we'll have to free all arrays again */
! freebytes (nvecs[i],finalsize * sizeof(t_float));
! goto done;
! }
! }
!
!
for (itemsread = 0; itemsread < finalsize; )
{
***************
*** 1329,1358 ****
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;
}
! /* zero out remaining elements of vectors */
!
for (i = 0; i < argc; i++)
{
! int nzero, vecsize;
! garray_getfloatarray(garrays[i], &vecsize, &vecs[i]);
! for (j = itemsread; j < vecsize; j++)
! vecs[i][j] = 0;
}
! /* zero out vectors in excess of number of channels */
! for (i = channels; i < argc; i++)
{
! int vecsize;
! float *foo;
! garray_getfloatarray(garrays[i], &vecsize, &foo);
! for (j = 0; j < vecsize; j++)
! foo[j] = 0;
}
! sys_unlock();
/* do all graphics updates */
for (i = 0; i < argc; i++)
! garray_redraw(garrays[i]);
fclose(fp);
fd = -1;
--- 1348,1409 ----
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;
}
!
! /* zero out vectors in excess of number of channels */
! for (i = channels; i < argc; i++)
! {
! for (j = 0; j < vecsize[i]; j++)
! nvecs[j] = 0;
! }
!
! /* zero out remaining elements of vectors */
for (i = 0; i < argc; i++)
{
! for (j = itemsread; j < finalsize; j++)
! nvecs[i][j] = 0;
}
!
! /* lock the system and reset the garrays */
! sys_lock();
! for (i = 0; i < argc; i++)
{
! #ifdef GARRAY_THREAD_LOCK
! garray_lock(garrays[i]);
! #endif
! garrays[i]->x_array.a_vec = (char *) nvecs[i];
! garrays[i]->x_array.a_n = finalsize;
! #ifdef GARRAY_THREAD_LOCK
! garray_unlock(garrays[i]);
! #endif
! if (garrays[i]->x_usedindsp) canvas_update_dsp();
! sys_unlock();
}
!
/* do all graphics updates */
for (i = 0; i < argc; i++)
! {
! t_glist *gl;
! int n = finalsize;
! /* if this is the only array in the graph,
! reset the graph's coordinates */
! gl = garrays[i]->x_glist;
! if (gl->gl_list == &garrays[i]->x_gobj && !garrays[i]->x_gobj.g_next)
! {
! vmess(&gl->gl_pd, gensym("bounds"), "ffff",
! 0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2);
! /* close any dialogs that might have the wrong info now... */
! gfxstub_deleteforkey(gl);
! }
! else garray_redraw(garrays[i]);
! }
!
! /* free the old arrays */
! for (i = 0; i < argc; i++)
! freebytes(vecs[i], vecsize[i] * sizeof(t_float));
!
!
fclose(fp);
fd = -1;
***************
*** 1501,1521 ****
! /* soundfiler_t_resize ...
! usage: resize table size ...
*/
! static void soundfiler_t_resize(t_soundfiler *x, t_symbol *s,
int argc, t_atom *argv)
{
sys_lock();
! garray_resize((t_garray *)pd_findbyclass(argv[0].a_w.w_symbol, garray_class), atom_getintarg(1,argc,argv));
sys_unlock();
! outlet_float(x->x_obj.ob_outlet, (float)atom_getintarg(1,argc,argv));
return;
usage:
! pd_error(x, "usage: read [flags] filename tablename...");
! post("flags: -skip <n> -nframes <n> -resize -maxsize <n> ...");
! post("-raw <headerbytes> <channels> <bytespersamp> <endian (b, l, or n)>.");
}
--- 1552,1648 ----
! /* TB: soundfiler_t_resize ...
! usage: resize table size
! adapted from garray_resize
*/
! static void soundfiler_t_resize(t_soundfiler *y, t_symbol *s,
int argc, t_atom *argv)
{
+
+ t_garray * x = (t_garray *)pd_findbyclass(argv[0].a_w.w_symbol, garray_class);
+
+ if (!(x))
+ {
+ pd_error(y, "%s: no such table", argv[0].a_w.w_symbol->s_name);
+ goto usage;
+ }
+
+
+ int was, elemsize; /* array contains was elements of size elemsize */
+ t_float * vec = (t_float*) x->x_array.a_vec; /* old array */
+ t_glist *gl;
+ int dspwas;
+ int n; /* resize of n elements */
+ char *nvec; /* new array */
+
+ if ((argv+1)->a_type == A_FLOAT)
+ {
+ n = (int) (argv+1)->a_w.w_float;
+ }
+ else
+ {
+ goto usage;
+ }
+
+ garray_getfloatarray(x, &was, &vec);
+
+ if (n == was)
+ {
+ return;
+ }
+
+ if (n < 1) n = 1;
+ elemsize = template_findbyname(x->x_array.a_templatesym)->t_n * sizeof(t_word);
+
+ if (was > n)
+ nvec = copybytes(x->x_array.a_vec, was * elemsize);
+ else
+ {
+ nvec = getbytes(n * elemsize);
+ memcpy (nvec, x->x_array.a_vec, was * elemsize);
+
+ /* LATER should check t_resizebytes result */
+ memset(nvec + was*elemsize,
+ 0, (n - was) * elemsize);
+ }
+ if (!nvec)
+ {
+ pd_error(x, "array resize failed: out of memory");
+ return;
+ }
+
+
+ /* TB: we'll have to be sure that no one is accessing the array */
sys_lock();
! #ifdef GARRAY_THREAD_LOCK
! garray_lock(x);
! #endif
! x->x_array.a_vec = nvec;
! x->x_array.a_n = n;
! #ifdef GARRAY_THREAD_LOCK
! garray_unlock(x);
! #endif
! if (x->x_usedindsp) canvas_update_dsp();
sys_unlock();
!
! /* if this is the only array in the graph,
! reset the graph's coordinates */
! gl = x->x_glist;
! if (gl->gl_list == &x->x_gobj && !x->x_gobj.g_next)
! {
! vmess(&gl->gl_pd, gensym("bounds"), "ffff",
! 0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2);
! /* close any dialogs that might have the wrong info now... */
! gfxstub_deleteforkey(gl);
! }
! else garray_redraw(x);
!
! freebytes (vec, was * elemsize);
! outlet_float(y->x_obj.ob_outlet, (float)atom_getintarg(1,argc,argv));
return;
usage:
! pd_error(x, "usage: resize tablename size");
}
***************
*** 1869,1883 ****
soundfiler_class = class_new(gensym("soundfiler"), (t_newmethod)soundfiler_new,
0, sizeof(t_soundfiler), 0, 0);
- class_addmethod(soundfiler_class, (t_method)soundfiler_read, gensym("read"),
- A_GIMME, 0);
- class_addmethod(soundfiler_class, (t_method)soundfiler_write,
- gensym("write"), A_GIMME, 0);
#ifdef THREADED_SF
class_addmethod(soundfiler_class, (t_method)soundfiler_t_read_addq,
! gensym("t_read"), A_GIMME, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_t_write_addq,
! gensym("t_write"), A_GIMME, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_t_resize_addq,
gensym("resize"), A_GIMME, 0);
#endif /* THREADED_SF */
}
--- 1996,2011 ----
soundfiler_class = class_new(gensym("soundfiler"), (t_newmethod)soundfiler_new,
0, sizeof(t_soundfiler), 0, 0);
#ifdef THREADED_SF
class_addmethod(soundfiler_class, (t_method)soundfiler_t_read_addq,
! gensym("read"), A_GIMME, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_t_write_addq,
! gensym("write"), A_GIMME, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_t_resize_addq,
gensym("resize"), A_GIMME, 0);
+ #else
+ class_addmethod(soundfiler_class, (t_method)soundfiler_read, gensym("read"),
+ A_GIMME, 0);
+ class_addmethod(soundfiler_class, (t_method)soundfiler_write,
+ gensym("write"), A_GIMME, 0);
#endif /* THREADED_SF */
}
Index: configure.in
===================================================================
RCS file: /cvsroot/pure-data/pd/src/configure.in,v
retrieving revision 1.1.1.4.2.17
retrieving revision 1.1.1.4.2.18
diff -C2 -d -r1.1.1.4.2.17 -r1.1.1.4.2.18
*** configure.in 23 May 2004 19:15:52 -0000 1.1.1.4.2.17
--- configure.in 30 May 2004 17:18:07 -0000 1.1.1.4.2.18
***************
*** 38,42 ****
AC_ARG_ENABLE(optimize, [ --enable-optimize enables optimized builds for: pentium4, pentium3],optimize=$enableval)
AC_ARG_ENABLE(threadedgui, [ --enable-threadedgui use yves degoyon's threaded gui patch],threadedgui=$enableval)
! AC_ARG_ENABLE(threadedsf, [ --enable-threadedsf use threaded soundfiler (EXPERIMENTAL)],threadedsf=$enableval)
AC_ARG_ENABLE(gathreadlocks, [ --enable-gathreadlocks t_garray threadlocks (EXPERIMENTAL)],gathreadlocks=$enableval)
--- 38,42 ----
AC_ARG_ENABLE(optimize, [ --enable-optimize enables optimized builds for: pentium4, pentium3],optimize=$enableval)
AC_ARG_ENABLE(threadedgui, [ --enable-threadedgui use yves degoyon's threaded gui patch],threadedgui=$enableval)
! AC_ARG_ENABLE(threadedsf, [ --enable-threadedsf use threaded soundfiler (EXPERIMENTAL, implies --enable-gathreadlocks)],threadedsf=$enableval)
AC_ARG_ENABLE(gathreadlocks, [ --enable-gathreadlocks t_garray threadlocks (EXPERIMENTAL)],gathreadlocks=$enableval)
***************
*** 190,194 ****
if test "$threadedsf" == "yes";
then
! MORECFLAGS=$MORECFLAGS" -DTHREADED_SF"
fi
--- 190,194 ----
if test "$threadedsf" == "yes";
then
! MORECFLAGS=$MORECFLAGS" -DTHREADED_SF -DGARRAY_THREAD_LOCK -D_GNU_SOURCE"
fi