aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zeroxpos~/help-zeroxpos~.pd70
-rw-r--r--zeroxpos~/zeroxpos~.c34
2 files changed, 39 insertions, 65 deletions
diff --git a/zeroxpos~/help-zeroxpos~.pd b/zeroxpos~/help-zeroxpos~.pd
index 31b0048..6f4cddd 100644
--- a/zeroxpos~/help-zeroxpos~.pd
+++ b/zeroxpos~/help-zeroxpos~.pd
@@ -1,45 +1,25 @@
-#N canvas 0 22 454 304 10;
-#X msg 182 52 1;
-#X msg 192 68 2;
-#X msg 224 90 5;
-#X obj 33 76 osc~ 100;
-#X floatatom 183 112 5 0 0 0 - - -;
-#X text 187 37 find...;
-#X text 207 52 1st zero crossing in frame;
-#X text 219 68 2nd zero crossing in frame;
-#X text 249 90 5th zero crossing in frame;
-#X text 240 105 ...etc;
-#X msg 76 31 bang;
-#X text 74 15 do it!;
-#X floatatom 57 160 5 0 0 3 sample - -;
-#X floatatom 183 159 5 0 0 3 direction - -;
-#X msg 329 156 \; pd dsp 1;
-#X obj 329 140 loadbang;
-#X text 29 205 If you ask to find a number of zero-crossings which
-will return a result past the end of the frame \, it will carry the
-number into the next frame and find it there!;
-#X obj 263 36 loadbang;
-#N canvas 0 22 213 256 it's_in_here! 0;
-#X obj 35 125 zeroxpos~;
-#X floatatom 94 104 5 0 0 0 - - -;
-#X obj 94 82 inlet;
-#X obj 35 49 inlet~;
-#X obj 39 193 block~ 1024;
-#X obj 36 154 outlet;
-#X obj 93 154 outlet;
-#X connect 0 0 5 0;
-#X connect 0 1 6 0;
-#X connect 1 0 0 1;
-#X connect 2 0 1 0;
-#X connect 3 0 0 0;
-#X restore 77 130 pd it's_in_here!;
-#X connect 0 0 4 0;
-#X connect 1 0 4 0;
-#X connect 2 0 4 0;
-#X connect 3 0 18 0;
-#X connect 4 0 18 1;
-#X connect 10 0 18 0;
-#X connect 15 0 14 0;
-#X connect 17 0 0 0;
-#X connect 18 0 12 0;
-#X connect 18 1 13 0;
+#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
+-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;
diff --git a/zeroxpos~/zeroxpos~.c b/zeroxpos~/zeroxpos~.c
index adccc14..d6c15c5 100644
--- a/zeroxpos~/zeroxpos~.c
+++ b/zeroxpos~/zeroxpos~.c
@@ -29,34 +29,28 @@ t_int *zeroxpos_tilde_perform(t_int *w)
int i = 0;
x->i_pol = 0;
x->i_ndx = -1;
- int prev = ctl->final_pol;
+ int prev = ctl->final_pol == 0 ? in[0] : ctl->final_pol;
for(i=0;i<n;i++)
{
polarity = in[i] >= 0 ? 1 : -1;
- while(i>0)
+ if((polarity < prev || polarity > prev) && count == number && x->i_bang == 1)
{
- if((polarity < prev || polarity > prev) && count == number && x->i_bang == 1)
- {
- x->i_ndx = i;
- x->i_pol = polarity;
- count++;
- x->i_bang = 0;
- }
- if((polarity < prev || polarity > prev) && count < number)
- {
- count++;
- }
- if(i==n-1)
- {
- ctl->final_pol = polarity;
- x->i_count = count;
- }
+ 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)
+ {
+ ctl->final_pol = polarity;
+ x->i_count = count;
}
prev = polarity;
}
- outlet_float(x->f_pol, (float)x->i_pol);
- outlet_float(x->f_pos, (float)x->i_ndx);
return(w+4);
}