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;
39 BOOST_AUTO_TEST_CASE (audio_merger_test1)
41 AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1));
43 /* Push 64 samples, 0 -> 63 at time 0 */
44 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
45 for (int i = 0; i < 64; ++i) {
46 buffers->data()[0][i] = i;
48 TimedAudioBuffers<int> tb = merger.push (buffers, 0);
50 /* That should not have caused an emission */
51 BOOST_CHECK_EQUAL (tb.audio, shared_ptr<const AudioBuffers> ());
52 BOOST_CHECK_EQUAL (tb.time, 0);
54 /* Push 64 samples, 0 -> 63 at time 22 */
55 tb = merger.push (buffers, 22);
57 /* That should have caused an emission of 22 samples at 0 */
58 BOOST_CHECK (tb.audio != shared_ptr<const AudioBuffers> ());
59 BOOST_CHECK_EQUAL (tb.audio->frames(), 22);
60 BOOST_CHECK_EQUAL (tb.time, 0);
62 /* And they should be a staircase */
63 for (int i = 0; i < 22; ++i) {
64 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i);
69 /* That flush should give us 64 samples at 22 */
70 BOOST_CHECK_EQUAL (tb.audio->frames(), 64);
71 BOOST_CHECK_EQUAL (tb.time, 22);
73 /* Check the sample values */
74 for (int i = 0; i < 64; ++i) {
79 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], correct);
83 BOOST_AUTO_TEST_CASE (audio_merger_test2)
85 AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1));
87 /* Push 64 samples, 0 -> 63 at time 9 */
88 shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
89 for (int i = 0; i < 64; ++i) {
90 buffers->data()[0][i] = i;
92 TimedAudioBuffers<int> tb = merger.push (buffers, 9);
94 /* That flush should give us 9 samples at 0 */
95 BOOST_CHECK_EQUAL (tb.audio->frames(), 9);
96 BOOST_CHECK_EQUAL (tb.time, 0);
98 for (int i = 0; i < 9; ++i) {
99 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], 0);
102 tb = merger.flush ();
104 /* That flush should give us 64 samples at 9 */
105 BOOST_CHECK_EQUAL (tb.audio->frames(), 64);
106 BOOST_CHECK_EQUAL (tb.time, 9);
108 /* Check the sample values */
109 for (int i = 0; i < 64; ++i) {
110 BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i);