As previous discussed in the thread "Whose fault is this crash? (nan and inf)", a patch is pasted below to fix the problem.
It might be possible to fix the problem a better way, by checking whether the integer index variable (called "idelsamps") is within bounds, but the complexity of the code goes a little bit above my head.
The other two situations mentioned in the thread that might have this problem, namely tabread4~ and poke~, should not have this problem since there are checks that the integer index values are within bounds.
diff --git a/pure-data/src/d_array.c b/pure-data/src/d_array.c index d365cf2..9c16a85 100644 --- a/pure-data/src/d_array.c +++ b/pure-data/src/d_array.c @@ -423,7 +423,11 @@ static t_int *tabread4_tilde_perform(t_int *w)
for (i = 0; i < n; i++) { - double findex = *in++ + onset; + t_sample inval = *in++; + if(!isfinite(inval)) + inval = 0.0f; + + double findex = inval + onset; int index = findex; t_sample frac, a, b, c, d, cminusb; static int count;
Sorry, it seems like I've been sending html formatted mails. I thought I had turned that option off, but I guess it must have been turned on again after switching to a different machine.
Sorry again, that patch was for tabread4~, which should work fine. Trying again:
diff --git a/pure-data/src/d_delay.c b/pure-data/src/d_delay.c index a6e5f7c..f22f7d7 100644 --- a/pure-data/src/d_delay.c +++ b/pure-data/src/d_delay.c @@ -271,7 +271,11 @@ static t_int *sigvd_perform(t_int *w) t_sample zerodel = x->x_zerodel; while (n--) { - t_sample delsamps = x->x_sr * *in++ - zerodel, frac; + t_sample inval = *in++; + if(!isfinite(inval)) + inval = 0.0f; + + t_sample delsamps = x->x_sr * inval - zerodel, frac; int idelsamps; t_sample a, b, c, d, cminusb; if (delsamps < 1.00001f) delsamps = 1.00001f;
On Tue, Sep 10, 2013 at 4:49 PM, Kjetil Matheussen k.s.matheussen@gmail.com wrote:
Sorry, it seems like I've been sending html formatted mails. I thought I had turned that option off, but I guess it must have been turned on again after switching to a different machine.
Hi Kjetil,
In my own code I tend to exploit the incomparibility of NaN.
Instead of:
if (x < lo) x = lo; if (x > hi) x = hi;
I write:
if (! (x >= lo)) x = lo; if (! (x <= hi)) x = hi;
As any comparison with NaN gives false, the first version will pass NaN through unchanged, but the second version will replace NaN with lo. Behaviour with finite values and +/-Infinity should remain the same as the first version.
On 10/09/13 19:01, Kjetil Matheussen wrote:
Sorry again, that patch was for tabread4~, which should work fine. Trying again:
diff --git a/pure-data/src/d_delay.c b/pure-data/src/d_delay.c index a6e5f7c..f22f7d7 100644 --- a/pure-data/src/d_delay.c +++ b/pure-data/src/d_delay.c @@ -271,7 +271,11 @@ static t_int *sigvd_perform(t_int *w) t_sample zerodel = x->x_zerodel; while (n--) {
t_sample delsamps = x->x_sr * *in++ - zerodel, frac;
t_sample inval = *in++;
if(!isfinite(inval))
inval = 0.0f;
t_sample delsamps = x->x_sr * inval - zerodel, frac;
Not sure what Miller's policy on C standards is, but all other Pd code seems to declare all variables at the start of a block.
int idelsamps; t_sample a, b, c, d, cminusb; if (delsamps < 1.00001f) delsamps = 1.00001f;
Claude
On Tue, Sep 10, 2013 at 8:40 PM, Claude Heiland-Allen claude@mathr.co.uk wrote:
Hi Kjetil,
In my own code I tend to exploit the incomparibility of NaN.
Instead of:
if (x < lo) x = lo; if (x > hi) x = hi;
I write:
if (! (x >= lo)) x = lo; if (! (x <= hi)) x = hi;
As any comparison with NaN gives false, the first version will pass NaN through unchanged, but the second version will replace NaN with lo. Behaviour with finite values and +/-Infinity should remain the same as the first version.
Hi Claude,
That is a nice solution, but is
" if (! (x >= lo)) x = lo; if (! (x <= hi)) x = hi; "
reallly faster than
" if(!isfinite(x)) x = 0.0f; if (x < lo) x = lo; if (x > hi) x = hi; "
?
If not, the second option is much clearer.
THanks all for this... I went ahead and patched it (Claude's way, but with an explanatory comment :)
On Wed, Sep 11, 2013 at 08:53:12PM +0200, Kjetil Matheussen wrote:
On Tue, Sep 10, 2013 at 8:40 PM, Claude Heiland-Allen claude@mathr.co.uk wrote:
Hi Kjetil,
In my own code I tend to exploit the incomparibility of NaN.
Instead of:
if (x < lo) x = lo; if (x > hi) x = hi;
I write:
if (! (x >= lo)) x = lo; if (! (x <= hi)) x = hi;
As any comparison with NaN gives false, the first version will pass NaN through unchanged, but the second version will replace NaN with lo. Behaviour with finite values and +/-Infinity should remain the same as the first version.
Hi Claude,
That is a nice solution, but is
" if (! (x >= lo)) x = lo; if (! (x <= hi)) x = hi; "
reallly faster than
" if(!isfinite(x)) x = 0.0f; if (x < lo) x = lo; if (x > hi) x = hi; "
?
If not, the second option is much clearer.
Pd-dev mailing list Pd-dev@iem.at http://lists.puredata.info/listinfo/pd-dev