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;
38 BOOST_AUTO_TEST_CASE (audio_merger_test1)
40 AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1));
42 /* Push 64 samples, 0 -> 63 at time 0 */
43 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
44 for (int i = 0; i < 64; ++i) {
45 buffers->data()[0][i] = i;
47 merger.push (buffers, 0);
49 /* Push 64 samples, 0 -> 63 at time 22 */
50 merger.push (buffers, 22);
52 TimedAudioBuffers<int> tb = merger.pull (22);
53 BOOST_CHECK (tb.audio != shared_ptr<const AudioBuffers> ());
54 BOOST_CHECK_EQUAL (tb.audio->frames(), 22);
55 BOOST_CHECK_EQUAL (tb.time, 0);
57 /* And they should be a staircase */
58 for (int i = 0; i < 22; ++i) {
59 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i);
64 /* That flush should give us 64 samples at 22 */
65 BOOST_CHECK_EQUAL (tb.audio->frames(), 64);
66 BOOST_CHECK_EQUAL (tb.time, 22);
68 /* Check the sample values */
69 for (int i = 0; i < 64; ++i) {
74 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], correct);
78 BOOST_AUTO_TEST_CASE (audio_merger_test2)
80 AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1));
82 /* Push 64 samples, 0 -> 63 at time 9 */
83 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
84 for (int i = 0; i < 64; ++i) {
85 buffers->data()[0][i] = i;
87 merger.push (buffers, 9);
89 TimedAudioBuffers<int> tb = merger.pull (9);
90 BOOST_CHECK_EQUAL (tb.audio->frames(), 9);
91 BOOST_CHECK_EQUAL (tb.time, 0);
93 for (int i = 0; i < 9; ++i) {
94 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], 0);
99 /* That flush should give us 64 samples at 9 */
100 BOOST_CHECK_EQUAL (tb.audio->frames(), 64);
101 BOOST_CHECK_EQUAL (tb.time, 9);
103 /* Check the sample values */
104 for (int i = 0; i < 64; ++i) {
105 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i);