Add simple support for generating audio MXFs from part of a WAV file (for multi-reel...
authorCarl Hetherington <cth@carlh.net>
Sat, 12 Jan 2013 19:26:57 +0000 (19:26 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 12 Jan 2013 19:26:57 +0000 (19:26 +0000)
examples/make_dcp.cc
run-tests.sh
src/dcp.cc
src/reel.cc
src/sound_asset.cc
src/sound_asset.h
test/tests.cc

index e1d8353bc3e79f0a6449fc8bd8a302ddc090cbe8..68e3f4f92c4b5a3e68d75110239497afc944f3ae 100644 (file)
@@ -93,7 +93,7 @@ main ()
 
        /* Now we can create the sound asset using these files */
        boost::shared_ptr<libdcp::SoundAsset> sound_asset (
-               new libdcp::SoundAsset (sound_files, "My Film DCP", "audio.mxf", 0, 24, 48)
+               new libdcp::SoundAsset (sound_files, "My Film DCP", "audio.mxf", 0, 24, 48, 0)
                );
 
        /* Now that we have the assets, we can create a Reel to put them in and add it to the CPL */
index 3c92dae0ef04c369f744f7307ffb89c4191e64ee..7e4643290b7147f8e931fb0948d54178e32c6110 100755 (executable)
@@ -10,6 +10,9 @@
 if [ "$1" == "--debug" ]; then
   shift
   LD_LIBRARY_PATH=build/src:build/asdcplib/src gdb --args build/test/tests
+elif [ "$1" == "--valgrind" ]; then
+  shift
+  LD_LIBRARY_PATH=build/src:build/asdcplib/src valgrind --tool="memcheck" build/test/tests
 else
   LD_LIBRARY_PATH=build/src:build/asdcplib/src build/test/tests
 fi
index a5e21d9f50a70c5ce035b3829726e429f76ad66d..03c1cdc2782c0329114b85708e32175aa98ac7d3 100644 (file)
@@ -457,9 +457,7 @@ CPL::write_xml () const
                (*i)->write_to_cpl (os);
        }
 
-       os << "      </AssetList>\n"
-          << "    </Reel>\n"
-          << "  </ReelList>\n"
+       os << "  </ReelList>\n"
           << "</CompositionPlaylist>\n";
 
        os.close ();
index 52a4f0fbd0a1c014c91a51e98d8c70006e5ad91c..8995f874ab8b710ac170d7dc98ecf2cc4de4e13a 100644 (file)
@@ -44,6 +44,9 @@ Reel::write_to_cpl (ostream& s) const
        if (_main_subtitle) {
                _main_subtitle->write_to_cpl (s);
        }
+
+       s << "      </AssetList>\n"
+         << "    </Reel>\n";
 }
        
 bool
index e987239a498eef3686a8cd80d00f249f4e07e831..98266b2805d486164f75545b6b5dd67b98ce2e8d 100644 (file)
@@ -42,12 +42,15 @@ using boost::lexical_cast;
 using namespace libdcp;
 
 SoundAsset::SoundAsset (
-       vector<string> const & files, string directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int length
+       vector<string> const & files, string directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int length, int start_frame
        )
        : MXFAsset (directory, mxf_name, progress, fps, 0, length)
        , _channels (files.size ())
        , _sampling_rate (0)
+       , _start_frame (start_frame)
 {
+       assert (_channels);
+       
        construct (boost::bind (&SoundAsset::path_from_channel, this, _1, files));
 }
 
@@ -56,18 +59,22 @@ SoundAsset::SoundAsset (
        string directory,
        string mxf_name,
        boost::signals2::signal<void (float)>* progress,
-       int fps, int length, int channels
+       int fps, int length, int start_frame, int channels
        )
        : MXFAsset (directory, mxf_name, progress, fps, 0, length)
        , _channels (channels)
        , _sampling_rate (0)
