Revert "Use make_shared<>."
[dcpomatic.git] / test / time_calculation_test.cc
index de300655dd757d3955885edeba406142227611f1..ddd685d0c33f2bb789ef1cce5567421c863958a8 100644 (file)
@@ -1,25 +1,28 @@
 /*
-    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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,
+    DCP-o-matic 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.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
 #include "lib/film.h"
 #include "lib/ffmpeg_content.h"
+#include "lib/video_content.h"
 #include "lib/player.h"
+#include "lib/audio_content.h"
 #include "test.h"
 #include <boost/test/unit_test.hpp>
 
@@ -40,7 +43,7 @@ static string const xml = "<Content>"
        "<VideoWidth>1280</VideoWidth>"
        "<VideoHeight>720</VideoHeight>"
        "<VideoFrameRate>25</VideoFrameRate>"
-       "<VideoFrameType>0</VideoFrameType>"
+       "<VideoFrameType>2d</VideoFrameType>"
        "<LeftCrop>0</LeftCrop>"
        "<RightCrop>0</RightCrop>"
        "<TopCrop>0</TopCrop>"
@@ -81,6 +84,7 @@ static string const xml = "<Content>"
        "<Name>und; 2 channels</Name>"
        "<Id>2</Id>"
        "<FrameRate>44100</FrameRate>"
+       "<Length>44100</Length>"
        "<Channels>2</Channels>"
        "<FirstAudio>0</FirstAudio>"
        "<Mapping>"
@@ -127,19 +131,44 @@ BOOST_AUTO_TEST_CASE (ffmpeg_time_calculation_test)
 
        /* 25fps content, 25fps DCP */
        film->set_video_frame_rate (25);
-       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 25.0));
        /* 25fps content, 24fps DCP; length should be increased */
        film->set_video_frame_rate (24);
-       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 24.0));
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 24.0));
        /* 25fps content, 30fps DCP; length should be decreased */
        film->set_video_frame_rate (30);
-       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 30.0));
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 30.0));
        /* 25fps content, 50fps DCP; length should be the same */
        film->set_video_frame_rate (50);
-       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 25.0));
        /* 25fps content, 60fps DCP; length should be decreased */
        film->set_video_frame_rate (60);
-       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() * (50.0 / 60) / 25.0));
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() * (50.0 / 60) / 25.0));
+
+       /* Make the content audio-only */
+       content->video.reset ();
+
+       /* 24fps content, 24fps DCP */
+       film->set_video_frame_rate (24);
+       content->set_video_frame_rate (24);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
+       /* 25fps content, 25fps DCP */
+       film->set_video_frame_rate (25);
+       content->set_video_frame_rate (25);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
+       /* 25fps content, 24fps DCP; length should be increased */
+       film->set_video_frame_rate (24);
+       BOOST_CHECK_SMALL (abs (content->full_length().get() - DCPTime::from_seconds(25.0 / 24).get()), 2);
+       /* 25fps content, 30fps DCP; length should be decreased */
+       film->set_video_frame_rate (30);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (25.0 / 30));
+       /* 25fps content, 50fps DCP; length should be the same */
+       film->set_video_frame_rate (50);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
+       /* 25fps content, 60fps DCP; length should be decreased */
+       film->set_video_frame_rate (60);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (50.0 / 60));
+
 }
 
 /** Test Player::dcp_to_content_video */
@@ -152,7 +181,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test1)
 
        list<string> notes;
        shared_ptr<FFmpegContent> content (new FFmpegContent (film, doc, film->state_version(), notes));
-       film->set_sequence_video (false);
+       film->set_sequence (false);
        film->add_content (content);
 
        shared_ptr<Player> player (new Player (film, film->playlist ()));
@@ -330,6 +359,21 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test1)
        BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  72);
        BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)), 144);
        BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 396);
+
+       /* Position 0s, no trim, content rate 29.9978733, DCP rate 30 */
+       content->set_position (DCPTime::from_seconds (0));
+       content->set_trim_start (ContentTime::from_seconds (0));
+       content->set_video_frame_rate (29.9978733);
+       film->set_video_frame_rate (30);
+       player->setup_pieces ();
+       BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
+       piece = player->_pieces.front ();
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (3200)), 1);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (6400)), 2);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (9600)), 3);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (12800)), 4);
+
 }
 
 /** Test Player::content_video_to_dcp */
@@ -342,7 +386,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test2)
 
        list<string> notes;
        shared_ptr<FFmpegContent> content (new FFmpegContent (film, doc, film->state_version(), notes));
-       film->set_sequence_video (false);
+       film->set_sequence (false);
        film->add_content (content);
 
        shared_ptr<Player> player (new Player (film, film->playlist ()));
@@ -518,8 +562,8 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
 
        list<string> notes;
        shared_ptr<FFmpegContent> content (new FFmpegContent (film, doc, film->state_version(), notes));
-       AudioStreamPtr stream = content->audio_streams().front();
-       film->set_sequence_video (false);
+       AudioStreamPtr stream = content->audio->streams().front();
+       film->set_sequence (false);
        film->add_content (content);
 
        shared_ptr<Player> player (new Player (film, film->playlist ()));
