2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
20 #include <boost/test/unit_test.hpp>
22 #include "sound_frame.h"
23 #include "sound_asset.h"
24 #include "sound_asset_reader.h"
25 #include "exceptions.h"
28 using boost::shared_ptr;
30 BOOST_AUTO_TEST_CASE (sound_frame_test)
32 int const frame_length = 2000;
33 int const channels = 6;
35 dcp::SoundAsset asset (
36 private_test / "TONEPLATES-SMPTE-PLAINTEXT_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV/pcm_95734608-5d47-4d3f-bf5f-9e9186b66afa_.mxf"
39 shared_ptr<const dcp::SoundFrame> frame = asset.start_read()->get_frame(42);
41 BOOST_REQUIRE_EQUAL (frame->size(), channels * frame_length * 3);
43 boost::filesystem::path ref_file = private_test / "data" / "frame.wav";
46 SNDFILE* sndfile = sf_open (ref_file.string().c_str(), SFM_READ, &info);
47 BOOST_REQUIRE (sndfile);
49 int ref_data[frame_length * channels];
50 int const read = sf_readf_int (sndfile, ref_data, frame_length);
51 BOOST_REQUIRE_EQUAL (read, frame_length);
53 uint8_t const * p = frame->data ();
54 for (int i = 0; i < (frame_length * channels); ++i) {
55 int x = ref_data[i] >> 8;
59 int const y = p[0] | (p[1] << 8) | (p[2] << 16);
60 BOOST_REQUIRE_EQUAL (x, y);
65 BOOST_AUTO_TEST_CASE (sound_frame_test2)
67 BOOST_CHECK_THROW (dcp::SoundAsset("frobozz"), dcp::FileError);
69 dcp::SoundAsset asset (
71 "TONEPLATES-SMPTE-PLAINTEXT_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV/pcm_95734608-5d47-4d3f-bf5f-9e9186b66afa_.mxf"
74 BOOST_CHECK_THROW (asset.start_read()->get_frame (99999999), dcp::DCPReadError);