diff options
author | Ed Kelly <edkelly@users.sourceforge.net> | 2007-03-05 16:35:52 +0000 |
---|---|---|
committer | Ed Kelly <edkelly@users.sourceforge.net> | 2007-03-05 16:35:52 +0000 |
commit | 1142163a6391018dadfef855ed53962900886ab9 (patch) | |
tree | fe74fc25a97c95ef3313c71128bf52a706b9e16e | |
parent | 0c0b07d3bff68484d554b33d7693117863404d2a (diff) |
This commit was generated by cvs2svn to compensate for changes in r7462,
which included commits to RCS files with non-trunk default branches.
svn path=/trunk/externals/ekext/; revision=7463
-rw-r--r-- | zeroxpos~/help-zeroxpos~.pd | 119 | ||||
-rw-r--r-- | zeroxpos~/zeroxpos~.c | 138 |
2 files changed, 212 insertions, 45 deletions
diff --git a/zeroxpos~/help-zeroxpos~.pd b/zeroxpos~/help-zeroxpos~.pd index 6f4cddd..7bb2f23 100644 --- a/zeroxpos~/help-zeroxpos~.pd +++ b/zeroxpos~/help-zeroxpos~.pd @@ -1,25 +1,96 @@ -#N canvas 0 0 450 300 10; -#X obj 149 197 print direction; -#X obj 77 219 print offset; -#X floatatom 149 126 5 0 0 0 - - -; -#X obj 76 96 osc~ 320; -#X obj 77 151 zeroxpos~ 3; -#X text 161 152 ...is also creation arg; -#X text 189 125 nth zero-crossing in frame...; -#X text 56 13 zeroxpos~: find n-th zero crossing in frame; -#X obj 144 89 bng 15 250 50 0 empty empty get-it 0 -6 0 8 -262144 -1 +#N canvas 0 0 603 357 10; +#X obj 251 132 block~ 256; +#X obj 144 150 zeroxpos~ 3; +#X obj 40 150 zeroxpos~ -3; +#X text 30 30 Zeroxpos~ finds a zero-crossing point within a dsp-block +; +#X obj 31 96 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X floatatom 77 180 5 0 0 0 - - -; -#X floatatom 149 175 5 0 0 0 - - -; -#X text 77 235 time since start of frame in samples; -#X text 170 215 direction (1=up \, -1=down); -#X obj 354 179 block~ 1024; -#X text 69 30 by Edward Kelly; -#X msg 245 45 \; pd dsp 1; -#X connect 2 0 4 1; -#X connect 3 0 4 0; -#X connect 4 0 9 0; -#X connect 4 1 10 0; -#X connect 8 0 4 0; -#X connect 9 0 1 0; -#X connect 10 0 0 0; +#X floatatom 40 167 5 0 0 0 - - -; +#X floatatom 144 167 5 0 0 0 - - -; +#X text 228 156 <-- creation argument sets the; +#X text 252 167 zero-crossing point to find; +#X text 251 178 1st \, 2nd \, 3rd etc.; +#X text 249 220 a positive argument finds; +#X text 247 233 the n-th zero crossing from; +#X text 247 245 the start of the block.; +#X text 35 222 a negative argument finds; +#X text 33 233 the n-th zero crossing from; +#X text 33 244 the end of the block.; +#X floatatom 177 107 5 0 0 0 - - -; +#N canvas 0 0 450 300 (subpatch) 0; +#X array block 256 float 3; +#A 0 0.253416 0.130458 0.00545404 -0.119636 -0.242851 -0.362248 -0.475957 +-0.582198 -0.679303 -0.765742 -0.840147 -0.901368 -0.948445 -0.980638 +-0.997421 -0.998542 -0.983994 -0.954005 -0.909041 -0.849786 -0.777197 +-0.692413 -0.596762 -0.491735 -0.378986 -0.26029 -0.137509 -0.012569 +0.112569 0.235939 0.355605 0.469692 0.576406 0.67406 0.761136 0.836267 +0.898277 0.946171 0.979207 0.996877 0.998904 0.985256 0.956116 0.911974 +0.853521 0.781673 0.697548 0.602464 0.497928 0.385577 0.267174 0.144571 +0.0197003 -0.105479 -0.229003 -0.348935 -0.463381 -0.570554 -0.668774 +-0.7565 -0.832341 -0.895109 -0.94383 -0.977741 -0.996308 -0.99921 -0.986431 +-0.958173 -0.914879 -0.857217 -0.786086 -0.70262 -0.608129 -0.504093 +-0.392134 -0.27402 -0.151607 -0.0268136 0.0984023 0.222071 0.342253 +0.457064 0.564703 0.663473 0.75182 0.828368 0.891918 0.941472 0.976224 +0.995654 0.999461 0.987585 0.960201 0.917728 0.860855 0.790474 0.707687 +0.613778 0.510233 0.398682 0.280874 0.158655 0.0339427 -0.0913004 -0.21511 +-0.335546 -0.450712 -0.558797 -0.658112 -0.7471 -0.824365 -0.888672 +-0.939028 -0.974648 -0.994974 -0.999679 -0.988672 -0.962151 -0.920532 +-0.864466 -0.794818 -0.712687 -0.619375 -0.516342 -0.405204 -0.287695 +-0.165673 -0.0410526 0.0842137 0.208159 0.328832 0.444344 0.552884 +0.652749 0.742354 0.820304 0.885381 0.936565 0.973047 0.994233 0.999818 +0.989715 0.964081 0.923301 0.868019 0.799117 0.717675 0.624969 0.522437 +0.411707 0.294517 0.172705 0.0481785 -0.0771039 -0.201175 -0.322089 +-0.43795 -0.546929 -0.647319 -0.737551 -0.816209 -0.882057 -0.934039 +-0.971362 -0.993442 -0.999933 -0.990717 -0.965937 -0.926001 -0.871533 +-0.803388 -0.722613 -0.630497 -0.528488 -0.418184 -0.301313 -0.179707 +-0.0552834 0.0700081 0.194203 0.315346 0.431537 0.540954 0.641883 0.732741 +0.812077 0.878668 0.931471 0.969657 0.992614 0.999977 0.991649 0.967759 +0.928683 0.87501 0.807601 0.72752 0.636021 0.534537 0.42465 0.308102 +0.186719 0.0624042 -0.0628919 -0.187199 -0.308567 -0.425094 -0.534951 +-0.636398 -0.727855 -0.807891 -0.875249 -0.928863 -0.967882 -0.991712 +-0.99998 -0.992555 -0.969531 -0.931286 -0.878427 -0.811782 -0.732395 +-0.641494 -0.540528 -0.43108 -0.314867 -0.193706 -0.0695031 0.0557888 +0.180206 0.301797 0.418643 0.528917 0.63089 0.722964 0.803687 0.87178 +0.926192 0.966069 0.990788 0.999936 0.993385 0.971245 0.933864 0.881826 +0.815924 0.73722 0.646947 0.546521 0.437509 0.321625 0.200696 0.0766166 +-0.0486669 -0.173186 -0.294984; +#X coords 0 1 255 -1 100 50 1; +#X restore 207 268 graph; +#X obj 220 87 tabwrite~ block; +#X obj 107 75 osc~ 880; +#X obj 79 284 tabread block; +#X floatatom 79 270 5 0 0 0 - - -; +#X floatatom 79 301 5 0 0 0 - - -; +#X floatatom 119 167 2 0 0 0 - - -; +#X floatatom 216 167 2 0 0 0 - - -; +#X text 36 193 output is in samples \, right output is direction (polarity) +of zero crossing.; +#X msg 320 94 mode \$1; +#X obj 320 79 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X text 349 77 <--- if the mode is zero \,; +#X text 389 89 zeroxpos will not look; +#X text 395 102 for zero-crossing points; +#X text 404 114 until after it receives a; +#X text 412 126 bang. But if it is set to 1 \,; +#X text 418 138 zeroxpos will continuously; +#X text 424 150 look for zero-crossings \,; +#X text 431 163 and output those stored; +#X text 437 175 in memory when banged.; +#X connect 1 0 6 0; +#X connect 1 1 24 0; +#X connect 2 0 5 0; +#X connect 2 1 23 0; +#X connect 4 0 2 0; +#X connect 4 0 1 0; +#X connect 4 0 18 0; +#X connect 16 0 2 1; +#X connect 19 0 2 0; +#X connect 19 0 1 0; +#X connect 19 0 18 0; +#X connect 20 0 22 0; +#X connect 21 0 20 0; +#X connect 26 0 1 0; +#X connect 26 0 2 0; +#X connect 27 0 26 0; diff --git a/zeroxpos~/zeroxpos~.c b/zeroxpos~/zeroxpos~.c index d6c15c5..54373f0 100644 --- a/zeroxpos~/zeroxpos~.c +++ b/zeroxpos~/zeroxpos~.c @@ -1,4 +1,5 @@ #include "m_pd.h" +#include <math.h> static t_class *zeroxpos_tilde_class; @@ -12,8 +13,8 @@ typedef struct _zeroxpos_tilde { t_object x_obj; t_zeroxpos_control x_ctl; - t_float f_num, f_dummy; - t_int i_bang, i_pol, i_count, i_ndx; + t_float f_num, f_dummy, f_dir; + t_int i_bang, i_pol, i_count, i_ndx, i_mode; t_outlet *f_pos, *f_pol; } t_zeroxpos_tilde; @@ -23,7 +24,8 @@ t_int *zeroxpos_tilde_perform(t_int *w) t_zeroxpos_control *ctl = (t_zeroxpos_control *)(w[2]); int n = (int)(w[3]); t_float *in = ctl->c_input; - int number = (int)x->f_num; + x->f_dir = x->f_num >= 0 ? 1 : -1; + int number = x->f_num >= 1 || x->f_num <= -1 ? (int)fabs(x->f_num) : 1; int count = x->i_count; int polarity = 1; int i = 0; @@ -31,33 +33,125 @@ t_int *zeroxpos_tilde_perform(t_int *w) x->i_ndx = -1; int prev = ctl->final_pol == 0 ? in[0] : ctl->final_pol; - for(i=0;i<n;i++) + if(x->i_mode == 0) { - polarity = in[i] >= 0 ? 1 : -1; - if((polarity < prev || polarity > prev) && count == number && x->i_bang == 1) + if(x->f_dir > 0) { - x->i_ndx = i; - x->i_pol = polarity; - count += 1e+06; - x->i_bang = 0; - outlet_float(x->f_pol, (float)x->i_pol); - outlet_float(x->f_pos, (float)x->i_ndx); + for(i=0;i<n;i++) + { + polarity = in[i] >= 0 ? 1 : -1; + if((polarity < prev || polarity > prev) && count == number && x->i_bang == 1) + { + x->i_ndx = i; + x->i_pol = polarity; + count += 1e+06; + x->i_bang = 0; + outlet_float(x->f_pol, (float)x->i_pol); + outlet_float(x->f_pos, (float)x->i_ndx); + } + if((polarity < prev || polarity > prev) && count < number) count++; + if(i==n-1&&count<number) + { + ctl->final_pol = polarity; + x->i_count = count; + } + prev = polarity; + } } - if((polarity < prev || polarity > prev) && count < number) count++; - if(i==n-1) + else if(x->f_dir < 0) { - ctl->final_pol = polarity; - x->i_count = count; + for(i=n-1;i>=0;i--) + { + polarity = in[i] >= 0 ? 1 : -1; + if((polarity < prev || polarity > prev) && count == number && x->i_bang == 1) + { + x->i_ndx = i; + x->i_pol = polarity; + count += 1e+06; + x->i_bang = 0; + outlet_float(x->f_pol, (float)(x->i_pol*-1)); + outlet_float(x->f_pos, (float)x->i_ndx+1); + } + if((polarity < prev || polarity > prev) && count < number) count++; + if(i==0&&count<number) + { + ctl->final_pol = polarity; + x->i_count = count; + } + prev = polarity; + } + } + } + else if(x->i_mode != 0) + { + if(x->f_dir > 0) + { + for(i=0;i<n;i++) + { + polarity = in[i] >= 0 ? 1 : -1; + if((polarity < prev || polarity > prev) && count == number) + { + x->i_ndx = i; + x->i_pol = polarity; + count += 1e+06; + x->i_bang = 0; + } + if((polarity < prev || polarity > prev) && count < number) count++; + if(i==n-1&&count<number) + { + ctl->final_pol = polarity; + x->i_count = count; + } + prev = polarity; + } + } + else if(x->f_dir < 0) + { + for(i=n-1;i>=0;i--) + { + polarity = in[i] >= 0 ? 1 : -1; + if((polarity < prev || polarity > prev) && count == number) + { + x->i_ndx = i; + x->i_pol = polarity; + count += 1e+06; + x->i_bang = 0; + } + if((polarity < prev || polarity > prev) && count < number) count++; + if(i==0&&count<number) + { + ctl->final_pol = polarity; + x->i_count = count; + } + prev = polarity; + } } - prev = polarity; } return(w+4); } void zeroxpos_tilde_bang(t_zeroxpos_tilde *x) { - x->i_bang = 1; - x->i_count = 0; + if(x->i_mode == 0) + { + x->i_bang = 1; + x->i_count = 0; + } + else if(x->i_mode != 0 && x->f_dir > 0) + { + outlet_float(x->f_pol, (float)x->i_pol); + outlet_float(x->f_pos, (float)x->i_ndx); + } + else if(x->i_mode != 0 && x->f_dir < 0) + { + outlet_float(x->f_pol, (float)(x->i_pol*-1)); + outlet_float(x->f_pos, (float)x->i_ndx+1); + } +} + +void zeroxpos_tilde_mode(t_zeroxpos_tilde *x, t_floatarg fmode) +{ + x->i_mode = (int)fmode; } void *zeroxpos_tilde_dsp(t_zeroxpos_tilde *x, t_signal **sp) @@ -70,8 +164,9 @@ void *zeroxpos_tilde_dsp(t_zeroxpos_tilde *x, t_signal **sp) void *zeroxpos_tilde_new(t_floatarg f) { t_zeroxpos_tilde *x = (t_zeroxpos_tilde *)pd_new(zeroxpos_tilde_class); - x->f_num = f > 0 ? f : 1; - x->x_ctl.final_pol = 1; + x->f_dir = f >= 0 ? 1 : -1; + x->f_num = f >= 1 || f <= -1 ? (int)fabs(f) : 1; + x->x_ctl.final_pol = 0; x->i_count = 0; floatinlet_new (&x->x_obj, &x->f_num); x->f_pos = outlet_new(&x->x_obj, gensym("float")); @@ -93,6 +188,7 @@ void zeroxpos_tilde_setup(void) class_sethelpsymbol(zeroxpos_tilde_class, gensym("help-zeroxpos~")); class_addbang(zeroxpos_tilde_class, zeroxpos_tilde_bang); class_addmethod(zeroxpos_tilde_class, (t_method)zeroxpos_tilde_dsp, gensym("dsp"), 0); + class_addmethod(zeroxpos_tilde_class, (t_method)zeroxpos_tilde_mode, gensym("mode"), A_DEFFLOAT, 0); CLASS_MAINSIGNALIN(zeroxpos_tilde_class, t_zeroxpos_tilde, f_dummy); } |