[PD-cvs] pd/src d_soundfile.c, 1.4.4.11.2.10.2.26, 1.4.4.11.2.10.2.27
Mathieu Bouchard
matju at users.sourceforge.net
Fri Jul 20 07:34:15 CEST 2007
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13870
Modified Files:
Tag: desiredata
d_soundfile.c
Log Message:
THREADEDSF fixes
Index: d_soundfile.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v
retrieving revision 1.4.4.11.2.10.2.26
retrieving revision 1.4.4.11.2.10.2.27
diff -C2 -d -r1.4.4.11.2.10.2.26 -r1.4.4.11.2.10.2.27
*** d_soundfile.c 20 Jul 2007 05:08:16 -0000 1.4.4.11.2.10.2.26
--- d_soundfile.c 20 Jul 2007 05:34:13 -0000 1.4.4.11.2.10.2.27
***************
*** 760,765 ****
static t_int soundfiler_read_output(t_int *w);
static void soundfiler_t_read(t_soundfiler *x, t_symbol *s, int argc, t_atom *argv) {
! int headersize = -1, channels = 0, bytespersample = 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;
--- 760,769 ----
static t_int soundfiler_read_output(t_int *w);
static void soundfiler_t_read(t_soundfiler *x, t_symbol *s, int argc, t_atom *argv) {
! t_param p;
! int headersize = -1;
! p.nchannels = 0; p.bytespersample = 0; p.bigendian = 0;
! int resize = 0, i, j;
! long skipframes = 0, nframes = 0, finalsize = 0, maxsize = DEFMAXSIZE, itemsread = 0;
! p.bytelimit = 0x7fffffff;
int fd = -1;
char endianness, *filename;
***************
*** 783,792 ****
} else if (!strcmp(flag, "raw")) {
EAT_ARG(A_FLOAT,headersize); if (headersize<0) goto usage;
! EAT_ARG(A_FLOAT,channels); if (channels<1) goto usage;
! EAT_ARG(A_FLOAT,bytespersample); if (bytespersample<2 || bytespersample>4) goto usage;
EAT_ARG(A_SYMBOL,endianness); if (endianness!='b' && endianness!='l' && endianness!='n') goto usage;
! if (endianness == 'b') bigendian = 1;
! else if (endianness == 'l') bigendian = 0;
! else bigendian = garray_ambigendian();
} else if (!strcmp(flag, "resize")) {
resize = 1;
--- 787,796 ----
} else if (!strcmp(flag, "raw")) {
EAT_ARG(A_FLOAT,headersize); if (headersize<0) goto usage;
! EAT_ARG(A_FLOAT,p.nchannels); if (p.nchannels<1) goto usage;
! EAT_ARG(A_FLOAT,p.bytespersample); if (p.bytespersample<2 || p.bytespersample>4) goto usage;
EAT_ARG(A_SYMBOL,endianness); if (endianness!='b' && endianness!='l' && endianness!='n') goto usage;
! if (endianness == 'b') p.bigendian = 1;
! else if (endianness == 'l') p.bigendian = 0;
! else p.bigendian = garray_ambigendian();
} else if (!strcmp(flag, "resize")) {
resize = 1;
***************
*** 799,803 ****
filename = argv[0].a_symbol->name;
argc--; argv++;
! for (i = 0; i < argc; i++) {
if (argv[i].a_type != A_SYMBOL) goto usage;
garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_symbol, garray_class);
--- 803,807 ----
filename = argv[0].a_symbol->name;
argc--; argv++;
! for (int i=0; i<argc; i++) {
if (argv[i].a_type != A_SYMBOL) goto usage;
garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_symbol, garray_class);
***************
*** 813,817 ****
finalsize = vecsize[i];
}
! fd = open_soundfile(canvas_getdir(x->canvas)->name, filename, headersize, &bytespersample, &bigendian, &channels, &bytelimit, skipframes);
if (fd < 0) {
error("soundfiler_read: %s: %s", filename, (errno == EIO ? "unknown or bad header format" : strerror(errno)));
--- 817,821 ----
finalsize = vecsize[i];
}
! fd = open_soundfile(canvas_getdir(x->canvas)->name, filename, headersize, &p, skipframes);
if (fd < 0) {
error("soundfiler_read: %s: %s", filename, (errno == EIO ? "unknown or bad header format" : strerror(errno)));
***************
*** 825,843 ****
if (poswas < 0 || eofis < 0) {error("lseek failed"); goto done;}
lseek(fd, poswas, SEEK_SET);
! framesinfile = (eofis - poswas) / (channels * bytespersample);
if (framesinfile > maxsize) {
error("soundfiler_read: truncated to %d elements", maxsize);
framesinfile = maxsize;
}
! framesinfile = min(framesinfile, bytelimit / (channels * bytespersample));
finalsize = framesinfile;
}
if (!finalsize) finalsize = 0x7fffffff;
! finalsize = min(finalsize, bytelimit / (channels * bytespersample));
fp = fdopen(fd, "rb");
! bufframes = SAMPBUFSIZE / (channels * bytespersample);
if (debug) {
post("buffers: %d", argc);
! post("channels: %d", channels);
}
munlockall();
--- 829,847 ----
if (poswas < 0 || eofis < 0) {error("lseek failed"); goto done;}
lseek(fd, poswas, SEEK_SET);
! framesinfile = (eofis - poswas) / p.bytesperchannel();
if (framesinfile > maxsize) {
error("soundfiler_read: truncated to %d elements", maxsize);
framesinfile = maxsize;
}
! framesinfile = min(framesinfile, p.bytelimit / p.bytesperchannel());
finalsize = framesinfile;
}
if (!finalsize) finalsize = 0x7fffffff;
! finalsize = min(finalsize, p.bytelimit / p.bytesperchannel());
fp = fdopen(fd, "rb");
! bufframes = SAMPBUFSIZE / p.bytesperchannel();
if (debug) {
post("buffers: %d", argc);
! post("channels: %d", p.nchannels);
}
munlockall();
***************
*** 865,876 ****
}
}
! if(i > channels) memset(nvecs[i],0,vecsize[i] * sizeof(t_float));
if (debug) post("transfer soundfile");
for (itemsread = 0; itemsread < finalsize; ) {
int thisread = finalsize - itemsread;
thisread = (thisread > bufframes ? bufframes : thisread);
! nitems = fread(sampbuf, channels * bytespersample, thisread, fp);
if (nitems <= 0) break;
! soundfile_xferin(channels, argc, nvecs, itemsread, (unsigned char *)sampbuf, nitems, bytespersample, bigendian);
itemsread += nitems;
}
--- 869,880 ----
}
}
! if(i > p.nchannels) memset(nvecs[i],0,vecsize[i] * sizeof(t_float));
if (debug) post("transfer soundfile");
for (itemsread = 0; itemsread < finalsize; ) {
int thisread = finalsize - itemsread;
thisread = (thisread > bufframes ? bufframes : thisread);
! nitems = fread(sampbuf, p.bytesperchannel(), thisread, fp);
if (nitems <= 0) break;
! soundfile_xferin(p.nchannels, argc, nvecs, itemsread, (unsigned char *)sampbuf, nitems, p.bytespersample, p.bigendian);
itemsread += nitems;
}
***************
*** 916,926 ****
/* idle callback for threadsafe synchronisation */
! static t_int soundfiler_read_update_garray(t_int * w) {
! t_garray* garray = (t_garray*)w[0];
t_int nvec = w[1];
t_int finalsize = w[2];
pthread_cond_t *conditional = (pthread_cond_t*) w[3];
! garray->array.vec = (char *) nvec;
! garray->array.n = finalsize;
if (garray->usedindsp) canvas_update_dsp();
/* signal helper thread */
--- 920,931 ----
/* idle callback for threadsafe synchronisation */
! static t_int soundfiler_read_update_garray(t_int *w) {
! t_garray *garray = (t_garray*)w[0];
t_int nvec = w[1];
t_int finalsize = w[2];
pthread_cond_t *conditional = (pthread_cond_t*) w[3];
! t_array *a = garray_getarray(garray);
! a->vec = (char *) nvec;
! a->n = finalsize;
if (garray->usedindsp) canvas_update_dsp();
/* signal helper thread */
***************
*** 929,933 ****
}
! static t_int soundfiler_read_update_graphics(t_int * w) {
t_garray *garray = (t_garray*) w[0];
t_canvas *gl;
--- 934,938 ----
}
! static t_int soundfiler_read_update_graphics(t_int *w) {
t_garray *garray = (t_garray*) w[0];
t_canvas *gl;
***************
*** 1049,1058 ****
char *nvec; /* new array */
t_garray *x = (t_garray *)pd_findbyclass(argv[0].a_symbol, garray_class);
! if (!(x)) {
! error("%s: no such table", argv[0].a_symbol->name);
! goto usage;
! }
! vec = (t_float*) x->array.vec;
! was = x->array.n;
if ((argv+1)->a_type == A_FLOAT) {
n = (int) (argv+1)->a_float;
--- 1054,1061 ----
char *nvec; /* new array */
t_garray *x = (t_garray *)pd_findbyclass(argv[0].a_symbol, garray_class);
! t_array *a = garray_getarray(x);
! if (!x) {error("%s: no such table", argv[0].a_symbol->name); goto usage;}
! vec = (t_float*) a->vec;
! was = a->n;
if ((argv+1)->a_type == A_FLOAT) {
n = (int) (argv+1)->a_float;
***************
*** 1060,1081 ****
if (n == was) return;
if (n < 1) n = 1;
! elemsize = template_findbyname(x->array.a_templatesym)->t_n * sizeof(t_word);
munlockall();
if (was > n) {
! nvec = (char*)copyalignedbytes(x->array.a_vec, was * elemsize);
} else {
! nvec = getalignedbytes(n * elemsize);
! memcpy (nvec, x->array.a_vec, was * elemsize);
memset(nvec + was*elemsize, 0, (n - was) * elemsize);
}
! if (!nvec) {
! error("array resize failed: out of memory");
! mlockall(MCL_FUTURE);
! return;
! }
/* TB: we'll have to be sure that no one is accessing the array */
sys_lock();
! x->array.vec = nvec;
! x->array.n = n;
if (x->usedindsp) canvas_update_dsp();
sys_unlock();
--- 1063,1080 ----
if (n == was) return;
if (n < 1) n = 1;
! elemsize = template_findbyname(a->templatesym)->t_n * sizeof(t_word);
munlockall();
if (was > n) {
! nvec = (char *)copyalignedbytes(a->vec, was * elemsize);
} else {
! nvec = (char *)getalignedbytes(n * elemsize);
! memcpy (nvec, a->vec, was * elemsize);
memset(nvec + was*elemsize, 0, (n - was) * elemsize);
}
! if (!nvec) {error("array resize failed: out of memory"); mlockall(MCL_FUTURE); return;}
/* TB: we'll have to be sure that no one is accessing the array */
sys_lock();
! a->vec = nvec;
! a->n = n;
if (x->usedindsp) canvas_update_dsp();
sys_unlock();
***************
*** 1109,1122 ****
char *nvec; /* new array */
t_garray * x = (t_garray *)pd_findbyclass(argv[0].a_symbol, garray_class);
! if (!(x)) {
! error("%s: no such table", argv[0].a_symbol->name);
! goto usage;
! }
! vec = (t_float*) x->array.a_vec;
! size = x->array.a_n;
if ((argv+1)->a_type == A_FLOAT) {
val = (int) (argv+1)->a_float;
} else goto usage;
! elemsize = template_findbyname(x->array.a_templatesym)->t_n * sizeof(t_word);
/* allocating memory */
munlockall();
--- 1108,1119 ----
char *nvec; /* new array */
t_garray * x = (t_garray *)pd_findbyclass(argv[0].a_symbol, garray_class);
! t_array *a = garray_getarray(x);
! if (!x) {error("%s: no such table", argv[0].a_symbol->name); goto usage;}
! vec = (t_float*) a->vec;
! size = a->n;
if ((argv+1)->a_type == A_FLOAT) {
val = (int) (argv+1)->a_float;
} else goto usage;
! elemsize = template_findbyname(a->templatesym)->t_n * sizeof(t_word);
/* allocating memory */
munlockall();
***************
*** 1131,1135 ****
/* TB: we'll have to be sure that no one is accessing the array */
sys_lock();
! x->array.a_vec = nvec;
if (x->usedindsp) canvas_update_dsp();
sys_unlock();
--- 1128,1132 ----
/* TB: we'll have to be sure that no one is accessing the array */
sys_lock();
! a->vec = nvec;
if (x->usedindsp) canvas_update_dsp();
sys_unlock();
More information about the Pd-cvs
mailing list