From 0d6a18d8c1d80f4badb06929b90515bf121595b5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 14 Jul 2015 21:30:49 +0100 Subject: [PATCH] Try rounding down when calculating frames from Times. --- src/lib/dcpomatic_time.h | 2 +- test/dcpomatic_time_test.cc | 39 +++++++++++++++++++++++++++++++++++++ test/wscript | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/dcpomatic_time_test.cc diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 437b78f62..4f95b64ff 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -133,7 +133,7 @@ public: template 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 index 000000000..4462ae870 --- /dev/null +++ b/test/dcpomatic_time_test.cc @@ -0,0 +1,39 @@ +/* + Copyright (C) 2015 Carl Hetherington + + 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 +#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; + } + } +} diff --git a/test/wscript b/test/wscript index 7e2cf4b0d..931f3e924 100644 --- a/test/wscript +++ b/test/wscript @@ -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 -- 2.30.2