Skip to content
Snippets Groups Projects
Commit 6cc1baf1 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

fix partconv crashers in bsaylor lib and add perfroutine for array errors

parent d7ce38f0
No related branches found
No related tags found
No related merge requests found
...@@ -65,6 +65,7 @@ typedef struct _partconv { ...@@ -65,6 +65,7 @@ typedef struct _partconv {
int nbins; int nbins;
int nparts; int nparts;
int ir_prepared; int ir_prepared;
int hosed; /* set if our array doesn't exist */
int pd_blocksize; int pd_blocksize;
// partitions of impulse response // partitions of impulse response
...@@ -121,6 +122,16 @@ static void partconv_deal_work(t_partconv *x) ...@@ -121,6 +122,16 @@ static void partconv_deal_work(t_partconv *x)
#include "altivec-perform.inc.c" #include "altivec-perform.inc.c"
#else #else
static t_int *partconv_perform_hosed(t_int *w)
{
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
int i;
for (i = 0; i < n; i++)
out[i] = 0;
return (w+5);
}
static t_int *partconv_perform(t_int *w) static t_int *partconv_perform(t_int *w)
{ {
t_partconv *x = (t_partconv *)(w[1]); t_partconv *x = (t_partconv *)(w[1]);
...@@ -132,7 +143,6 @@ static t_int *partconv_perform(t_int *w) ...@@ -132,7 +143,6 @@ static t_int *partconv_perform(t_int *w)
int k; // bin int k; // bin
int p; // partition int p; // partition
int endpart; int endpart;
#ifdef USE_SSE #ifdef USE_SSE
int v1; int v1;
int v2; int v2;
...@@ -148,7 +158,6 @@ static t_int *partconv_perform(t_int *w) ...@@ -148,7 +158,6 @@ static t_int *partconv_perform(t_int *w)
float *sumbuf1ptr; float *sumbuf1ptr;
float *sumbuf2ptr; float *sumbuf2ptr;
memcpy(&(x->inbuf[x->inbufpos]), in, n*sizeof(float)); // gather a block of input into input buffer memcpy(&(x->inbuf[x->inbufpos]), in, n*sizeof(float)); // gather a block of input into input buffer
x->inbufpos += n; x->inbufpos += n;
if (x->inbufpos >= x->partsize) { if (x->inbufpos >= x->partsize) {
...@@ -235,13 +244,12 @@ static t_int *partconv_perform(t_int *w) ...@@ -235,13 +244,12 @@ static t_int *partconv_perform(t_int *w)
static void partconv_free(t_partconv *x) static void partconv_free(t_partconv *x)
{ {
int i; int i;
fftwf_free(x->inbuf); fftwf_free(x->inbuf);
for (i = 0; i < x->nparts; i++) for (i = 0; i < x->nparts; i++)
fftwf_free(x->irpart_td[i]); fftwf_free(x->irpart_td[i]);
fftwf_free(x->input_td); fftwf_free(x->input_td);
fftwf_destroy_plan(x->input_plan); fftwf_destroy_plan(x->input_plan);
for (i = 0; i < x->nsumbufs; i++) { for (i = 0; i < x->nsumbufs; i++) {
fftwf_free(x->sumbufs[i].fd); fftwf_free(x->sumbufs[i].fd);
fftwf_destroy_plan(x->sumbufs[i].plan); fftwf_destroy_plan(x->sumbufs[i].plan);
} }
...@@ -259,20 +267,25 @@ static void partconv_set(t_partconv *x, t_symbol *s) ...@@ -259,20 +267,25 @@ static void partconv_set(t_partconv *x, t_symbol *s)
// get the array from pd // get the array from pd
x->arrayname = s; x->arrayname = s;
if ( ! (arrayobj = (t_garray *)pd_findbyclass(x->arrayname, garray_class))) { if ( ! (arrayobj = (t_garray *)pd_findbyclass(x->arrayname, garray_class))) {
if (*x->arrayname->s_name) { x->hosed = 1;
pd_error(x, "partconv~: %s: no such array", x->arrayname->s_name); if (x->arrayname && *x->arrayname->s_name)
return; pd_error(x, "partconv~: %s: no such array",
} x->arrayname->s_name);
else
pd_error(x, "partconv~: need an array name");
return;
} else if ( ! garray_getfloatarray(arrayobj, &arraysize, &array)) { } else if ( ! garray_getfloatarray(arrayobj, &arraysize, &array)) {
x->hosed = 1;
pd_error(x, "%s: bad template", x->arrayname->s_name); pd_error(x, "%s: bad template", x->arrayname->s_name);
return; return;
} else {
x->hosed = 0;
} }
// if the IR has already been prepared, free everything first // if the IR has already been prepared, free everything first
if (x->ir_prepared == 1) { if (x->ir_prepared == 1) {
partconv_free(x); partconv_free(x);
} }
// caculate number of partitions // caculate number of partitions
x->nparts = arraysize / x->partsize; x->nparts = arraysize / x->partsize;
if (arraysize % x->partsize != 0) if (arraysize % x->partsize != 0)
...@@ -336,8 +349,12 @@ static void partconv_dsp(t_partconv *x, t_signal **sp) ...@@ -336,8 +349,12 @@ static void partconv_dsp(t_partconv *x, t_signal **sp)
if (x->ir_prepared == 0) { if (x->ir_prepared == 0) {
partconv_set(x, x->arrayname); partconv_set(x, x->arrayname);
} }
if (x->hosed)
dsp_add(partconv_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, (t_int)sp[0]->s_n); dsp_add(partconv_perform_hosed, 4, x, sp[0]->s_vec,
sp[1]->s_vec, (t_int)sp[0]->s_n);
else
dsp_add(partconv_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec,
(t_int)sp[0]->s_n);
} }
static void *partconv_new(t_symbol *s, int argc, t_atom *argv) static void *partconv_new(t_symbol *s, int argc, t_atom *argv)
...@@ -352,11 +369,12 @@ static void *partconv_new(t_symbol *s, int argc, t_atom *argv) ...@@ -352,11 +369,12 @@ static void *partconv_new(t_symbol *s, int argc, t_atom *argv)
instantiate and get to the help patch */ instantiate and get to the help patch */
if (!argc) if (!argc)
{ {
post("partconv~: warning: no arguments given");
SETSYMBOL(sane_defaults, &s_); SETSYMBOL(sane_defaults, &s_);
SETFLOAT(sane_defaults+1, 2.); SETFLOAT(sane_defaults+1, 64.);
argc = 2; argc = 2;
argv = sane_defaults; argv = sane_defaults;
pd_error(x, "partconv~: no arguments given. Setting some "
"sane defaults to keep Purr Data from crashing.");
} }
else else
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment