+
+ shared_ptr<Film> film = shared_ptr<Film> (new Film (p.string()));
+ film->write_metadata ();
+ return film;
+}
+
+void
+check_audio_file (boost::filesystem::path ref, boost::filesystem::path check)
+{
+ SF_INFO ref_info;
+ ref_info.format = 0;
+ SNDFILE* ref_file = sf_open (ref.string().c_str(), SFM_READ, &ref_info);
+ BOOST_CHECK (ref_file);
+
+ SF_INFO check_info;
+ check_info.format = 0;
+ SNDFILE* check_file = sf_open (check.string().c_str(), SFM_READ, &check_info);
+ BOOST_CHECK (check_file);
+
+ BOOST_CHECK_EQUAL (ref_info.frames, check_info.frames);
+ BOOST_CHECK_EQUAL (ref_info.samplerate, check_info.samplerate);
+ BOOST_CHECK_EQUAL (ref_info.channels, check_info.channels);
+ BOOST_CHECK_EQUAL (ref_info.format, check_info.format);
+
+ /* buffer_size is in frames */
+ sf_count_t const buffer_size = 65536 * ref_info.channels;
+ scoped_array<int32_t> ref_buffer (new int32_t[buffer_size]);
+ scoped_array<int32_t> check_buffer (new int32_t[buffer_size]);
+
+ sf_count_t N = ref_info.frames;
+ while (N) {
+ sf_count_t this_time = min (buffer_size, N);
+ sf_count_t r = sf_readf_int (ref_file, ref_buffer.get(), this_time);
+ BOOST_CHECK_EQUAL (r, this_time);
+ r = sf_readf_int (check_file, check_buffer.get(), this_time);
+ BOOST_CHECK_EQUAL (r, this_time);
+
+ for (sf_count_t i = 0; i < this_time; ++i) {
+ BOOST_REQUIRE_MESSAGE (
+ abs (ref_buffer[i] - check_buffer[i]) <= 65536,
+ ref << " differs from " << check << " at " << (ref_info.frames - N + i) << " of " << ref_info.frames
+ << "(" << ref_buffer[i] << " vs " << check_buffer[i] << ")"
+ );
+ }
+
+ N -= this_time;
+ }