+
+
+float
+AudioAnalysis::gain_correction (shared_ptr<const Playlist> playlist)
+{
+ if (playlist->content().size() == 1 && analysis_gain ()) {
+ /* In this case we know that the analysis was of a single piece of content and
+ we know that content's gain when the analysis was run. Hence we can work out
+ what correction is now needed to make it look `right'.
+ */
+ DCPOMATIC_ASSERT (playlist->content().front()->audio);
+ return playlist->content().front()->audio->gain() - analysis_gain().get();
+ }
+
+ return 0.0f;
+}
+
+
+/** @return Peak across all channels, and the channel number it is on */
+pair<AudioAnalysis::PeakTime, int>
+AudioAnalysis::overall_sample_peak () const
+{
+ DCPOMATIC_ASSERT (!_sample_peak.empty());
+
+ optional<PeakTime> pt;
+ int c = 0;
+
+ for (size_t i = 0; i < _sample_peak.size(); ++i) {
+ if (!pt || _sample_peak[i].peak > pt->peak) {
+ pt = _sample_peak[i];
+ c = i;
+ }
+ }
+
+ return make_pair (pt.get(), c);
+}
+
+
+optional<float>
+AudioAnalysis::overall_true_peak () const
+{
+ optional<float> p;
+
+ for (auto i: _true_peak) {
+ if (!p || i > *p) {
+ p = i;
+ }
+ }
+
+ return p;
+}
+