summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-27 18:25:11 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-27 18:25:11 +0100
commit65379c3a9d78ae627519c0820c0814db0083f8af (patch)
treeffef68bf4de9b9cf957abbe67aad0e43363664b7 /test
parent4e4b758bb59cde29fcd85ed1a59a42a32536f230 (diff)
Extract audio merging code from Player.
Diffstat (limited to 'test')
-rw-r--r--test/audio_merger_test.cc134
-rw-r--r--test/wscript3
2 files changed, 136 insertions, 1 deletions
diff --git a/test/audio_merger_test.cc b/test/audio_merger_test.cc
new file mode 100644
index 000000000..9c3fd3a30
--- /dev/null
+++ b/test/audio_merger_test.cc
@@ -0,0 +1,134 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/test/unit_test.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/signals2.hpp>
+#include "lib/audio_merger.h"
+#include "lib/audio_buffers.h"
+
+using boost::shared_ptr;
+using boost::bind;
+
+static shared_ptr<const AudioBuffers> last_audio;
+static int last_time;
+
+static int
+pass_through (int x)
+{
+ return x;
+}
+
+static void
+process_audio (shared_ptr<const AudioBuffers> audio, int time)
+{
+ last_audio = audio;
+ last_time = time;
+}
+
+static void
+reset ()
+{
+ last_audio.reset ();
+ last_time = 0;
+}
+
+BOOST_AUTO_TEST_CASE (audio_merger_test1)
+{
+ AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1));
+ merger.Audio.connect (bind (&process_audio, _1, _2));
+
+ reset ();
+
+ /* Push 64 samples, 0 -> 63 at time 0 */
+ shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
+ for (int i = 0; i < 64; ++i) {
+ buffers->data()[0][i] = i;
+ }
+ merger.push (buffers, 0);
+
+ /* That should not have caused an emission */
+ BOOST_CHECK_EQUAL (last_audio, shared_ptr<const AudioBuffers> ());
+ BOOST_CHECK_EQUAL (last_time, 0);
+
+ /* Push 64 samples, 0 -> 63 at time 22 */
+ merger.push (buffers, 22);
+
+ /* That should have caused an emission of 22 samples at 0 */
+ BOOST_CHECK (last_audio != shared_ptr<const AudioBuffers> ());
+ BOOST_CHECK_EQUAL (last_audio->frames(), 22);
+ BOOST_CHECK_EQUAL (last_time, 0);
+
+ /* And they should be a staircase */
+ for (int i = 0; i < 22; ++i) {
+ BOOST_CHECK_EQUAL (last_audio->data()[0][i], i);
+ }
+
+ reset ();
+ merger.flush ();
+
+ /* That flush should give us 64 samples at 22 */
+ BOOST_CHECK_EQUAL (last_audio->frames(), 64);
+ BOOST_CHECK_EQUAL (last_time, 22);
+
+ /* Check the sample values */
+ for (int i = 0; i < 64; ++i) {
+ int correct = i;
+ if (i < (64 - 22)) {
+ correct += i + 22;
+ }
+ BOOST_CHECK_EQUAL (last_audio->data()[0][i], correct);
+ }
+}
+
+BOOST_AUTO_TEST_CASE (audio_merger_test2)
+{
+ AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1));
+ merger.Audio.connect (bind (&process_audio, _1, _2));
+
+ reset ();
+
+ /* Push 64 samples, 0 -> 63 at time 9 */
+ shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64));
+ for (int i = 0; i < 64; ++i) {
+ buffers->data()[0][i] = i;
+ }
+ merger.push (buffers, 9);
+
+ /* That flush should give us 9 samples at 0 */
+ BOOST_CHECK_EQUAL (last_audio->frames(), 9);
+ BOOST_CHECK_EQUAL (last_time, 0);
+
+ for (int i = 0; i < 9; ++i) {
+ BOOST_CHECK_EQUAL (last_audio->data()[0][i], 0);
+ }
+
+ reset ();
+ merger.flush ();
+
+ /* That flush should give us 64 samples at 9 */
+ BOOST_CHECK_EQUAL (last_audio->frames(), 64);
+ BOOST_CHECK_EQUAL (last_time, 9);
+
+ /* Check the sample values */
+ for (int i = 0; i < 64; ++i) {
+ BOOST_CHECK_EQUAL (last_audio->data()[0][i], i);
+ }
+}
diff --git a/test/wscript b/test/wscript
index fef1584f3..0fcb185f8 100644
--- a/test/wscript
+++ b/test/wscript
@@ -16,12 +16,13 @@ def build(bld):
obj.use = 'libdcpomatic'
obj.source = """
test.cc
+ silence_padding_test.cc
+ audio_merger_test.cc
resampler_test.cc
ffmpeg_audio_test.cc
threed_test.cc
play_test.cc
frame_rate_test.cc
- silence_padding_test.cc
audio_delay_test.cc
ffmpeg_pts_offset.cc
ffmpeg_examiner_test.cc