Skip to content

Commit

Permalink
fixed index bug in point.lookup, added dspstate check in point.interp…
Browse files Browse the repository at this point in the history
… so that it will always output when the dspstate changes
  • Loading branch information
ramagottfried committed Sep 16, 2016
1 parent 203e453 commit 9c8f103
Show file tree
Hide file tree
Showing 7 changed files with 549 additions and 242 deletions.
9 changes: 4 additions & 5 deletions code/point.interp.gendsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"appversion" : {
"major" : 7,
"minor" : 2,
"revision" : 4,
"revision" : 5,
"architecture" : "x64",
"modernui" : 1
}
,
"rect" : [ 499.0, 45.0, 656.0, 821.0 ],
"rect" : [ 372.0, 45.0, 656.0, 821.0 ],
"editing_bgcolor" : [ 0.9, 0.9, 0.9, 1.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
Expand Down Expand Up @@ -65,7 +65,7 @@
}
, {
"box" : {
"code" : "expA(x0) // approx exp(x) (more accurate than 'fastexp()') from sm_filter_pack\n{\n\tx = 0.999996 + (0.031261316 + (0.00048274797 + 0.000006 * x0) * x0) * x0;\n\tx *= x; x *= x; x *= x; x *= x; x *= x;\n\treturn x;\n}\r\n\r\nHistory prev_idx, prev_v;\r\nBuffer points(\"#0-yc0\");\r\nParam interp(1);\r\npoints_len = dim(points);\r\nmax_idx = points_len-1;\r\nphase = in1;\r\nidx = in2;\r\nv = prev_v;\r\n\r\nif( change(phase) || change(idx) ) {\r\n\tif( interp == 0 )\r\n\t{\r\n\t\tv = peek(points, clip(idx, 0, max_idx), 0, channels=1);\r\n\t}\r\n\telse\r\n\t{\r\n\t\t// get y positions and interpolate a la curve~ \r\n\t\ty0 = peek(points, clip(idx, 0, max_idx), 0, channels=1);\r\n\t\ty1 = peek(points, clip(idx+1, 0, max_idx), 0, channels=1);\r\n\t\trange = y1-y0;\r\n\t\t\r\n\t\tfp = peek(points, clip(idx+1, 0, max_idx), 1, channels=1);\r\n\t\r\n\t\tif( fp == 0 )\r\n\t\t\tv = y0 + phase*range;\r\n\t\telse {\r\n\t\t\tgp = (exp(fp * phase) - 1.) / (exp(fp) - 1.) ;\r\n\t\t\tv = y0 + gp*range;\r\n\t\t}\r\n\t}\r\n}\r\nout1 = v;\r\nprev_idx = idx;\r\nprev_v = v;",
"code" : "expA(x0) // approx exp(x) (more accurate than 'fastexp()') from sm_filter_pack\n{\n\tx = 0.999996 + (0.031261316 + (0.00048274797 + 0.000006 * x0) * x0) * x0;\n\tx *= x; x *= x; x *= x; x *= x; x *= x;\n\treturn x;\n}\r\n\r\nHistory prev_idx, prev_v;\r\nBuffer points(\"#0-yc0\");\r\nParam interp(1);\r\nParam dspstate(0);\r\npoints_len = dim(points);\r\nmax_idx = points_len-1;\r\nphase = in1;\r\nidx = in2;\r\nv = prev_v;\r\n\r\nif( change(phase) || change(idx) || change(dspstate) ) {\r\n\tif( interp == 0 )\r\n\t{\r\n\t\tv = peek(points, clip(idx, 0, max_idx), 0, channels=1);\r\n\t}\r\n\telse\r\n\t{\r\n\t\t// get y positions and interpolate a la curve~ \r\n\t\ty0 = peek(points, clip(idx, 0, max_idx), 0, channels=1);\r\n\t\ty1 = peek(points, clip(idx+1, 0, max_idx), 0, channels=1);\r\n\t\trange = y1-y0;\r\n\t\t\r\n\t\tfp = peek(points, clip(idx+1, 0, max_idx), 1, channels=1);\r\n\t\r\n\t\tif( fp == 0 )\r\n\t\t\tv = y0 + phase*range;\r\n\t\telse {\r\n\t\t\tgp = (exp(fp * phase) - 1.) / (exp(fp) - 1.) ;\r\n\t\t\tv = y0 + gp*range;\r\n\t\t}\r\n\t}\r\n}\r\nout1 = v;\r\nprev_idx = idx;\r\nprev_v = v;",
"fontface" : 0,
"fontname" : "Arial",
"fontsize" : 12.0,
Expand Down Expand Up @@ -119,8 +119,7 @@
}

}
],
"autosave" : 0
]
}

}
11 changes: 5 additions & 6 deletions code/point.lookup.gendsp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 582.0, 731.0, 37.0, 20.0 ],
"patching_rect" : [ 582.0, 743.0, 37.0, 20.0 ],
"style" : "",
"text" : "out 2"
}
Expand All @@ -64,7 +64,7 @@
}
, {
"box" : {
"code" : "History prev_idx, prev_phase;\r\nBuffer points(\"#0-xyc0\");\r\npoints_len = dim(points);\r\nmax_idx = points_len-1;\r\nidx = prev_idx;\r\nphase = prev_phase;\r\n\r\n// if x position changes, check position and adjust index if necessary\r\nif( change(in1) ) {\r\n\tx0 = peek(points, clip(idx, 0, max_idx), 0, channels=1);\r\n\tx1 = peek(points, clip(idx+1, 0, max_idx), 0, channels=1);\r\n\r\n\tif( in1 < x0 ){\r\n\t\twhile( in1 < x0 && idx > 0 ){\r\n\t\t\tidx -= 1;\r\n\t\t\tx0 = peek(points, clip(idx, 0, max_idx), 0, channels=1);\r\n\t\t}\r\n\t\t\r\n\t\tif( in1 < x0 && idx <= 0 )\r\n\t\t\tx1 = x0;\r\n\t\telse\r\n\t\t\tx1 = peek(points, clip(idx+1, 0, max_idx), 0, channels=1);\r\n\r\n\t} else if( in1 >= x1 )\t{\r\n\t\twhile( in1 >= x1 && idx < points_len ){\r\n\t\t\tidx += 1;\r\n\t\t\tx1 = peek(points, clip(idx+1, 0, max_idx), 0, channels=1);\r\n\t\t}\r\n\t\t\r\n\t\tif( in1 > x1 && idx >= points_len ) \r\n\t\t\tx0 = x1;\r\n\t\telse\r\n\t\t\tx0 = peek(points, clip(idx, 0, max_idx), 0, channels=1);\r\n\t}\r\n\t\r\n\tif( idx == max_idx && x0 == x1 )\r\n\t{\r\n\t\tphase = 1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tphase = scale(in1, x0, x1, 0, 1);\r\n\t}\r\n\r\n}\r\nout1 = phase;\r\nout2 = idx;\r\n\r\nprev_idx = clip(idx, 0, max_idx);\r\nprev_phase = phase;",
"code" : "History idx, phase;\r\nBuffer points(\"#0-xyc0\");\r\nParam dspstate(0);\r\npoints_len = dim(points);\r\nmax_idx0 = points_len-2;\r\nmax_idx1 = points_len-1;\r\n\r\n// if x position changes, check position and adjust index if necessary\r\nif( change(in1) || change(dspstate) ) {\r\n\tx0 = peek(points, clip(idx, 0, max_idx0), 0, channels=1);\r\n\tx1 = peek(points, clip(idx+1, 0, max_idx1), 0, channels=1);\r\n\r\n\tif( in1 < x0 ){\r\n\t\twhile( in1 < x0 && idx > 0 ){\r\n\t\t\tidx -= 1;\r\n\t\t\tx0 = peek(points, clip(idx, 0, max_idx0), 0, channels=1);\r\n\t\t}\r\n\t\t\r\n\t\tif( in1 < x0 && idx <= 0 )\r\n\t\t\tx1 = x0;\r\n\t\telse\r\n\t\t\tx1 = peek(points, clip(idx+1, 0, max_idx1), 0, channels=1);\r\n\r\n\t} else if( in1 >= x1 )\t{\r\n\t\twhile( in1 >= x1 && idx < points_len ){\r\n\t\t\tidx += 1;\r\n\t\t\tx1 = peek(points, clip(idx+1, 0, max_idx1), 0, channels=1);\r\n\t\t}\r\n\t\t\r\n\t\tif( in1 > x1 && idx >= points_len ) \r\n\t\t\tx0 = x1;\r\n\t\telse\r\n\t\t\tx0 = peek(points, clip(idx, 0, max_idx0), 0, channels=1);\r\n\t}\r\n\t\r\n\tif( idx >= max_idx1 && x0 == x1 )\r\n\t{\r\n\t\tphase = 1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tphase = scale(in1, x0, x1, 0, 1);\r\n\t}\r\n\r\n\tidx = clip(idx, 0, max_idx0);\r\n\r\n}\r\nout1 = phase;\r\nout2 = idx;",
"fontface" : 0,
"fontname" : "Arial",
"fontsize" : 12.0,
Expand All @@ -73,7 +73,7 @@
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "", "" ],
"patching_rect" : [ 50.0, 44.0, 551.0, 665.0 ],
"patching_rect" : [ 50.0, 44.0, 551.0, 685.0 ],
"style" : ""
}

Expand All @@ -85,7 +85,7 @@
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 50.0, 731.0, 37.0, 20.0 ],
"patching_rect" : [ 50.0, 743.0, 37.0, 20.0 ],
"style" : "",
"text" : "out 1"
}
Expand Down Expand Up @@ -119,8 +119,7 @@
}

}
],
"autosave" : 0
]
}

}
Loading

0 comments on commit 9c8f103

Please sign in to comment.