+       , _start_frame (start_frame)
 {
+       assert (_channels);
+       
        construct (get_path);
 }
 
 SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int entry_point, int length)
        : MXFAsset (directory, mxf_name, 0, fps, entry_point, length)
        , _channels (0)
+       , _start_frame (0)
 {
        ASDCP::PCM::MXFReader reader;
        if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
@@ -96,7 +103,7 @@ void
 SoundAsset::construct (boost::function<string (Channel)> get_path)
 {
        ASDCP::Rational asdcp_fps (_fps, 1);
-       
+
        ASDCP::PCM::WAVParser pcm_parser_channel[_channels];
        if (pcm_parser_channel[0].OpenRead (get_path(LEFT).c_str(), asdcp_fps)) {
                throw FileError ("could not open WAV file for reading", get_path(LEFT));
@@ -153,6 +160,15 @@ SoundAsset::construct (boost::function<string (Channel)> get_path)
                throw FileError ("could not open audio MXF for writing", path().string());
        }
 
+       /* Skip through up to our _start_frame; this is pretty inefficient... */
+       for (int i = 0; i < _start_frame; ++i) {
+               for (int j = 0; j < _channels; ++j) {
+                       if (ASDCP_FAILURE (pcm_parser_channel[j].ReadFrame (frame_buffer_channel[j]))) {
+                               throw MiscError ("could not read audio frame");
+                       }
+               }
+       }
+       
        for (int i = 0; i < _length; ++i) {
 
                for (int j = 0; j < _channels; ++j) {
index 3189c0674471d08141bbb45d4e301155dc38936f..9fb1d60b2581bbcc6ff1becef0d4becd2bbcc8e4 100644 (file)
@@ -44,6 +44,7 @@ public:
         *  @param progress Signal to inform of progress.
         *  @param fps Frames per second.
         *  @param length Length in frames.
+        *  @param start_frame Frame in the source to start writing from.
         */
        SoundAsset (
                std::vector<std::string> const & files,
@@ -51,7 +52,8 @@ public:
                std::string mxf_name,
                boost::signals2::signal<void (float)>* progress,
                int fps,
-               int length
+               int length,
+               int start_frame
                );
 
        /** Construct a SoundAsset, generating the MXF from some WAV files.
@@ -62,6 +64,7 @@ public:
         *  @param progress Signal to inform of progress.
         *  @param fps Frames per second.
         *  @param length Length in frames.
+        *  @param start_frame Frame in the source to start writing from.
         *  @param channels Number of audio channels.
         */
        SoundAsset (
@@ -71,6 +74,7 @@ public:
                boost::signals2::signal<void (float)>* progress,
                int fps,
                int length,
+               int start_frame,
                int channels
                );
 
@@ -106,6 +110,7 @@ private:
        /** Number of channels in the asset */
        int _channels;
        int _sampling_rate;
+       int _start_frame;
 };
 
 }
index ef25b7c8d6fb85eb9ef84a9f390da2636b01e47e..be960699d5870350655d7fd170aedec785b397d8 100644 (file)
@@ -86,6 +86,7 @@ BOOST_AUTO_TEST_CASE (dcp_test)
                                                   &(d.Progress),
                                                   24,
                                                   24,
+                                                  0,
                                                   2
                                                   ));
        
@@ -102,7 +103,7 @@ BOOST_AUTO_TEST_CASE (error_test)
        p.push_back ("frobozz");
 
        BOOST_CHECK_THROW (new libdcp::MonoPictureAsset (p, "build/test/bar", "video.mxf", &d.Progress, 24, 24, 32, 32), libdcp::FileError);
-       BOOST_CHECK_THROW (new libdcp::SoundAsset (p, "build/test/bar", "audio.mxf", &d.Progress, 24, 24), libdcp::FileError);
+       BOOST_CHECK_THROW (new libdcp::SoundAsset (p, "build/test/bar", "audio.mxf", &d.Progress, 24, 24, 0), libdcp::FileError);
 }
 
 BOOST_AUTO_TEST_CASE (read_dcp)