2 Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "lib/audio_merger.h"
22 #include "lib/audio_buffers.h"
23 #include <boost/test/unit_test.hpp>
24 #include <boost/bind.hpp>
25 #include <boost/function.hpp>
26 #include <boost/signals2.hpp>
29 using boost::shared_ptr;
32 static shared_ptr<const AudioBuffers> last_audio;
34 int const sampling_rate = 48000;
36 BOOST_AUTO_TEST_CASE (audio_merger_test1)
38 AudioMerger merger (1, sampling_rate);
40 /* Push 64 samples, 0 -> 63 at time 0 */
41 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
42 for (int i = 0; i < 64; ++i) {
43 buffers->data()[0][i] = i;
45 merger.push (buffers, DCPTime());
47 /* Push 64 samples, 0 -> 63 at time 22 */
48 merger.push (buffers, DCPTime::from_frames (22, sampling_rate));
50 pair<shared_ptr<AudioBuffers>, DCPTime> tb = merger.pull (DCPTime::from_frames (22, sampling_rate));
51 BOOST_CHECK (tb.first != shared_ptr<const AudioBuffers> ());
52 BOOST_CHECK_EQUAL (tb.first->frames(), 22);
53 BOOST_CHECK_EQUAL (tb.second.get(), 0);
55 /* And they should be a staircase */
56 for (int i = 0; i < 22; ++i) {
57 BOOST_CHECK_EQUAL (tb.first->data()[0][i], i);
60 tb = merger.pull (DCPTime::from_frames (22 + 64, sampling_rate));
62 BOOST_CHECK_EQUAL (tb.first->frames(), 64);
63 BOOST_CHECK_EQUAL (tb.second.get(), DCPTime::from_frames(22, sampling_rate).get());
65 /* Check the sample values */
66 for (int i = 0; i < 64; ++i) {
71 BOOST_CHECK_EQUAL (tb.first->data()[0][i], correct);
75 BOOST_AUTO_TEST_CASE (audio_merger_test2)
77 AudioMerger merger (1, sampling_rate);
79 /* Push 64 samples, 0 -> 63 at time 9 */
80 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
81 for (int i = 0; i < 64; ++i) {
82 buffers->data()[0][i] = i;
84 merger.push (buffers, DCPTime::from_frames (9, sampling_rate));
86 pair<shared_ptr<AudioBuffers>, DCPTime> tb = merger.pull (DCPTime::from_frames (9, sampling_rate));
87 BOOST_CHECK_EQUAL (tb.first->frames(), 9);
88 BOOST_CHECK_EQUAL (tb.second.get(), 0);
90 for (int i = 0; i < 9; ++i) {
91 BOOST_CHECK_EQUAL (tb.first->data()[0][i], 0);
94 tb = merger.pull (DCPTime::from_frames (9 + 64, sampling_rate));
96 BOOST_CHECK_EQUAL (tb.first->frames(), 64);
97 BOOST_CHECK_EQUAL (tb.second.get(), DCPTime::from_frames(9, sampling_rate).get());
99 /* Check the sample values */
100 for (int i = 0; i < 64; ++i) {
101 BOOST_CHECK_EQUAL (tb.first->data()[0][i], i);