@@ -533,9 +577,9 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        shared_ptr<Piece> piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.5)),  24000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.0)), 144000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
 
        /* Position 3s, no trim, video/audio content rate = video/audio DCP rate */
        content->set_position (DCPTime::from_seconds (3));
@@ -546,11 +590,11 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)),  72000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 324000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
 
        /* Position 3s, 1.5s trim, video/audio content rate = video/audio DCP rate */
        content->set_position (DCPTime::from_seconds (3));
@@ -561,17 +605,13 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),   0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),  72000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)), 144000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 396000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
 
-       /* Position 0, no trim, content video rate 24, DCP video rate 25, both audio rates still 48k.
-          Now we are resampling the audio so that 48000 content samples become 46080 DCP samples
-          (sounding the same and still corresponding to 1 second) which are then played over 24/25s
-          so that they run fast.  Hence 1 second in the DCP uses (25/24) * 48000 content samples.
-       */
+       /* Position 0, no trim, content video rate 24, DCP video rate 25, both audio rates still 48k */
        content->set_position (DCPTime ());
        content->set_trim_start (ContentTime ());
        content->set_video_frame_rate (24);
@@ -580,9 +620,9 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.6)),  30000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.0)), 150000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.6)),  28800);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
 
        /* Position 3s, no trim, content video rate 24, DCP rate 25, both audio rates still 48k. */
        content->set_position (DCPTime::from_seconds (3));
@@ -593,13 +633,15 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.60)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.60)),  80000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 337500);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.60)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.60)),  76800);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
 
-       /* Position 3s, 1.6s trim, content rate 24, DCP rate 25, both audio rates still 48k */
+       /* Position 3s, 1.6s trim, content rate 24, DCP rate 25, both audio rates still 48k.
+          1s of content is 46080 samples after resampling.
+       */
        content->set_position (DCPTime::from_seconds (3));
        content->set_trim_start (ContentTime::from_seconds (1.6));
        content->set_video_frame_rate (24);
@@ -608,11 +650,11 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.60)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),  76800);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.60)), 156800);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 414300);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.60)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  73728);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.60)), 150528);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 397728);
 
        /* Position 0, no trim, content rate 24, DCP rate 48, both audio rates still 48k.
           Now, for example, a DCPTime position of 3s means 3s at 48fps.  Since we run the video
@@ -627,9 +669,9 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.5)),  24000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.0)), 144000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
 
        /* Position 3s, no trim, content rate 24, DCP rate 48 */
        content->set_position (DCPTime::from_seconds (3));
@@ -640,11 +682,11 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)),  72000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 324000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
 
        /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
        content->set_position (DCPTime::from_seconds (3));
@@ -655,11 +697,11 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),   0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),  72000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)), 144000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 396000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),   0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
 
        /* Position 0, no trim, content rate 48, DCP rate 24
           Now, for example, a DCPTime position of 3s means 3s at 24fps.  Since we run the video
@@ -673,9 +715,9 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.5)),  24000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.0)), 144000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
 
        /* Position 3s, no trim, content rate 24, DCP rate 48 */
        content->set_position (DCPTime::from_seconds (3));
@@ -686,11 +728,11 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)),  72000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 324000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
 
        /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
        content->set_position (DCPTime::from_seconds (3));
@@ -701,15 +743,13 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),   0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),  72000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)), 144000);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 396000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),   0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
 
-       /* Position 0, no trim, video content rate = video DCP rate, content audio rate = 44.1k
-          Now 44100 content samples correspond to 1s.
-       */
+       /* Position 0, no trim, video content rate = video DCP rate, content audio rate = 44.1k */
        content->set_position (DCPTime ());
        content->set_trim_start (ContentTime ());
        content->set_video_frame_rate (24);
@@ -718,9 +758,9 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.5)),  22050);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.0)), 132300);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
 
        /* Position 3s, no trim, video content rate = video DCP rate, content audio rate = 44.1k */
        content->set_position (DCPTime::from_seconds (3));
@@ -731,11 +771,11 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)),  66150);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 297675);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
 
        /* Position 3s, 1.5s trim, video content rate = video DCP rate, content audio rate = 44.1k */
        content->set_position (DCPTime::from_seconds (3));
@@ -746,9 +786,20 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (0.50)),      0);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (3.00)),  66150);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (4.50)), 132300);
-       BOOST_CHECK_EQUAL (player->dcp_to_content_audio (piece, stream, DCPTime::from_seconds (9.75)), 363825);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
+
+       /* Check with a large start trim */
+       content->set_position (DCPTime::from_seconds (0));
+       content->set_trim_start (ContentTime::from_seconds (54143));
+       content->set_video_frame_rate (24);
+       film->set_video_frame_rate (24);
+       stream->_frame_rate = 48000;
+       player->setup_pieces ();
+       BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
+       piece = player->_pieces.front ();
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 54143L * 48000);
 }