From ab05e3bee669e8056962fab2fc6fc0be5589c0d1 Mon Sep 17 00:00:00 2001 From: Cyrille Henry Date: Tue, 8 Jul 2008 16:21:39 +0000 Subject: add tabread6c~ svn path=/trunk/externals/nusmuk/; revision=10150 --- tab/makefile | 2 +- tab/tabosc4aa~-help.pd | 34 +++++----- tab/tabread4c~.c | 12 ++-- tab/tabread6c~-help.pd | 58 ++++++++++++++++ tab/tabread6c~.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 259 insertions(+), 22 deletions(-) create mode 100644 tab/tabread6c~-help.pd create mode 100644 tab/tabread6c~.c (limited to 'tab') diff --git a/tab/makefile b/tab/makefile index 1ae94c1..4dd12d5 100755 --- a/tab/makefile +++ b/tab/makefile @@ -57,7 +57,7 @@ SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ # ----------------------- LINUX i386 ----------------------- -pd_linux: tabosc4c~.pd_linux tabread4c~.pd_linux tabosc4cloop~.pd_linux tabosc4h~.pd_linux tabosc4l~.pd_linux tabosc4aa~.pd_linux +pd_linux: tabosc4c~.pd_linux tabosc4cloop~.pd_linux tabosc4aa~.pd_linux tabread4c~.pd_linux tabread6c~.pd_linux .SUFFIXES: .pd_linux diff --git a/tab/tabosc4aa~-help.pd b/tab/tabosc4aa~-help.pd index da9adac..1b5d0c9 100644 --- a/tab/tabosc4aa~-help.pd +++ b/tab/tabosc4aa~-help.pd @@ -1,11 +1,11 @@ -#N canvas 624 76 774 681 12; +#N canvas 635 121 774 681 12; #X floatatom 41 42 9 0 0 0 - - -; #N canvas 0 0 450 300 (subpatch) 0; #X array array99 11 float 0; #X coords 0 1 10 -1 250 200 1; #X restore 436 180 graph; #X obj 437 48 loadbang; -#X floatatom 41 -1 5 0 0 0 - - -; +#X floatatom 41 -1 5 0 135 0 - - -; #X obj 41 19 mtof; #X floatatom 77 307 0 0 0 0 - - -; #N canvas 159 26 706 447 output 0; @@ -76,7 +76,6 @@ but offer a 4 points cubic interpolation with tengent continuity. So \, in some case \, quality is better than the standart interpolation ; -#X obj 42 123 tabosc4aa~ array99; #X obj 179 122 tabosc4~ array99; #X obj 157 498 oscillo~; #X text 279 17 tabosc4~; @@ -198,10 +197,12 @@ but offer a 4 points cubic interpolation with tengent continuity. So #X restore 205 288 pd osc~; #X msg 305 230 reset \, create \, 1; #X msg 311 252 0 \, destroy; -#X obj 305 274 gemwin 60; #X msg 41 60 \$1 100; #X obj 41 83 line~; -#X connect 0 0 27 0; +#X obj 42 123 tabosc4aa~ array99; +#X obj 305 274 gemwin 20; +#X floatatom 106 4 5 0 0 0 - - -; +#X connect 0 0 25 0; #X connect 2 0 16 0; #X connect 3 0 4 0; #X connect 4 0 0 0; @@ -209,8 +210,8 @@ but offer a 4 points cubic interpolation with tengent continuity. So #X connect 6 0 5 0; #X connect 7 0 6 2; #X connect 8 0 6 0; -#X connect 8 0 20 0; -#X connect 8 0 23 0; +#X connect 8 0 19 0; +#X connect 8 0 22 0; #X connect 9 0 13 0; #X connect 10 0 9 0; #X connect 11 0 12 0; @@ -218,14 +219,15 @@ but offer a 4 points cubic interpolation with tengent continuity. So #X connect 13 0 11 0; #X connect 13 0 14 1; #X connect 14 0 6 0; -#X connect 14 0 20 0; -#X connect 14 0 23 0; +#X connect 14 0 19 0; +#X connect 14 0 22 0; #X connect 15 0 18 1; -#X connect 15 0 19 1; -#X connect 18 0 14 0; -#X connect 19 0 8 0; -#X connect 24 0 26 0; +#X connect 15 0 27 1; +#X connect 18 0 8 0; +#X connect 23 0 28 0; +#X connect 24 0 28 0; #X connect 25 0 26 0; -#X connect 27 0 28 0; -#X connect 28 0 18 0; -#X connect 28 0 19 0; +#X connect 26 0 18 0; +#X connect 26 0 27 0; +#X connect 27 0 14 0; +#X connect 29 0 4 0; diff --git a/tab/tabread4c~.c b/tab/tabread4c~.c index 41f4ff3..c4a7804 100644 --- a/tab/tabread4c~.c +++ b/tab/tabread4c~.c @@ -72,7 +72,7 @@ static t_int *tabread4c_tilde_perform(t_int *w) int maxindex; t_word *buf = x->x_vec, *wp; int i; - double a0,a1,a2; // CH + double a3,a1,a2; // CH maxindex = x->x_npoints - 3; @@ -117,10 +117,12 @@ static t_int *tabread4c_tilde_perform(t_int *w) // cminusb - 0.1666667f * (1.-frac) * ( // (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b) // CH - a0 = d - c - a + b; - a1 = a - b - a0; - a2 = c - a; - *out++ = ((a0*frac+a1)*frac+a2)*frac+b; + // 4-point, 3rd-order Hermite (x-form) + a1 = 0.5f * (c - a); + a2 = a - 2.5 * b + 2.f * c - 0.5f * d; + a3 = 0.5f * (d - a) + 1.5f * (b - c); + + *out++ = ((a3 * frac + a2) * frac + a1) * frac + b; } return (w+5); zero: diff --git a/tab/tabread6c~-help.pd b/tab/tabread6c~-help.pd new file mode 100644 index 0000000..ba67350 --- /dev/null +++ b/tab/tabread6c~-help.pd @@ -0,0 +1,58 @@ +#N canvas 334 239 834 544 10; +#N canvas 0 0 450 300 (subpatch) 0; +#X array array99 20 float 0; +#X coords 0 1 19 -1 250 200 1; +#X restore 515 66 graph; +#X obj 69 195 line~; +#X obj 36 139 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 36 32 loadbang; +#X obj 300 195 line~; +#X obj 36 55 t b b; +#N canvas 0 0 450 300 (subpatch) 0; +#X array test_4c 44100 float 0; +#X coords 0 1 44099 -1 250 200 1; +#X restore 278 316 graph; +#X obj 70 219 tabread6c~ array99; +#N canvas 0 0 450 300 (subpatch) 0; +#X array test_6c 44100 float 0; +#X coords 0 1 44099 -1 250 200 1; +#X restore 18 317 graph; +#X obj 301 219 tabread4c~ array99; +#X obj 583 373 phasor~ 222; +#X msg 68 77 \; array99 resize 20 \; array99 0 0 0 0 0 0 -0.5 -0.5 +-0.5 0.5 0.5 0.5 -0.5 0 0 0.5 0 0 0 0 0 \; pd dsp 1 \;; +#X msg 70 171 2 \, 17 1000; +#X msg 300 172 2 \, 17 1000; +#X obj 583 400 *~ 15; +#X obj 582 425 +~ 2; +#X obj 582 448 tabread6c~ array99; +#X obj 606 471 tabread4c~ array99; +#X obj 582 494 dac~; +#X floatatom 583 354 5 0 0 0 - - -; +#X floatatom 583 314 5 0 0 0 - - -; +#X obj 583 333 mtof; +#X obj 302 258 tabwrite~ test_4c; +#X obj 36 250 tabwrite~ test_6c; +#X connect 1 0 7 0; +#X connect 2 0 12 0; +#X connect 2 0 13 0; +#X connect 2 0 22 0; +#X connect 2 0 23 0; +#X connect 3 0 5 0; +#X connect 4 0 9 0; +#X connect 5 0 2 0; +#X connect 5 1 11 0; +#X connect 7 0 23 0; +#X connect 9 0 22 0; +#X connect 10 0 14 0; +#X connect 12 0 1 0; +#X connect 13 0 4 0; +#X connect 14 0 15 0; +#X connect 15 0 16 0; +#X connect 15 0 17 0; +#X connect 16 0 18 0; +#X connect 17 0 18 1; +#X connect 19 0 10 0; +#X connect 20 0 21 0; +#X connect 21 0 19 0; diff --git a/tab/tabread6c~.c b/tab/tabread6c~.c new file mode 100644 index 0000000..6bfe127 --- /dev/null +++ b/tab/tabread6c~.c @@ -0,0 +1,175 @@ +// tabread6c~ +// most of this code comes from pd. just the interpolation shematic is diferent. + + +/* +This software is copyrighted by Miller Puckette and others. The following +terms (the "Standard Improved BSD License") apply to all files associated with +the software unless explicitly disclaimed in individual files: + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. +3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// Cyrille Henry 06 2008 + +#include "m_pd.h" + +/******************** tabread6c~ ***********************/ + +static t_class *tabread6c_tilde_class; + +typedef struct _tabread6c_tilde +{ + t_object x_obj; + int x_npoints; + t_word *x_vec; + t_symbol *x_arrayname; + t_float x_f; +} t_tabread6c_tilde; + +static void *tabread6c_tilde_new(t_symbol *s) +{ + t_tabread6c_tilde *x = (t_tabread6c_tilde *)pd_new(tabread6c_tilde_class); + x->x_arrayname = s; + x->x_vec = 0; + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); +} + +static t_int *tabread6c_tilde_perform(t_int *w) +{ + t_tabread6c_tilde *x = (t_tabread6c_tilde *)(w[1]); + t_sample *in = (t_sample *)(w[2]); + t_sample *out = (t_sample *)(w[3]); + int n = (int)(w[4]); + int maxindex; + t_word *buf = x->x_vec, *wp; + int i; + double a0,a1,a2,a3,a4,a5; // CH + + maxindex = x->x_npoints - 3; + + if (!buf) goto zero; + +#if 0 /* test for spam -- I'm not ready to deal with this */ + for (i = 0, xmax = 0, xmin = maxindex, fp = in1; i < n; i++, fp++) + { + t_sample f = *in1; + if (f < xmin) xmin = f; + else if (f > xmax) xmax = f; + } + if (xmax < xmin + x->c_maxextent) xmax = xmin + x->c_maxextent; + for (i = 0, splitlo = xmin+ x->c_maxextent, splithi = xmax - x->c_maxextent, + fp = in1; i < n; i++, fp++) + { + t_sample f = *in1; + if (f > splitlo && f < splithi) goto zero; + } +#endif + + for (i = 0; i < n; i++) + { + t_sample findex = *in++; + int index = findex; + t_sample frac, a, b, c, d, e, f, cminusb; + static int count; + if (index < 1) + index = 1, frac = 0; + else if (index > maxindex) + index = maxindex, frac = 1; + else frac = findex - index; + wp = buf + index; + a = wp[-2].w_float; + b = wp[-1].w_float; + c = wp[0].w_float; + d = wp[1].w_float; + e = wp[2].w_float; + f = wp[3].w_float; +// CH + + a0 = c; + a1 = ( 1./12.)*a - ( 2./3. )*b + ( 2./3. )*d - ( 1./12.)*e; + a2 = (-1./24.)*a + ( 2./3. )*b - ( 5./4. )*c + ( 2./3. )*d - ( 1./24.)*e; + a3 = (-3./8. )*a + (13./8. )*b - (35./12.)*c + (11./4. )*d - (11./8. )*e + ( 7./24.)*f; + a4 = (13./24.)*a - ( 8./3. )*b + (21./4. )*c - (31./6. )*d + (61./24.)*e - ( 1./2. )*f; + a5 = (-5./24.)*a + (25./24.)*b - (25./12.)*c + (25./12.)*d - (25./24.)*e + ( 5./24.)*f; + + *out++ = ((((a5 * frac + a4 ) * frac + a3) * frac + a2) * frac + a1) * frac + a0; + + } + return (w+5); + zero: + while (n--) *out++ = 0; + + return (w+5); +} + +void tabread6c_tilde_set(t_tabread6c_tilde *x, t_symbol *s) +{ + t_garray *a; + + x->x_arrayname = s; + if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + { + if (*s->s_name) + pd_error(x, "tabread6c~: %s: no such array", x->x_arrayname->s_name); + x->x_vec = 0; + } + else if (!garray_getfloatwords(a, &x->x_npoints, &x->x_vec)) + { + pd_error(x, "%s: bad template for tabread6c~", x->x_arrayname->s_name); + x->x_vec = 0; + } + else garray_usedindsp(a); +} + +static void tabread6c_tilde_dsp(t_tabread6c_tilde *x, t_signal **sp) +{ + tabread6c_tilde_set(x, x->x_arrayname); + + dsp_add(tabread6c_tilde_perform, 4, x, + sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + +} + +static void tabread6c_tilde_free(t_tabread6c_tilde *x) +{ +} + +void tabread6c_tilde_setup(void) +{ + tabread6c_tilde_class = class_new(gensym("tabread6c~"), + (t_newmethod)tabread6c_tilde_new, (t_method)tabread6c_tilde_free, + sizeof(t_tabread6c_tilde), 0, A_DEFSYM, 0); + CLASS_MAINSIGNALIN(tabread6c_tilde_class, t_tabread6c_tilde, x_f); + class_addmethod(tabread6c_tilde_class, (t_method)tabread6c_tilde_dsp, + gensym("dsp"), 0); + class_addmethod(tabread6c_tilde_class, (t_method)tabread6c_tilde_set, + gensym("set"), A_SYMBOL, 0); +} -- cgit v1.2.1