All audio content should resample if the output frame rate and content
[dcpomatic.git] / test / audio_with_specified_video_frame_rate_test.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <boost/test/unit_test.hpp>
21 #include "lib/film.h"
22 #include "lib/dcp_content_type.h"
23 #include "lib/ratio.h"
24 #include "lib/sndfile_content.h"
25 #include "lib/audio_buffers.h"
26 #include "lib/player.h"
27 #include "test.h"
28
29 using std::cout;
30 using boost::shared_ptr;
31
32 static
33 void
34 process_audio (shared_ptr<const AudioBuffers> buffers, int* samples)
35 {
36         cout << "weeeeeeeeee " << buffers->frames() << "\n";
37         *samples += buffers->frames ();
38 }
39
40 /** Test the situation where a piece of SndfileContent has its video
41  *  frame rate specified (i.e. the rate that it was prepared for),
42  *  and hence might need resampling.
43  */
44 BOOST_AUTO_TEST_CASE (audio_with_specified_video_frame_rate_test)
45 {
46         /* Make a film using staircase.wav with the DCP at 30fps and the audio specified
47            as being prepared for 29.97.
48         */
49         
50         shared_ptr<Film> film = new_test_film ("audio_with_specified_video_frame_rate_test");
51         film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR"));
52         film->set_container (Ratio::from_id ("185"));
53         film->set_name ("audio_with_specified_video_frame_rate_test");
54
55         shared_ptr<SndfileContent> content (new SndfileContent (film, "test/data/sine_440.wav"));
56         content->set_video_frame_rate (29.97);
57         film->examine_and_add_content (content);
58         
59         wait_for_jobs ();
60
61         film->set_video_frame_rate (30);
62
63         BOOST_CHECK_EQUAL (content->content_audio_frame_rate(), 48000);
64         BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952);
65 }