[SCM] calf/master: + Framework: make Hermite interpolation monotonic at all cost (temp. workaround)

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:38:34 UTC 2013


The following commit has been merged in the master branch:
commit 65ad89b97bac63829895b7dc367044dbe3d4fe87
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Wed Nov 19 00:02:47 2008 +0000

    + Framework: make Hermite interpolation monotonic at all cost (temp. workaround)

diff --git a/src/calf/primitives.h b/src/calf/primitives.h
index 34f8e48..78e4155 100644
--- a/src/calf/primitives.h
+++ b/src/calf/primitives.h
@@ -26,6 +26,7 @@
 #include <cmath>
 #include <cstdlib>
 #include <stdint.h>
+#include <stdio.h>
 
 namespace dsp {
 
@@ -481,7 +482,6 @@ inline float normalized_hermite(float t, float p0, float p1, float m0, float m1)
 }
 
 /// Hermite interpolation between two points and slopes 
-/// @arg t normalized x coordinate (0-1 over the interval in question)
 /// @arg x point within interval (x0 <= x <= x1)
 /// @arg x0 interval start
 /// @arg x1 interval end
@@ -493,10 +493,29 @@ inline float hermite_interpolation(float x, float x0, float x1, float p0, float
 {
     float width = x1 - x0;
     float t = (x - x0) / width;
+    float delta = (p1-p0)/width;
+    if (fabs(delta) == small_value<float>())
+    {
+        m0 = m1 = 0.f;
+    }
+    else
+    {
+        float idelta = 1.0 / delta;
+        float alpha = m0 / delta;
+        float beta = m1 / delta;
+        if (alpha*alpha + beta*beta > 9)
+        {
+            float sc = (3.0 * delta) / sqrt(m0*m0+m1*m1);
+            m0 = sc * alpha * delta;
+            m1 = sc * beta * delta;
+            // printf("bump...%f\n", sc);
+        }
+    }
     m0 *= width;
     m1 *= width;
     float t2 = t*t;
     float t3 = t2*t;
+    // printf("t=%f p0=%f p1=%f m0=%f m1=%f\n", t, p0, p1, m0, m1);
     return (2*t3 - 3*t2 + 1) * p0 + (t3 - 2*t2 + t) * m0 + (-2*t3 + 3*t2) * p1 + (t3-t2) * m1;
 }
 

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list