Minor tidy-ups to MTDM code; add test.
authorCarl Hetherington <carl@carlh.net>
Fri, 1 Jun 2012 16:52:56 +0000 (16:52 +0000)
committerCarl Hetherington <carl@carlh.net>
Fri, 1 Jun 2012 16:52:56 +0000 (16:52 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12527 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/mtdm.h
libs/ardour/mtdm.cc
libs/ardour/port_insert.cc
libs/ardour/test/mtdm_test.cc [new file with mode: 0644]
libs/ardour/test/mtdm_test.h [new file with mode: 0644]
libs/ardour/wscript

index 9d67e1cd646e2465626ff02f54fb530080ee1587..59b504b821b7fb180a108b92c7545f3c6130b2e8 100644 (file)
@@ -27,11 +27,11 @@ public:
        MTDM ();
 
        int process (size_t len, float *inp, float *out);
-       int resolve (void);
-       void invert (void) { _inv ^= 1; }
-       int    inv (void) { return _inv; }
-       double del (void) { return _del; }
-       double err (void) { return _err; }
+       int resolve ();
+       void invert () { _inv ^= 1; }
+       int    inv () { return _inv; }
+       double del () { return _del; }
+       double err () { return _err; }
 
 private:
        class Freq {
index ba73025053fcd3a17386843243d22c82cb4f1c1d..4c27b3b6005197a493f0050f39aa85a42b7db28d 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "ardour/mtdm.h"
 
-MTDM::MTDM (void)
+MTDM::MTDM ()
        : _cnt (0)
        , _inv (0)
 {
index 46c4d7e9d5e6a296c8fba44946a394d5e75ea3e9..05d0aa3c6f2ba06aa85531328271f07d222a7a18 100644 (file)
@@ -62,10 +62,7 @@ PortInsert::~PortInsert ()
 void
 PortInsert::start_latency_detection ()
 {
-        if (_mtdm != 0) {
-                delete _mtdm;
-        }
-
+       delete _mtdm;
         _mtdm = new MTDM;
         _latency_flush_frames = false;
         _latency_detect = true;
@@ -118,7 +115,7 @@ PortInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame,
                         Sample* out = outbuf.data();
 
                         _mtdm->process (nframes, in, out);
-
+                       
                         outbuf.set_is_silent (false);
                 }
 
diff --git a/libs/ardour/test/mtdm_test.cc b/libs/ardour/test/mtdm_test.cc
new file mode 100644 (file)
index 0000000..e409bd6
--- /dev/null
@@ -0,0 +1,29 @@
+#include <cstring>
+#include <cmath>
+#include "ardour/mtdm.h"
+#include "mtdm_test.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (MTDMTest);
+
+using namespace std;
+
+void
+MTDMTest::basicTest ()
+{
+       float in[256];
+       float out[256];
+
+       memset (in, 0, 256 * sizeof (float));
+       MTDM* mtdm = new MTDM;
+       mtdm->process (256, in, out);
+       memcpy (in, out, 256 * sizeof (float));
+       
+       for (int i = 0; i < 64; ++i) {
+               mtdm->process (256, in, out);
+               memcpy (in, out, 256 * sizeof (float));
+
+               CPPUNIT_ASSERT_EQUAL (0, mtdm->resolve ());
+               CPPUNIT_ASSERT (mtdm->err() < 1);
+               CPPUNIT_ASSERT_EQUAL (256.0, rint (mtdm->del()));
+       }
+}
diff --git a/libs/ardour/test/mtdm_test.h b/libs/ardour/test/mtdm_test.h
new file mode 100644 (file)
index 0000000..c02a4f2
--- /dev/null
@@ -0,0 +1,17 @@
+#include <sigc++/sigc++.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class MTDMTest : public CppUnit::TestFixture
+{
+       CPPUNIT_TEST_SUITE (MTDMTest);
+       CPPUNIT_TEST (basicTest);
+       CPPUNIT_TEST_SUITE_END ();
+
+public:
+       void setUp () {}
+       void tearDown () {}
+
+       void basicTest ();
+};
+
index 2312c363d2df92ff98ddc2f99c23edfa5eb2ca58..ee86a203193608f30077480a245f4a30ad68605c 100644 (file)
@@ -437,6 +437,7 @@ def build(bld):
                 test/playlist_layering_test.cc
                 test/playlist_read_test.cc
                 test/control_surfaces_test.cc
+                test/mtdm_test.cc
                 test/testrunner.cc
         '''.split()