aboutsummaryrefslogtreecommitdiff
path: root/src/nz~.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nz~.c')
-rw-r--r--src/nz~.c76
1 files changed, 34 insertions, 42 deletions
diff --git a/src/nz~.c b/src/nz~.c
index 0f8b249..09aa05c 100644
--- a/src/nz~.c
+++ b/src/nz~.c
@@ -1,29 +1,30 @@
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
-iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */
+iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2011 */
#include "m_pd.h"
#include "iemlib.h"
#include "iem_delay.h"
-/* -------------------------- nz_tilde~ ------------------------------ */
+/* --------------------------- nz_tilde~ ------------------------------ */
+/* --- one delwrite~and several delread~, independend of samplerate --- */
static t_class *nz_tilde_class;
typedef struct _nz_tilde
{
t_object x_obj;
- t_float *x_begmem1;
- t_float *x_begmem2;
+ t_sample *x_begmem1;
+ t_sample *x_begmem2;
int x_mallocsize;
int x_max_delay_samples;
int x_n_delays;
int x_writeindex;
int *x_del_samples;
int x_blocksize;
- t_float **x_io;
- t_float x_msi;
+ t_sample **x_io;
+ t_float x_scalar_sig_in;
} t_nz_tilde;
static void nz_tilde_list(t_nz_tilde *x, t_symbol *s, int argc, t_atom *argv)
@@ -51,12 +52,12 @@ static t_int *nz_tilde_perform(t_int *w)
t_nz_tilde *x = (t_nz_tilde *)(w[1]);
int n=(int)(w[2]);
int num_dels=x->x_n_delays;
- t_float *in;
- t_float *out;
+ t_sample *in;
+ t_sample *out;
int i, j;
- t_float *writevec1;
- t_float *writevec2;
- t_float *readvec;
+ t_sample *writevec1;
+ t_sample *writevec2;
+ t_sample *readvec;
writevec2 = x->x_begmem2 + x->x_writeindex;
writevec1 = x->x_begmem1 + x->x_writeindex;
@@ -87,12 +88,12 @@ static t_int *nz_tilde_perf8(t_int *w)
t_nz_tilde *x = (t_nz_tilde *)(w[1]);
int n=(int)(w[2]);
int num_dels=x->x_n_delays;
- t_float *in;
- t_float *out;
+ t_sample *in;
+ t_sample *out;
int i, j;
- t_float *writevec1;
- t_float *writevec2;
- t_float *readvec;
+ t_sample *writevec1;
+ t_sample *writevec2;
+ t_sample *readvec;
writevec2 = x->x_begmem2 + x->x_writeindex;
writevec1 = x->x_begmem1 + x->x_writeindex;
@@ -127,7 +128,7 @@ static t_int *nz_tilde_perf8(t_int *w)
for(j=0; j<num_dels; j++)
{
out = x->x_io[j+1];
- readvec = writevec2 - x->x_del_samples[j];
+ readvec = x->x_begmem2 + x->x_writeindex - x->x_del_samples[j];
i = n;
while(i)
{
@@ -155,40 +156,32 @@ static t_int *nz_tilde_perf8(t_int *w)
static void nz_tilde_dsp(t_nz_tilde *x, t_signal **sp)
{
int n = sp[0]->s_n;
- int i, j, max_samps, num_dels = x->x_n_delays + 1;
+ int i, max_samps, num_io = x->x_n_delays + 1;
if(!x->x_blocksize)/*first time*/
{
max_samps = x->x_max_delay_samples;
- i = max_samps / n;
- j = max_samps - i * n;
+ max_samps += ((- max_samps) & (n - 1));
+ max_samps += n;
/* allocate memory as a multiple of blocksize */
- if(j)
- max_samps = (i+1) * n;
- else
- max_samps = i * n;
-// post("malloc = %d, maxdel = %d", max_samps, x->x_max_delay_samples);
x->x_mallocsize = max_samps;
- x->x_begmem1 = (t_float *)getbytes(2 * x->x_mallocsize * sizeof(t_float));
+ x->x_begmem1 = (t_sample *)getbytes(2 * x->x_mallocsize * sizeof(t_sample));
x->x_begmem2 = x->x_begmem1 + x->x_mallocsize;
x->x_writeindex = 0;
}
else if(x->x_blocksize != n)
{
max_samps = x->x_max_delay_samples;
- i = max_samps / n;
- j = max_samps - i * n;
- if(j)
- max_samps = (i+1) * n;
- else
- max_samps = i * n;
- x->x_begmem1 = (t_float *)resizebytes(x->x_begmem1, 2*x->x_mallocsize*sizeof(t_float), 2*max_samps*sizeof(t_float));
+ max_samps += ((- max_samps) & (n - 1));
+ max_samps += n;
+ /* allocate memory as a multiple of blocksize */
+ x->x_begmem1 = (t_sample *)resizebytes(x->x_begmem1, 2*x->x_mallocsize*sizeof(t_sample), 2*max_samps*sizeof(t_sample));
x->x_mallocsize = max_samps;
x->x_begmem2 = x->x_begmem1 + x->x_mallocsize;
x->x_writeindex = 0;
}
x->x_blocksize = n;
- for(i=0; i<num_dels; i++)
+ for(i=0; i<num_io; i++)
x->x_io[i] = sp[i]->s_vec;
if(n&7)
dsp_add(nz_tilde_perform, 2, x, n);
@@ -209,35 +202,34 @@ static void *nz_tilde_new(t_floatarg n_delays, t_floatarg max_delay_samples)
max_samps = 1;
x->x_max_delay_samples = max_samps;
x->x_mallocsize = 0;
- x->x_begmem1 = (t_float *)0;
- x->x_begmem2 = (t_float *)0;
+ x->x_begmem1 = (t_sample *)0;
+ x->x_begmem2 = (t_sample *)0;
x->x_writeindex = 0;
x->x_blocksize = 0;
- x->x_io = (t_float **)getbytes((x->x_n_delays + 1) * sizeof(t_float *));
+ x->x_io = (t_sample **)getbytes((x->x_n_delays + 1) * sizeof(t_sample *));
x->x_del_samples = (int *)getbytes(x->x_n_delays * sizeof(int));
for(i=0; i<n_out; i++)
{
outlet_new(&x->x_obj, &s_signal);
x->x_del_samples[i] = 0;
}
- x->x_msi = 0.0f;
+ x->x_scalar_sig_in = (t_float)0.0;
return (x);
}
static void nz_tilde_free(t_nz_tilde *x)
{
freebytes(x->x_del_samples, x->x_n_delays * sizeof(int));
- freebytes(x->x_io, (x->x_n_delays + 1) * sizeof(t_float *));
+ freebytes(x->x_io, (x->x_n_delays + 1) * sizeof(t_sample *));
if(x->x_begmem1)
- freebytes(x->x_begmem1, 2 * x->x_mallocsize * sizeof(t_float));
+ freebytes(x->x_begmem1, 2 * x->x_mallocsize * sizeof(t_sample));
}
void nz_tilde_setup(void)
{
nz_tilde_class = class_new(gensym("nz~"), (t_newmethod)nz_tilde_new, (t_method)nz_tilde_free,
sizeof(t_nz_tilde), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(nz_tilde_class, t_nz_tilde, x_msi);
+ CLASS_MAINSIGNALIN(nz_tilde_class, t_nz_tilde, x_scalar_sig_in);
class_addlist(nz_tilde_class, (t_method)nz_tilde_list);
class_addmethod(nz_tilde_class, (t_method)nz_tilde_dsp, gensym("dsp"), 0);
-// class_sethelpsymbol(nz_tilde_class, gensym("iemhelp2/nz~-help"));
}