From db43bb27d0317e255ff95eb37c7971f2a6388d8c Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Tue, 18 Jul 2017 13:07:59 -0400
Subject: [PATCH] fix for #348, plus compatibility codepath and Pd Vanilla
 version bump

---
 pd/src/d_math.c | 18 +++++++++++++++++-
 pd/src/m_pd.h   |  2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/pd/src/d_math.c b/pd/src/d_math.c
index 3c75a9465..7b385c8bf 100644
--- a/pd/src/d_math.c
+++ b/pd/src/d_math.c
@@ -247,6 +247,20 @@ static void *sigwrap_new(void)
 }
 
 static t_int *sigwrap_perform(t_int *w)
+{
+    t_sample *in = *(t_sample **)(w+1), *out = *(t_sample **)(w+2);
+    t_int n = *(t_int *)(w+3);
+    while (n--)
+    {
+        t_sample f = *in++;
+        int k = f;
+        if (k <= f) *out++ = f-k;
+        else *out++ = f - (k-1);
+    }
+    return (w + 4);
+}
+
+static t_int *sigwrap_perform_old(t_int *w)
 {
     t_sample *in = *(t_sample **)(w+1), *out = *(t_sample **)(w+2);
     t_int n = *(t_int *)(w+3);
@@ -262,7 +276,9 @@ static t_int *sigwrap_perform(t_int *w)
 
 static void sigwrap_dsp(t_sigwrap *x, t_signal **sp)
 {
-    dsp_add(sigwrap_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+    dsp_add((pd_compatibilitylevel > 47 ?
+        sigwrap_perform : sigwrap_perform_old),
+            3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
 }
 
 void sigwrap_setup(void)
diff --git a/pd/src/m_pd.h b/pd/src/m_pd.h
index a3b75f1ea..8e2d86f87 100644
--- a/pd/src/m_pd.h
+++ b/pd/src/m_pd.h
@@ -11,7 +11,7 @@ extern "C" {
 #include <stdarg.h>
 
 #define PD_MAJOR_VERSION 0
-#define PD_MINOR_VERSION 47
+#define PD_MINOR_VERSION 48
 #define PD_BUGFIX_VERSION 0
 #define PD_TEST_VERSION ""
 #define PD_L2ORK_VERSION "2.2.3"
-- 
GitLab