aboutsummaryrefslogtreecommitdiff
path: root/modules/tabreadmix~.c
diff options
context:
space:
mode:
authorTom Schouten <doelie@users.sourceforge.net>2012-10-27 13:58:28 +0000
committerTom Schouten <doelie@users.sourceforge.net>2012-10-27 13:58:28 +0000
commit201a9e763213f555d6797d0c6cad26a533fa75a5 (patch)
tree2fb38504fe5c029d731f23d35c8db95a553d7c8e /modules/tabreadmix~.c
parent99c67991f9a3c49485bc40b05f8ce85ecd838da5 (diff)
creb: tabreadmix~ changes + build fixes + 32/64 bit fixes
svn path=/trunk/externals/creb/; revision=16491
Diffstat (limited to 'modules/tabreadmix~.c')
-rw-r--r--modules/tabreadmix~.c85
1 files changed, 70 insertions, 15 deletions
diff --git a/modules/tabreadmix~.c b/modules/tabreadmix~.c
index 74940a2..d122eea 100644
--- a/modules/tabreadmix~.c
+++ b/modules/tabreadmix~.c
@@ -1,6 +1,9 @@
/*
* tabreadmix.c - an overlap add tabread~ clone
+ *
* Copyright (c) 2000-2003 by Tom Schouten
+ * Additional code (audiorate, wrap messages) copyright (c) 2008 by
+ * Damian Stewart, damian [at] frey [dot] co [dot] nz
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,8 +35,9 @@ typedef struct _tabreadmix_tilde
t_float x_f;
/* file position vars */
- int x_currpos;
- int x_prevpos;
+ t_float x_currpos;
+ t_float x_prevpos;
+ t_float x_posinc;
/* cross fader state vars */
int x_xfade_size;
@@ -42,6 +46,12 @@ typedef struct _tabreadmix_tilde
t_float x_xfade_sin;
t_float x_xfade_state_c;
t_float x_xfade_state_s;
+
+ /* wrap start and end */
+ int x_wrap_start;
+ int x_wrap_end;
+ int x_wrap_length;
+
} t_tabreadmix_tilde;
@@ -49,22 +59,23 @@ typedef struct _tabreadmix_tilde
inline void tabreadmix_tilde_wrapindices(t_tabreadmix_tilde *x)
{
- int max;
/* modulo */
- x->x_currpos %= x->x_npoints;
- x->x_prevpos %= x->x_npoints;
+ while ( x->x_currpos > x->x_wrap_end )
+ x->x_currpos -= x->x_wrap_length;
+ while ( x->x_prevpos > x->x_wrap_end )
+ x->x_prevpos -= x->x_wrap_length;
/* make sure 0<=..<x->x_npoints */
//if (x->x_currpos < 0) x->x_currpos += x->x_npoints;
//if (x->x_prevpos < 0) x->x_prevpos += x->x_npoints;
x->x_currpos += (x->x_currpos < 0) * x->x_npoints;
x->x_prevpos += (x->x_prevpos < 0) * x->x_npoints;
-
+
+
}
-
#define min(x,y) ((x)<(y)?(x):(y))
static t_int *tabreadmix_tilde_perform(t_int *w)
@@ -82,7 +93,8 @@ static t_int *tabreadmix_tilde_perform(t_int *w)
int leftover;
int newpos = (int)*pos;
- maxxindex = x->x_npoints;
+// maxxindex = x->x_npoints;
+ maxxindex = x->x_wrap_end;
if (!buf) goto zero;
if (maxxindex <= 0) goto zero;
@@ -103,14 +115,13 @@ static t_int *tabreadmix_tilde_perform(t_int *w)
/* mix and write */
newpos = (int)(*pos++);
- *out++ = currgain * buf[x->x_currpos++]
- + prevgain * buf[x->x_prevpos++];
+ *out++ = currgain * buf[(int)x->x_currpos] + prevgain * buf[(int)x->x_prevpos];
+ x->x_currpos += x->x_posinc;
+ x->x_prevpos += x->x_posinc;
/* advance oscillator */
- c = x->x_xfade_state_c * x->x_xfade_cos
- - x->x_xfade_state_s * x->x_xfade_sin;
- s = x->x_xfade_state_c * x->x_xfade_sin
- + x->x_xfade_state_s * x->x_xfade_cos;
+ c = x->x_xfade_state_c * x->x_xfade_cos - x->x_xfade_state_s * x->x_xfade_sin;
+ s = x->x_xfade_state_c * x->x_xfade_sin + x->x_xfade_state_s * x->x_xfade_cos;
x->x_xfade_state_c = c;
x->x_xfade_state_s = s;
}
@@ -145,9 +156,12 @@ static void tabreadmix_tilde_blocksize(t_tabreadmix_tilde *x, t_float size)
{
double prev_phase;
int max;
- t_float fmax = (t_float)x->x_npoints * 0.5;
+
+ t_float fmax = (t_float)x->x_wrap_length * 0.5;
if (size < 1.0) size = 1.0;
+// post( "got input size %f\n", size );
+
prev_phase = (double)x->x_xfade_phase;
prev_phase *= size;
@@ -175,6 +189,23 @@ static void tabreadmix_tilde_blocksize(t_tabreadmix_tilde *x, t_float size)
}
+void tabreadmix_tilde_wrap(t_tabreadmix_tilde *x, t_float start, t_float end )
+{
+ if ( start > end )
+ error( "tabreadmix~: wrap: start %i must be lower than end %i", (int)start, (int)end );
+ else if ( 0 > start || start > x->x_npoints )
+ error( "tabreadmix~: wrap: start %i must be between 0 and bufsize (%d)", (int)start, (int)x->x_npoints );
+ else if ( 0 > end || end > x->x_npoints )
+ error( "tabreadmix~: wrap: end %i must be between 0 and bufsize (%d)", (int)end, (int)x->x_npoints );
+ else
+ {
+ x->x_wrap_start = start;
+ x->x_wrap_end = end;
+ x->x_wrap_length = end - start;
+ }
+
+}
+
void tabreadmix_tilde_pitch(t_tabreadmix_tilde *x, t_float f)
{
if (f < 1) f = 1;
@@ -182,6 +213,15 @@ void tabreadmix_tilde_pitch(t_tabreadmix_tilde *x, t_float f)
tabreadmix_tilde_blocksize(x, sys_getsr() / f);
}
+
+void tabreadmix_tilde_audiorate(t_tabreadmix_tilde *x, t_float f)
+{
+ if ( f<0.001 ) f = 0.001;
+
+ x->x_posinc = f;
+}
+
+
void tabreadmix_tilde_chunks(t_tabreadmix_tilde *x, t_float f)
{
if (f < 1.0) f = 1.0;
@@ -197,6 +237,7 @@ void tabreadmix_tilde_bang(t_tabreadmix_tilde *x, t_float f)
void tabreadmix_tilde_set(t_tabreadmix_tilde *x, t_symbol *s)
{
t_garray *a;
+ int old_npoints = x->x_npoints;
x->x_arrayname = s;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
@@ -212,6 +253,14 @@ void tabreadmix_tilde_set(t_tabreadmix_tilde *x, t_symbol *s)
}
else garray_usedindsp(a);
+ // reset wrappage
+ if ( old_npoints != x->x_npoints )
+ {
+ x->x_wrap_start = 0;
+ x->x_wrap_end = x->x_npoints;
+ x->x_wrap_length = x->x_npoints;
+ }
+
/* make sure indices are inside array */
if (x->x_npoints == 0){
x->x_currpos = 0;
@@ -247,6 +296,7 @@ static void *tabreadmix_tilde_new(t_symbol *s)
x->x_xfade_size = 1024;
x->x_currpos = 0;
x->x_prevpos = 0;
+ x->x_posinc = 1.0;
x->x_xfade_state_c = 0.5;
x->x_xfade_state_s = 0.0;
tabreadmix_tilde_blocksize(x, 1024);
@@ -269,6 +319,11 @@ void tabreadmix_tilde_setup(void)
gensym("pitch"), A_FLOAT, 0);
class_addmethod(tabreadmix_tilde_class, (t_method)tabreadmix_tilde_chunks,
gensym("chunks"), A_FLOAT, 0);
+ class_addmethod(tabreadmix_tilde_class, (t_method)tabreadmix_tilde_audiorate,
+ gensym("audiorate"), A_FLOAT, 0 );
+ class_addmethod(tabreadmix_tilde_class, (t_method)tabreadmix_tilde_wrap,
+ gensym("wrap"), A_FLOAT, A_FLOAT, 0 );
class_addmethod(tabreadmix_tilde_class, (t_method)tabreadmix_tilde_bang,
gensym("bang"), 0);
+
}