Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1446
Modified Files:
Tag: desiredata
d_soundfile.c
Log Message:
more 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.8
retrieving revision 1.4.4.11.2.10.2.9
diff -C2 -d -r1.4.4.11.2.10.2.8 -r1.4.4.11.2.10.2.9
*** d_soundfile.c 3 Jul 2007 01:05:09 -0000 1.4.4.11.2.10.2.8
--- d_soundfile.c 3 Jul 2007 04:34:59 -0000 1.4.4.11.2.10.2.9
***************
*** 13,16 ****
--- 13,17 ----
/* threaded soundfiler by Tim Blechmann */
+ // #define THREADED_SF
#ifndef MSW
***************
*** 27,31 ****
#include <stdlib.h>
! #include "m_pd.h"
#define MAXSFCHANS 64
--- 28,35 ----
#include <stdlib.h>
! #define PD_PLUSPLUS_FACE
! #include "desire.h"
! #define a_symbol a_w.w_symbol
! #define a_float a_w.w_float
#define MAXSFCHANS 64
***************
*** 394,407 ****
t_symbol *filesym;
float rate = -1;
! while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_w.w_symbol->s_name == '-') {
! char *flag = argv->a_w.w_symbol->s_name + 1;
if (!strcmp(flag, "skip")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((onset = (long) argv[1].a_w.w_float) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "nframes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = (long) argv[1].a_w.w_float) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "bytes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((bytespersamp = (int) argv[1].a_w.w_float) < 2) || bytespersamp > 4) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "normalize")) {normalize = 1; argc -= 1; argv += 1;
--- 398,411 ----
t_symbol *filesym;
float rate = -1;
! while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_symbol->s_name == '-') {
! char *flag = argv->a_symbol->s_name + 1;
if (!strcmp(flag, "skip")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((onset = (long) argv[1].a_float) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "nframes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = (long) argv[1].a_float) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "bytes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((bytespersamp = (int) argv[1].a_float) < 2) || bytespersamp > 4) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "normalize")) {normalize = 1; argc -= 1; argv += 1;
***************
*** 412,421 ****
} else if (!strcmp(flag, "little")) {endianness = 0; argc -= 1; argv += 1;
} else if (!strcmp(flag, "r") || !strcmp(flag, "rate")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((rate = argv[1].a_w.w_float) <= 0)) goto usage;
argc -= 2; argv += 2;
} else goto usage;
}
if (!argc || argv->a_type != A_SYMBOL) goto usage;
! filesym = argv->a_w.w_symbol;
/* check if format not specified and fill in */
if (filetype < 0) {
--- 416,425 ----
} else if (!strcmp(flag, "little")) {endianness = 0; argc -= 1; argv += 1;
} else if (!strcmp(flag, "r") || !strcmp(flag, "rate")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((rate = argv[1].a_float) <= 0)) goto usage;
argc -= 2; argv += 2;
} else goto usage;
}
if (!argc || argv->a_type != A_SYMBOL) goto usage;
! filesym = argv->a_symbol;
/* check if format not specified and fill in */
if (filetype < 0) {
***************
*** 662,666 ****
static pthread_t sf_thread_id; /* id of soundfiler thread */
- static pthread_attr_t sf_attr;
struct t_sfprocess {
--- 666,669 ----
***************
*** 699,705 ****
pthread_mutex_lock(&(last_entry->mutex));
last_entry->process = process;
! last_entry->x = x;
last_entry->argc = argc;
! last_entry->argv = copybytes (argv, argc * sizeof(t_atom));
last_entry->next = NULL;
pthread_mutex_unlock(&(last_entry->mutex));
--- 702,708 ----
pthread_mutex_lock(&(last_entry->mutex));
last_entry->process = process;
! last_entry->x = (t_soundfiler *)x;
last_entry->argc = argc;
! last_entry->argv = (t_atom *)copybytes(argv, argc * sizeof(t_atom));
last_entry->next = NULL;
pthread_mutex_unlock(&(last_entry->mutex));
***************
*** 733,739 ****
/* global soundfiler thread ... sleeping until signaled */
void soundfiler_thread() {
! t_sfprocess * me;
! int i;
! t_sfprocess * next;
#ifdef DEBUG
post("soundfiler_thread ID: %d", pthread_self());
--- 736,741 ----
/* global soundfiler thread ... sleeping until signaled */
void soundfiler_thread() {
! t_sfprocess *me;
! t_sfprocess *next;
#ifdef DEBUG
post("soundfiler_thread ID: %d", pthread_self());
***************
*** 783,789 ****
int status;
// initialize queue
! soundfiler_queue = getbytes (sizeof(t_sfqueue));
! pthread_mutex_init (&soundfiler_queue->mutex,NULL);
! pthread_cond_init (&soundfiler_queue->cond,NULL);
soundfiler_queue->begin=soundfiler_queue->end=NULL;
/* pthread_mutex_unlock(&(soundfiler_queue->mutex)); */
--- 785,791 ----
int status;
// initialize queue
! soundfiler_queue = (t_sfqueue *)getbytes(sizeof(t_sfqueue));
! pthread_mutex_init(&soundfiler_queue->mutex,NULL);
! pthread_cond_init(&soundfiler_queue->cond,NULL);
soundfiler_queue->begin=soundfiler_queue->end=NULL;
/* pthread_mutex_unlock(&(soundfiler_queue->mutex)); */
***************
*** 803,807 ****
#endif /* UNIX */
//start thread
! status = pthread_create(&sf_thread_id, &sf_attr, (void *) soundfiler_thread,NULL);
if (status != 0) error("Couldn't create soundfiler thread: %d",status);
else post("global soundfiler thread launched, priority: %d", sf_param.sched_priority);
--- 805,809 ----
#endif /* UNIX */
//start thread
! status = pthread_create(&sf_thread_id, &sf_attr, (void *(*)(void *)) soundfiler_thread,NULL);
if (status != 0) error("Couldn't create soundfiler thread: %d",status);
else post("global soundfiler thread launched, priority: %d", sf_param.sched_priority);
***************
*** 838,843 ****
static void soundfiler_t_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, itemsleft, maxsize = DEFMAXSIZE, itemsread = 0,
! bytelimit = 0x7fffffff;
int fd = -1;
char endianness, *filename;
--- 840,844 ----
static void soundfiler_t_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;
***************
*** 852,872 ****
pthread_mutex_t resume_after_callback_mutex = PTHREAD_MUTEX_INITIALIZER; /* dummy */
t_int* outargs;
! while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_w.w_symbol->s_name == '-') {
! char *flag = argv->a_w.w_symbol->s_name + 1;
if (!strcmp(flag, "skip")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((skipframes = argv[1].a_w.w_float) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "nframes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = argv[1].a_w.w_float) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "raw")) {
if (argc < 5 ||
! argv[1].a_type != A_FLOAT || ((headersize = argv[1].a_w.w_float) < 0) ||
! argv[2].a_type != A_FLOAT || ((channels = argv[2].a_w.w_float) < 1) ||
(channels > MAXSFCHANS) ||
! argv[3].a_type != A_FLOAT || ((bytespersamp = argv[3].a_w.w_float) < 2) ||
(bytespersamp > 4) ||
argv[4].a_type != A_SYMBOL ||
! ((endianness = argv[4].a_w.w_symbol->s_name[0]) != 'b'
&& endianness != 'l' && endianness != 'n'))
goto usage;
--- 853,873 ----
pthread_mutex_t resume_after_callback_mutex = PTHREAD_MUTEX_INITIALIZER; /* dummy */
t_int* outargs;
! while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_symbol->s_name == '-') {
! char *flag = argv->a_symbol->s_name + 1;
if (!strcmp(flag, "skip")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((skipframes = long(argv[1].a_float)) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "nframes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = long(argv[1].a_float)) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "raw")) {
if (argc < 5 ||
! argv[1].a_type != A_FLOAT || ((headersize = int(argv[1].a_float)) < 0) ||
! argv[2].a_type != A_FLOAT || ((channels = int(argv[2].a_float)) < 1) ||
(channels > MAXSFCHANS) ||
! argv[3].a_type != A_FLOAT || ((bytespersamp = int(argv[3].a_float)) < 2) ||
(bytespersamp > 4) ||
argv[4].a_type != A_SYMBOL ||
! ((endianness = argv[4].a_symbol->s_name[0]) != 'b'
&& endianness != 'l' && endianness != 'n'))
goto usage;
***************
*** 879,883 ****
argc -= 1; argv += 1;
} else if (!strcmp(flag, "maxsize")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((maxsize = argv[1].a_w.w_float) < 0)) goto usage;
resize = 1; /* maxsize implies resize. */
argc -= 2; argv += 2;
--- 880,884 ----
argc -= 1; argv += 1;
} else if (!strcmp(flag, "maxsize")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((maxsize = long(argv[1].a_float)) < 0)) goto usage;
resize = 1; /* maxsize implies resize. */
argc -= 2; argv += 2;
***************
*** 885,898 ****
}
if (argc < 2 || argc > MAXSFCHANS + 1 || argv[0].a_type != A_SYMBOL) goto usage;
! filename = argv[0].a_w.w_symbol->s_name;
argc--; argv++;
for (i = 0; i < argc; i++) {
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) {
! pd_error(x, "%s: no such table", argv[i].a_w.w_symbol->s_name);
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...");
--- 886,899 ----
}
if (argc < 2 || argc > MAXSFCHANS + 1 || argv[0].a_type != A_SYMBOL) goto usage;
! filename = argv[0].a_symbol->s_name;
argc--; argv++;
for (i = 0; i < argc; i++) {
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_symbol, garray_class))) {
! pd_error(x, "%s: no such table", argv[i].a_symbol->s_name);
goto done;
}
else if (!garray_getfloatarray(garrays[i], &vecsize[i], &vecs[i]))
! error("%s: bad template for tabwrite", argv[i].a_symbol->s_name);
if (finalsize && finalsize != vecsize[i] && !resize) {
post("soundfiler_read: arrays have different lengths; resizing...");
***************
*** 940,944 ****
if (resize)
for (i = 0; i < argc; i++) {
! nvecs[i]=getalignedbytes (finalsize * sizeof(t_float));
/* if we are out of memory, free it again and quit */
if (nvecs[i]==0) {
--- 941,945 ----
if (resize)
for (i = 0; i < argc; i++) {
! nvecs[i] = (float *)getalignedbytes(finalsize * sizeof(t_float));
/* if we are out of memory, free it again and quit */
if (nvecs[i]==0) {
***************
*** 953,957 ****
else
for (i = 0; i < argc; i++) {
! nvecs[i] = getalignedbytes (vecsize[i] * sizeof(t_float));
/* if we are out of memory, free it again and quit */
if (nvecs[i]==0) {
--- 954,958 ----
else
for (i = 0; i < argc; i++) {
! nvecs[i] = (float *)getalignedbytes(vecsize[i] * sizeof(t_float));
/* if we are out of memory, free it again and quit */
if (nvecs[i]==0) {
***************
*** 1006,1010 ****
sys_callback(&soundfiler_read_update_graphics, w, 2);
}
- end:
/* free the old arrays */
for (i = 0; i < argc; i++) freealignedbytes(vecs[i], vecsize[i] * sizeof(t_float));
--- 1007,1010 ----
***************
*** 1024,1028 ****
#endif
outargs = (t_int*)getbytes(2*sizeof(t_int));
! outargs[0] = (t_int)x->x_obj.ob_outlet;
outargs[1] = (t_int)itemsread;
sys_callback(&soundfiler_read_output, outargs, 2);
--- 1024,1028 ----
#endif
outargs = (t_int*)getbytes(2*sizeof(t_int));
! outargs[0] = (t_int)x->outlet;
outargs[1] = (t_int)itemsread;
sys_callback(&soundfiler_read_output, outargs, 2);
***************
*** 1035,1041 ****
t_int finalsize = w[2];
pthread_cond_t * conditional = (pthread_cond_t*) w[3];
! garray->x_array.a_vec = (char *) nvec;
! garray->x_array.a_n = finalsize;
! if (garray->x_usedindsp) canvas_update_dsp();
/* signal helper thread */
pthread_cond_broadcast(conditional);
--- 1035,1041 ----
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 */
pthread_cond_broadcast(conditional);
***************
*** 1044,1049 ****
static t_int soundfiler_read_update_graphics(t_int * w) {
! t_garray* garray = (t_garray*) w[0];
! t_glist *gl;
int n = w[1];
/* if this is the only array in the graph, reset the graph's coordinates */
--- 1044,1049 ----
static t_int soundfiler_read_update_graphics(t_int * w) {
! t_garray *garray = (t_garray*) w[0];
! t_canvas *gl;
int n = w[1];
/* if this is the only array in the graph, reset the graph's coordinates */
***************
*** 1051,1058 ****
post("redraw array %p", garray);
#endif
! gl = garray->x_glist;
! if (gl->gl_list == &garray->x_gobj && !garray->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... */
} else garray_redraw(garray);
--- 1051,1057 ----
post("redraw array %p", garray);
#endif
! gl = garray->canvas;
! if (gl->list == garray && !garray->next) {
! vmess(gl, gensym("bounds"), "ffff", 0., gl->y1, double(n > 1 ? n-1 : 1), gl->y2);
/* close any dialogs that might have the wrong info now... */
} else garray_redraw(garray);
***************
*** 1073,1082 ****
call it too... not done yet though. */
long soundfiler_t_dowrite(void *obj, t_canvas *canvas, int argc, t_atom *argv) {
! int headersize, bytespersamp, bigendian, endianness, swap, filetype, normalize, i, j, nchannels;
! long onset, nframes, itemsleft, maxsize = DEFMAXSIZE, itemswritten = 0;
t_garray *garrays[MAXSFCHANS];
t_float *vecs[MAXSFCHANS];
char sampbuf[SAMPBUFSIZE];
! int bufframes, nitems;
int fd = -1;
float normfactor, biggest = 0, samplerate;
--- 1072,1081 ----
call it too... not done yet though. */
long soundfiler_t_dowrite(void *obj, t_canvas *canvas, int argc, t_atom *argv) {
! int bytespersamp, bigendian, swap, filetype, normalize, i, j, nchannels;
! long onset, nframes, itemswritten = 0;
t_garray *garrays[MAXSFCHANS];
t_float *vecs[MAXSFCHANS];
char sampbuf[SAMPBUFSIZE];
! int bufframes;
int fd = -1;
float normfactor, biggest = 0, samplerate;
***************
*** 1093,1102 ****
int vecsize;
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) {
! pd_error(obj, "%s: no such table", argv[i].a_w.w_symbol->s_name);
goto fail;
}
else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
! error("%s: bad template for tabwrite", argv[i].a_w.w_symbol->s_name);
if (nframes > vecsize - onset)
nframes = vecsize - onset;
--- 1092,1101 ----
int vecsize;
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_symbol, garray_class))) {
! pd_error(obj, "%s: no such table", argv[i].a_symbol->s_name);
goto fail;
}
else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
! error("%s: bad template for tabwrite", argv[i].a_symbol->s_name);
if (nframes > vecsize - onset)
nframes = vecsize - onset;
***************
*** 1125,1129 ****
bufframes = SAMPBUFSIZE / (nchannels * bytespersamp);
for (itemswritten = 0; itemswritten < nframes; ) {
! int thiswrite = nframes - itemswritten, nitems, nbytes;
thiswrite = (thiswrite > bufframes ? bufframes : thiswrite);
soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite,
--- 1124,1128 ----
bufframes = SAMPBUFSIZE / (nchannels * bytespersamp);
for (itemswritten = 0; itemswritten < nframes; ) {
! int thiswrite = nframes - itemswritten, nbytes;
thiswrite = (thiswrite > bufframes ? bufframes : thiswrite);
soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite,
***************
*** 1143,1147 ****
close (fd);
}
! return ((float)itemswritten);
usage:
pd_error(obj, "usage: write [flags] filename tablename...");
--- 1142,1146 ----
close (fd);
}
! return itemswritten;
usage:
pd_error(obj, "usage: write [flags] filename tablename...");
***************
*** 1157,1161 ****
long bozo = soundfiler_t_dowrite(x, x->canvas, argc, argv);
sys_lock();
! outlet_float(x->x_obj.ob_outlet, (float)bozo);
sys_lock();
}
--- 1156,1160 ----
long bozo = soundfiler_t_dowrite(x, x->canvas, argc, argv);
sys_lock();
! outlet_float(x->outlet, (float)bozo);
sys_lock();
}
***************
*** 1170,1191 ****
int was, elemsize; /* array contains was elements of size elemsize */
t_float * vec; /* old array */
! t_glist *gl;
! int dspwas;
int n; /* resize of n elements */
char *nvec; /* new array */
! 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;
}
! vec = (t_float*) x->x_array.a_vec;
! was = x->x_array.a_n;
if ((argv+1)->a_type == A_FLOAT) {
! n = (int) (argv+1)->a_w.w_float;
} else goto usage;
if (n == was) return;
if (n < 1) n = 1;
! elemsize = template_findbyname(x->x_array.a_templatesym)->t_n * sizeof(t_word);
#if (_POSIX_MEMLOCK - 0) >= 200112L
--- 1169,1189 ----
int was, elemsize; /* array contains was elements of size elemsize */
t_float * vec; /* old array */
! t_canvas *gl;
int n; /* resize of n elements */
char *nvec; /* new array */
! t_garray * x = (t_garray *)pd_findbyclass(argv[0].a_symbol, garray_class);
if (!(x)) {
! pd_error(y, "%s: no such table", argv[0].a_symbol->s_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;
} else goto usage;
if (n == was) return;
if (n < 1) n = 1;
! elemsize = template_findbyname(x->array.a_templatesym)->t_n * sizeof(t_word);
#if (_POSIX_MEMLOCK - 0) >= 200112L
***************
*** 1193,1200 ****
#endif
if (was > n) {
! nvec = (char*)copyalignedbytes(x->x_array.a_vec, was * elemsize);
} else {
nvec = getalignedbytes(n * elemsize);
! memcpy (nvec, x->x_array.a_vec, was * elemsize);
memset(nvec + was*elemsize, 0, (n - was) * elemsize);
}
--- 1191,1198 ----
#endif
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);
}
***************
*** 1209,1221 ****
/* TB: we'll have to be sure that no one is accessing the array */
sys_lock();
! x->x_array.a_vec = nvec;
! x->x_array.a_n = n;
! 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... */
} else garray_redraw(x);
--- 1207,1218 ----
/* 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();
/* if this is the only array in the graph, reset the graph's coordinates */
! gl = x->canvas;
! if (gl->list == x && !x->next) {
! vmess(gl, gensym("bounds"), "ffff", 0., gl->y1, (double)(n > 1 ? n-1 : 1), gl->y2);
/* close any dialogs that might have the wrong info now... */
} else garray_redraw(x);
***************
*** 1225,1229 ****
#endif
sys_lock();
! outlet_float(y->x_obj.ob_outlet, (float)atom_getintarg(1,argc,argv));
sys_unlock();
return;
--- 1222,1226 ----
#endif
sys_lock();
! outlet_float(y->outlet, (float)atom_getintarg(1,argc,argv));
sys_unlock();
return;
***************
*** 1241,1265 ****
int size, elemsize; /* array contains was elements of size elemsize */
t_float * vec; /* old array */
! t_glist *gl;
! int dspwas;
int val; /* value */
char *nvec; /* new array */
int i;
! 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;
}
! vec = (t_float*) x->x_array.a_vec;
! size = x->x_array.a_n;
if ((argv+1)->a_type == A_FLOAT) {
! val = (int) (argv+1)->a_w.w_float;
} else goto usage;
! elemsize = template_findbyname(x->x_array.a_templatesym)->t_n * sizeof(t_word);
/* allocating memory */
#if (_POSIX_MEMLOCK - 0) >= 200112L
munlockall();
#endif
! nvec = getalignedbytes(size * elemsize);
if (!nvec) {
pd_error(x, "array resize failed: out of memory");
--- 1238,1261 ----
int size, elemsize; /* array contains was elements of size elemsize */
t_float * vec; /* old array */
! t_canvas *gl;
int val; /* value */
char *nvec; /* new array */
int i;
! t_garray * x = (t_garray *)pd_findbyclass(argv[0].a_symbol, garray_class);
if (!(x)) {
! pd_error(y, "%s: no such table", argv[0].a_symbol->s_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 */
#if (_POSIX_MEMLOCK - 0) >= 200112L
munlockall();
#endif
! nvec = (char *)getalignedbytes(size * elemsize);
if (!nvec) {
pd_error(x, "array resize failed: out of memory");
***************
*** 1273,1284 ****
/* TB: we'll have to be sure that no one is accessing the array */
sys_lock();
! x->x_array.a_vec = nvec;
! 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)(size > 1 ? size-1 : 1), gl->gl_y2);
/* close any dialogs that might have the wrong info now... */
} else garray_redraw(x);
--- 1269,1279 ----
/* 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();
/* if this is the only array in the graph, reset the graph's coordinates */
! gl = x->canvas;
! if (gl->list == x && !x->next) {
! vmess(gl, gensym("bounds"), "ffff", 0., gl->y1, (double)(size > 1 ? size-1 : 1), gl->y2);
/* close any dialogs that might have the wrong info now... */
} else garray_redraw(x);
***************
*** 1288,1292 ****
#endif
sys_lock();
! outlet_float(y->x_obj.ob_outlet, size);
sys_unlock();
return;
--- 1283,1287 ----
#endif
sys_lock();
! outlet_float(y->outlet, size);
sys_unlock();
return;
***************
*** 1329,1349 ****
int bufframes, nitems;
FILE *fp;
! while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_w.w_symbol->s_name == '-') {
! char *flag = argv->a_w.w_symbol->s_name + 1;
if (!strcmp(flag, "skip")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((skipframes = long(argv[1].a_w.w_float)) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "nframes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = long(argv[1].a_w.w_float)) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "raw")) {
if (argc < 5 ||
! argv[1].a_type != A_FLOAT || ((headersize = int(argv[1].a_w.w_float)) < 0) ||
! argv[2].a_type != A_FLOAT || ((channels = int(argv[2].a_w.w_float)) < 1) ||
(channels > MAXSFCHANS) ||
! argv[3].a_type != A_FLOAT || ((bytespersamp = int(argv[3].a_w.w_float)) < 2) ||
(bytespersamp > 4) ||
argv[4].a_type != A_SYMBOL ||
! ((endianness = argv[4].a_w.w_symbol->s_name[0]) != 'b' && endianness != 'l' && endianness != 'n'))
goto usage;
if (endianness == 'b') bigendian = 1;
--- 1324,1344 ----
int bufframes, nitems;
FILE *fp;
! while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_symbol->s_name == '-') {
! char *flag = argv->a_symbol->s_name + 1;
if (!strcmp(flag, "skip")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((skipframes = long(argv[1].a_float)) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "nframes")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = long(argv[1].a_float)) < 0)) goto usage;
argc -= 2; argv += 2;
} else if (!strcmp(flag, "raw")) {
if (argc < 5 ||
! argv[1].a_type != A_FLOAT || ((headersize = int(argv[1].a_float)) < 0) ||
! argv[2].a_type != A_FLOAT || ((channels = int(argv[2].a_float)) < 1) ||
(channels > MAXSFCHANS) ||
! argv[3].a_type != A_FLOAT || ((bytespersamp = int(argv[3].a_float)) < 2) ||
(bytespersamp > 4) ||
argv[4].a_type != A_SYMBOL ||
! ((endianness = argv[4].a_symbol->s_name[0]) != 'b' && endianness != 'l' && endianness != 'n'))
goto usage;
if (endianness == 'b') bigendian = 1;
***************
*** 1355,1359 ****
argc -= 1; argv += 1;
} else if (!strcmp(flag, "maxsize")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((maxsize = long(argv[1].a_w.w_float)) < 0)) goto usage;
resize = 1; /* maxsize implies resize. */
argc -= 2; argv += 2;
--- 1350,1354 ----
argc -= 1; argv += 1;
} else if (!strcmp(flag, "maxsize")) {
! if (argc < 2 || argv[1].a_type != A_FLOAT || ((maxsize = long(argv[1].a_float)) < 0)) goto usage;
resize = 1; /* maxsize implies resize. */
argc -= 2; argv += 2;
***************
*** 1361,1374 ****
}
if (argc < 2 || argc > MAXSFCHANS + 1 || argv[0].a_type != A_SYMBOL) goto usage;
! filename = argv[0].a_w.w_symbol->s_name;
argc--; argv++;
for (i = 0; i < argc; i++) {
int vecsize;
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) {
! pd_error(x, "%s: no such table", argv[i].a_w.w_symbol->s_name);
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...");
--- 1356,1369 ----
}
if (argc < 2 || argc > MAXSFCHANS + 1 || argv[0].a_type != A_SYMBOL) goto usage;
! filename = argv[0].a_symbol->s_name;
argc--; argv++;
for (i = 0; i < argc; i++) {
int vecsize;
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_symbol, garray_class))) {
! pd_error(x, "%s: no such table", argv[i].a_symbol->s_name);
goto done;
} else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
! error("%s: bad template for tabwrite", argv[i].a_symbol->s_name);
if (finalsize && finalsize != vecsize && !resize) {
post("soundfiler_read: arrays have different lengths; resizing...");
***************
*** 1473,1482 ****
int vecsize;
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) {
! pd_error(obj, "%s: no such table", argv[i].a_w.w_symbol->s_name);
goto fail;
}
else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
! error("%s: bad template for tabwrite", argv[i].a_w.w_symbol->s_name);
if (nframes > vecsize - onset)
nframes = vecsize - onset;
--- 1468,1477 ----
int vecsize;
if (argv[i].a_type != A_SYMBOL) goto usage;
! if (!(garrays[i] = (t_garray *)pd_findbyclass(argv[i].a_symbol, garray_class))) {
! pd_error(obj, "%s: no such table", argv[i].a_symbol->s_name);
goto fail;
}
else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
! error("%s: bad template for tabwrite", argv[i].a_symbol->s_name);
if (nframes > vecsize - onset)
nframes = vecsize - onset;
***************
*** 1546,1550 ****
class_addmethod(soundfiler_class, (t_method)soundfiler_t_resize_addq, gensym("resize"), A_GIMME, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_t_const_addq, gensym("const"), A_GIMME, 0);
! else
class_addmethod(soundfiler_class, (t_method)soundfiler_read, gensym("read"), A_GIMME, 0);
#endif /* THREADED_SF */
--- 1541,1545 ----
class_addmethod(soundfiler_class, (t_method)soundfiler_t_resize_addq, gensym("resize"), A_GIMME, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_t_const_addq, gensym("const"), A_GIMME, 0);
! #else
class_addmethod(soundfiler_class, (t_method)soundfiler_read, gensym("read"), A_GIMME, 0);
#endif /* THREADED_SF */
***************
*** 1775,1789 ****
}
sfread_cond_signal(&x->answercondition);
! } else if (x->requestcode == REQUEST_CLOSE) {
! if (x->fd >= 0) {
! fd = x->fd;
! pthread_mutex_unlock(&x->mutex);
! close (fd);
! pthread_mutex_lock(&x->mutex);
! x->fd = -1;
! }
! if (x->requestcode == REQUEST_CLOSE) x->requestcode = REQUEST_NOTHING;
! sfread_cond_signal(&x->answercondition);
! } else if (x->requestcode == REQUEST_QUIT) {
if (x->fd >= 0) {
fd = x->fd;
--- 1770,1774 ----
}
sfread_cond_signal(&x->answercondition);
! } else if (x->requestcode == REQUEST_CLOSE || x->requestcode == REQUEST_QUIT) {
if (x->fd >= 0) {
fd = x->fd;
***************
*** 1795,1800 ****
x->requestcode = REQUEST_NOTHING;
sfread_cond_signal(&x->answercondition);
- break;
}
}
pthread_mutex_unlock(&x->mutex);
--- 1780,1785 ----
x->requestcode = REQUEST_NOTHING;
sfread_cond_signal(&x->answercondition);
}
+ if (x->requestcode == REQUEST_QUIT) break;
}
pthread_mutex_unlock(&x->mutex);
***************
*** 1952,1958 ****
int i, noutlets = x->noutlets;
pthread_mutex_lock(&x->mutex);
! x->vecsize = sp[0]->s_n;
x->sigperiod = (x->fifosize / (x->bytespersample * x->sfchannels * x->vecsize));
! for (i = 0; i < noutlets; i++) x->outvec[i] = sp[i]->s_vec;
pthread_mutex_unlock(&x->mutex);
dsp_add(readsf_perform, 1, x);
--- 1937,1943 ----
int i, noutlets = x->noutlets;
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);
dsp_add(readsf_perform, 1, x);
***************
*** 2063,2068 ****
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)) {
int fifosize = x->fifosize, fifotail;
char *buf = x->buf;
--- 2048,2052 ----
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)) {
int fifosize = x->fifosize, fifotail;
char *buf = x->buf;
***************
*** 2071,2081 ****
writing until there are at least WRITESIZE bytes in the
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;
--- 2055,2062 ----
writing until there are at least WRITESIZE bytes in the
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;
***************
*** 2095,2100 ****
else {
x->fifotail += sysrtn;
! if (x->fifotail == fifosize)
! x->fifotail = 0;
}
x->itemswritten += sysrtn / (x->bytespersample * x->sfchannels);
--- 2076,2080 ----
else {
x->fifotail += sysrtn;
! if (x->fifotail == fifosize) x->fifotail = 0;
}
x->itemswritten += sysrtn / (x->bytespersample * x->sfchannels);
***************
*** 2103,2107 ****
}
} else if (x->requestcode == REQUEST_CLOSE || x->requestcode == REQUEST_QUIT) {
- int quit = (x->requestcode == REQUEST_QUIT);
if (x->fd >= 0) {
int bytesperframe = x->bytespersample * x->sfchannels;
--- 2083,2086 ----
***************
*** 2119,2124 ****
x->requestcode = REQUEST_NOTHING;
sfread_cond_signal(&x->answercondition);
- if (quit) break;
}
}
pthread_mutex_unlock(&x->mutex);
--- 2098,2103 ----
x->requestcode = REQUEST_NOTHING;
sfread_cond_signal(&x->answercondition);
}
+ if (x->requestcode == REQUEST_QUIT) break;
}
pthread_mutex_unlock(&x->mutex);
***************
*** 2140,2144 ****
if (!buf) return 0;
x = (t_writesf *)pd_new(writesf_class);
! for (i = 1; i < nchannels; i++) inlet_new(x,&x->ob_pd, &s_signal, &s_signal);
x->f = 0;
x->sfchannels = nchannels;
--- 2119,2123 ----
if (!buf) return 0;
x = (t_writesf *)pd_new(writesf_class);
! for (i = 1; i < nchannels; i++) inlet_new(x,x, &s_signal, &s_signal);
x->f = 0;
x->sfchannels = nchannels;
***************
*** 2244,2248 ****
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);
--- 2223,2227 ----
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);
***************
*** 2252,2261 ****
static void writesf_dsp(t_writesf *x, t_signal **sp) {
! int i, ninlets = x->sfchannels;
pthread_mutex_lock(&x->mutex);
! x->vecsize = sp[0]->s_n;
! x->sigperiod = (x->fifosize / (x->bytespersample * ninlets * x->vecsize));
! for (i = 0; i < ninlets; i++) x->outvec[i] = sp[i]->s_vec;
! x->insamplerate = sp[0]->s_sr;
pthread_mutex_unlock(&x->mutex);
dsp_add(writesf_perform, 1, x);
--- 2231,2240 ----
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;
pthread_mutex_unlock(&x->mutex);
dsp_add(writesf_perform, 1, x);