aboutsummaryrefslogtreecommitdiff
path: root/pd/src/d_soundfile.c
diff options
context:
space:
mode:
authorMiller Puckette <millerpuckette@users.sourceforge.net>2005-08-19 23:28:03 +0000
committerMiller Puckette <millerpuckette@users.sourceforge.net>2005-08-19 23:28:03 +0000
commitd6a71adae7c90224e2a49f0edcd4fd52fa0a1b30 (patch)
tree3ff96fa9bd7aceaeb5c832c097788c80a98bee17 /pd/src/d_soundfile.c
parent8892fb6aabcbfd2c4695c154c22751b5fe5c9004 (diff)
Version 0.39-0test5. Bug fixes and more care about closing dirty windows
and quitting. svn path=/trunk/; revision=3434
Diffstat (limited to 'pd/src/d_soundfile.c')
-rw-r--r--pd/src/d_soundfile.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/pd/src/d_soundfile.c b/pd/src/d_soundfile.c
index 07e0635b..0ec2c2af 100644
--- a/pd/src/d_soundfile.c
+++ b/pd/src/d_soundfile.c
@@ -1976,13 +1976,34 @@ static void *writesf_child_main(void *zz)
x->x_requestcode = REQUEST_BUSY;
x->x_fileerror = 0;
- /* if there's already a file open, close it */
+ /* if there's already a file open, close it. This
+ should never happen since writesf_open() calls stop if
+ needed and then waits until we're idle. */
if (x->x_fd >= 0)
{
+ int bytesperframe = x->x_bytespersample * x->x_sfchannels;
+ int bigendian = x->x_bigendian;
+ char *filename = x->x_filename;
+ int fd = x->x_fd;
+ int filetype = x->x_filetype;
+ int itemswritten = x->x_itemswritten;
+ int swap = x->x_swap;
pthread_mutex_unlock(&x->x_mutex);
- close (x->x_fd);
+
+ soundfile_finishwrite(x, filename, fd,
+ filetype, 0x7fffffff, itemswritten,
+ bytesperframe, swap);
+ close (fd);
+
pthread_mutex_lock(&x->x_mutex);
x->x_fd = -1;
+#ifdef DEBUG_SOUNDFILE
+ {
+ char s[1000];
+ sprintf(s, "bug??? ditched %d\n", itemswritten);
+ pute(s);
+ }
+#endif
if (x->x_requestcode != REQUEST_BUSY)
continue;
}
@@ -2087,9 +2108,9 @@ static void *writesf_child_main(void *zz)
}
x->x_itemswritten +=
sysrtn / (x->x_bytespersample * x->x_sfchannels);
- sprintf(boo, "after: head %d, tail %d\n",
- x->x_fifohead, x->x_fifotail);
#ifdef DEBUG_SOUNDFILE
+ sprintf(boo, "after: head %d, tail %d written %d\n",
+ x->x_fifohead, x->x_fifotail, x->x_itemswritten);
pute(boo);
#endif
/* signal parent in case it's waiting for data */
@@ -2263,6 +2284,10 @@ static void writesf_open(t_writesf *x, t_symbol *s, int argc, t_atom *argv)
int filetype, bytespersamp, swap, bigendian, normalize;
long onset, nframes;
float samplerate;
+ if (x->x_state != STATE_IDLE)
+ {
+ writesf_stop(x);
+ }
if (soundfiler_writeargparse(x, &argc,
&argv, &filesym, &filetype, &bytespersamp, &swap, &bigendian,
&normalize, &onset, &nframes, &samplerate))
@@ -2276,6 +2301,11 @@ static void writesf_open(t_writesf *x, t_symbol *s, int argc, t_atom *argv)
if (argc)
pd_error(x, "extra argument(s) to writesf~: ignored");
pthread_mutex_lock(&x->x_mutex);
+ while (x->x_requestcode != REQUEST_NOTHING)
+ {
+ sfread_cond_signal(&x->x_requestcondition);
+ sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
+ }
x->x_bytespersample = bytespersamp;
x->x_swap = swap;
x->x_bigendian = bigendian;