Include tidying src/lib/a-j*.h
[dcpomatic.git] / src / lib / analyse_audio_job.cc
index b17dd07dcb0869cb1891aecbe7068319a433a1f0..e997c03c57b729ce274ec46b0a49a63ca8d9bd81 100644 (file)
@@ -23,6 +23,7 @@
 #include "compose.hpp"
 #include "film.h"
 #include "player.h"
+#include "playlist.h"
 #include <boost/foreach.hpp>
 
 #include "i18n.h"
@@ -36,9 +37,9 @@ using boost::dynamic_pointer_cast;
 
 int const AnalyseAudioJob::_num_points = 1024;
 
-AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> f, shared_ptr<const Playlist> p)
-       : Job (f)
-       , _playlist (p)
+AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist)
+       : Job (film)
+       , _playlist (playlist)
        , _done (0)
        , _samples_per_point (1)
        , _overall_peak (0)
@@ -64,15 +65,15 @@ AnalyseAudioJob::run ()
 {
        shared_ptr<Player> player (new Player (_film, _playlist));
        player->set_ignore_video ();
-       
-       int64_t const len = _film->length().frames (_film->audio_frame_rate());
+
+       int64_t const len = _playlist->length().frames_round (_film->audio_frame_rate());
        _samples_per_point = max (int64_t (1), len / _num_points);
 
        _current.resize (_film->audio_channels ());
        _analysis.reset (new AudioAnalysis (_film->audio_channels ()));
 
        bool has_any_audio = false;
-       BOOST_FOREACH (shared_ptr<Content> c, _film->content ()) {
+       BOOST_FOREACH (shared_ptr<Content> c, _playlist->content ()) {
                if (dynamic_pointer_cast<AudioContent> (c)) {
                        has_any_audio = true;
                }
@@ -88,8 +89,18 @@ AnalyseAudioJob::run ()
        }
 
        _analysis->set_peak (_overall_peak, DCPTime::from_frames (_overall_peak_frame, _film->audio_frame_rate ()));
+
+       if (_playlist->content().size() == 1) {
+               /* If there was only one piece of content in this analysis we may later need to know what its
+                  gain was when we analysed it.
+               */
+               shared_ptr<const AudioContent> ac = dynamic_pointer_cast<const AudioContent> (_playlist->content().front ());
+               DCPOMATIC_ASSERT (ac);
+               _analysis->set_analysis_gain (ac->audio_gain ());
+       }
+
        _analysis->write (_film->audio_analysis_path (_playlist));
-       
+
        set_progress (1);
        set_state (FINISHED_OK);
 }
@@ -128,4 +139,3 @@ AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b)
                ++_done;
        }
 }
-