Allow creation of ATMOS sync on channel 14.
[libdcp.git] / test / sound_frame_test.cc
index fa7e210368d7fcb26aedd31234a0633cd9a60e7f..d0840d8c2a7b9911bfe9f9621170ce78fe06336e 100644 (file)
@@ -1,40 +1,58 @@
 /*
-    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2019 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of libdcp.
+
+    libdcp 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,
+    libdcp 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.
+    along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of portions of this program with the
+    OpenSSL library under certain conditions as described in each
+    individual source file, and distribute linked combinations
+    including the two.
 
+    You must obey the GNU General Public License in all respects
+    for all of the code used other than OpenSSL.  If you modify
+    file(s) with this exception, you may extend this exception to your
+    version of the file(s), but you are not obligated to do so.  If you
+    do not wish to do so, delete this exception statement from your
+    version.  If you delete this exception statement from all source
+    files in the program, then also delete it here.
 */
 
 #include <boost/test/unit_test.hpp>
 #include "test.h"
 #include "sound_frame.h"
+#include "sound_asset.h"
+#include "sound_asset_reader.h"
 #include "exceptions.h"
 #include <sndfile.h>
 
+using boost::shared_ptr;
+
 BOOST_AUTO_TEST_CASE (sound_frame_test)
 {
        int const frame_length = 2000;
        int const channels = 6;
 
-       dcp::SoundFrame frame (
-               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",
-               42,
-               0
+       dcp::SoundAsset asset (
+               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"
                );
 
-       BOOST_REQUIRE_EQUAL (frame.size(), channels * frame_length * 3);
+       shared_ptr<const dcp::SoundFrame> frame = asset.start_read()->get_frame(42);
+
+       BOOST_REQUIRE_EQUAL (frame->size(), channels * frame_length * 3);
 
        boost::filesystem::path ref_file = private_test / "data" / "frame.wav";
        SF_INFO info;
@@ -46,7 +64,7 @@ BOOST_AUTO_TEST_CASE (sound_frame_test)
        int const read = sf_readf_int (sndfile, ref_data, frame_length);
        BOOST_REQUIRE_EQUAL (read, frame_length);
 
-       uint8_t const * p = frame.data ();
+       uint8_t const * p = frame->data ();
        for (int i = 0; i < (frame_length * channels); ++i) {
                int x = ref_data[i] >> 8;
                if (x < 0) {
@@ -60,11 +78,12 @@ BOOST_AUTO_TEST_CASE (sound_frame_test)
 
 BOOST_AUTO_TEST_CASE (sound_frame_test2)
 {
-       BOOST_CHECK_THROW (dcp::SoundFrame ("frobozz", 42, 0), dcp::FileError);
-       BOOST_CHECK_THROW (dcp::SoundFrame (
-                                  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",
-                                  999999999, 0
-                                  ), dcp::DCPReadError
+       BOOST_CHECK_THROW (dcp::SoundAsset("frobozz"), dcp::FileError);
+
+       dcp::SoundAsset asset (
+               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"
                );
+
+       BOOST_CHECK_THROW (asset.start_read()->get_frame (99999999), dcp::ReadError);
 }