Try rounding down when calculating frames from Times.
authorCarl Hetherington <cth@carlh.net>
Tue, 14 Jul 2015 20:30:49 +0000 (21:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 14 Jul 2015 20:30:49 +0000 (21:30 +0100)
src/lib/dcpomatic_time.h
test/dcpomatic_time_test.cc [new file with mode: 0644]
test/wscript

index 437b78f627bc7e51f5c59701f3fe7a59b3528924..4f95b64ffe64fe2be69409dca18e26788299a975 100644 (file)
@@ -133,7 +133,7 @@ public:
 
        template <typename T>
        int64_t frames (T r) const {
-               return rint (double (_t) * r / HZ);
+               return floor (double (_t) * r / HZ);
        }
 
        /** @param r Frames per second */
diff --git a/test/dcpomatic_time_test.cc b/test/dcpomatic_time_test.cc
new file mode 100644 (file)
index 0000000..4462ae8
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/test/unit_test.hpp>
+#include "lib/dcpomatic_time.h"
+
+BOOST_AUTO_TEST_CASE (dcpomatic_time_test)
+{
+       FrameRateChange frc (24, 48);
+       int j = 0;
+       int k = 0;
+       for (int64_t i = 0; i < 62000; i += 2000) {
+               DCPTime d (i);
+               ContentTime c (d, frc);
+               std::cout << i << " " << d << " " << c << " " << c.frames (24.0) << " " << j << "\n";
+               BOOST_CHECK_EQUAL (c.frames (24.0), j);
+               ++k;
+               if (k == 2) {
+                       ++j;
+                       k = 0;
+               }
+       }
+}
index 7e2cf4b0dd93f8f8b184879e15092a246700800b..931f3e924b36d1910f0d66d4bf5348eac5ab1e16 100644 (file)
@@ -47,6 +47,7 @@ def build(bld):
                  client_server_test.cc
                  colour_conversion_test.cc
                  dcp_subtitle_test.cc
+                 dcpomatic_time_test.cc
                  ffmpeg_audio_test.cc
                  ffmpeg_dcp_test.cc
                  ffmpeg_decoder_seek_test.cc