+static
+void
+test_rewriting_sound(string name, bool modify)
+{
+ using namespace boost::filesystem;
+
+ dcp::DCP A ("test/ref/DCP/dcp_test1");
+ A.read ();
+
+ BOOST_REQUIRE (!A.cpls().empty());
+ BOOST_REQUIRE (!A.cpls().front()->reels().empty());
+ auto A_picture = dynamic_pointer_cast<dcp::ReelMonoPictureAsset>(A.cpls().front()->reels().front()->main_picture());
+ BOOST_REQUIRE (A_picture);
+ auto A_sound = dynamic_pointer_cast<dcp::ReelSoundAsset>(A.cpls().front()->reels().front()->main_sound());
+
+ string const picture = "j2c_5279f9aa-94d7-42a6-b0e0-e4eaec4e2a15.mxf";
+
+ remove_all ("build/test/" + name);
+ dcp::DCP B ("build/test/" + name);
+ auto reel = make_shared<dcp::Reel>();
+
+ BOOST_REQUIRE (A_picture->mono_asset());
+ BOOST_REQUIRE (A_picture->mono_asset()->file());
+ copy_file (A_picture->mono_asset()->file().get(), path("build") / "test" / name / picture);
+ reel->add(make_shared<dcp::ReelMonoPictureAsset>(make_shared<dcp::MonoPictureAsset>(path("build") / "test" / name / picture), 0));
+
+ auto reader = A_sound->asset()->start_read();
+ auto sound = make_shared<dcp::SoundAsset>(A_sound->asset()->edit_rate(), A_sound->asset()->sampling_rate(), A_sound->asset()->channels(), dcp::LanguageTag("en-US"), dcp::Standard::SMPTE);
+ auto writer = sound->start_write(path("build") / "test" / name / "pcm_8246f87f-e1df-4c42-a290-f3b3069ff021.mxf", {});
+
+ bool need_to_modify = modify;
+ for (int i = 0; i < A_sound->asset()->intrinsic_duration(); ++i) {
+ auto sf = reader->get_frame (i);
+ float* out[sf->channels()];
+ for (int j = 0; j < sf->channels(); ++j) {
+ out[j] = new float[sf->samples()];
+ }
+ for (int j = 0; j < sf->samples(); ++j) {
+ for (int k = 0; k < sf->channels(); ++k) {
+ out[k][j] = static_cast<float>(sf->get(k, j)) / (1 << 23);
+ if (need_to_modify) {
+ out[k][j] += 1.0 / (1 << 23);
+ need_to_modify = false;
+ }
+ }
+ }
+ writer->write (out, sf->samples());
+ for (int j = 0; j < sf->channels(); ++j) {
+ delete[] out[j];
+ }
+ }
+ writer->finalize();
+
+ reel->add(make_shared<dcp::ReelSoundAsset>(sound, 0));
+ reel->add(simple_markers());
+
+ auto cpl = make_shared<dcp::CPL>("A Test DCP", dcp::ContentKind::TRAILER, dcp::Standard::SMPTE);
+ cpl->add (reel);
+
+ B.add (cpl);
+ B.write_xml ();
+
+ dcp::EqualityOptions eq;
+ eq.reel_hashes_can_differ = true;
+ eq.max_audio_sample_error = 0;
+ if (modify) {
+ BOOST_CHECK (!A.equals(B, eq, boost::bind(¬e, _1, _2)));
+ } else {
+ BOOST_CHECK (A.equals(B, eq, boost::bind(¬e, _1, _2)));
+ }
+}
+
+/** Test comparison of a DCP with another that has the same picture and the same (but re-written) sound */
+BOOST_AUTO_TEST_CASE (dcp_test9)
+{
+ test_rewriting_sound ("dcp_test9", false);
+}
+
+/** Test comparison of a DCP with another that has the same picture and very slightly modified sound */
+BOOST_AUTO_TEST_CASE (dcp_test10)
+{
+ test_rewriting_sound ("dcp_test10", true);
+}
+