2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include <boost/test/unit_test.hpp>
21 #include <boost/bind.hpp>
22 #include <boost/function.hpp>
23 #include <boost/signals2.hpp>
24 #include "lib/audio_merger.h"
25 #include "lib/audio_buffers.h"
27 using boost::shared_ptr;
30 static shared_ptr<const AudioBuffers> last_audio;
32 BOOST_AUTO_TEST_CASE (audio_merger_test1)
34 int const frame_rate = 48000;
35 AudioMerger merger (1, frame_rate);
37 /* Push 64 samples, 0 -> 63 at time 0 */
38 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
39 for (int i = 0; i < 64; ++i) {
40 buffers->data()[0][i] = i;
42 merger.push (buffers, DCPTime ());
44 /* Push 64 samples, 0 -> 63 at time 22 */
45 merger.push (buffers, DCPTime::from_frames (22, frame_rate));
47 TimedAudioBuffers<DCPTime> tb = merger.pull (DCPTime::from_frames (22, frame_rate));
48 BOOST_CHECK (tb.audio != shared_ptr<const AudioBuffers> ());
49 BOOST_CHECK_EQUAL (tb.audio->frames(), 22);
50 BOOST_CHECK_EQUAL (tb.time, DCPTime ());
52 /* And they should be a staircase */
53 for (int i = 0; i < 22; ++i) {
54 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i);
59 /* That flush should give us 64 samples at 22 */
60 BOOST_CHECK_EQUAL (tb.audio->frames(), 64);
61 BOOST_CHECK_EQUAL (tb.time, DCPTime::from_frames (22, frame_rate));
63 /* Check the sample values */
64 for (int i = 0; i < 64; ++i) {
69 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], correct);
73 BOOST_AUTO_TEST_CASE (audio_merger_test2)
75 int const frame_rate = 48000;
76 AudioMerger merger (1, frame_rate);
78 /* Push 64 samples, 0 -> 63 at time 9 */
79 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
80 for (int i = 0; i < 64; ++i) {
81 buffers->data()[0][i] = i;
83 merger.push (buffers, DCPTime::from_frames (9, frame_rate));
85 TimedAudioBuffers<DCPTime> tb = merger.pull (DCPTime::from_frames (9, frame_rate));
86 BOOST_CHECK_EQUAL (tb.audio->frames(), 9);
87 BOOST_CHECK_EQUAL (tb.time, DCPTime ());
89 for (int i = 0; i < 9; ++i) {
90 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], 0);
95 /* That flush should give us 64 samples at 9 */
96 BOOST_CHECK_EQUAL (tb.audio->frames(), 64);
97 BOOST_CHECK_EQUAL (tb.time, DCPTime::from_frames (9, frame_rate));
99 /* Check the sample values */
100 for (int i = 0; i < 64; ++i) {
101 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i);