Accessor for ClosedCaptionsDialog.
[dcpomatic.git] / src / lib / audio_analysis.cc
index 022c5935d1a6b305fbdd3fbdd9652b587d3acb0a..13917cb5f6d693f3987b0c8adb85526a6426747c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -46,8 +46,9 @@ using boost::shared_ptr;
 using boost::optional;
 using boost::dynamic_pointer_cast;
 using dcp::raw_convert;
+using namespace dcpomatic;
 
-int const AudioAnalysis::_current_state_version = 2;
+int const AudioAnalysis::_current_state_version = 3;
 
 AudioAnalysis::AudioAnalysis (int channels)
 {
@@ -90,6 +91,8 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
        _loudness_range = f.optional_number_child<float> ("LoudnessRange");
 
        _analysis_gain = f.optional_number_child<double> ("AnalysisGain");
+       _samples_per_point = f.number_child<int64_t> ("SamplesPerPoint");
+       _sample_rate = f.number_child<int64_t> ("SampleRate");
 }
 
 void
@@ -156,6 +159,9 @@ AudioAnalysis::write (boost::filesystem::path filename)
                root->add_child("AnalysisGain")->add_child_text (raw_convert<string> (_analysis_gain.get ()));
        }
 
+       root->add_child("SamplesPerPoint")->add_child_text (raw_convert<string> (_samples_per_point));
+       root->add_child("SampleRate")->add_child_text (raw_convert<string> (_sample_rate));
+
        doc->write_to_file_formatted (filename.string ());
 }
 
@@ -178,8 +184,10 @@ AudioAnalysis::gain_correction (shared_ptr<const Playlist> playlist)
 pair<AudioAnalysis::PeakTime, int>
 AudioAnalysis::overall_sample_peak () const
 {
+       DCPOMATIC_ASSERT (!_sample_peak.empty ());
+
        optional<PeakTime> pt;
-       int c;
+       int c = 0;
 
        for (size_t i = 0; i < _sample_peak.size(); ++i) {
                if (!pt || _sample_peak[i].peak > pt->peak) {