2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef DCPOMATIC_AUDIO_ANALYSIS_H
23 #define DCPOMATIC_AUDIO_ANALYSIS_H
26 #include "dcpomatic_time.h"
27 #include "audio_point.h"
28 #include <libcxml/cxml.h>
29 #include <boost/optional.hpp>
30 #include <boost/filesystem.hpp>
45 explicit AudioAnalysis (int c);
46 explicit AudioAnalysis (boost::filesystem::path);
48 void add_point (int c, AudioPoint const & p);
51 PeakTime (float p, dcpomatic::DCPTime t)
57 dcpomatic::DCPTime time;
60 void set_sample_peak (std::vector<PeakTime> peak) {
64 void set_true_peak (std::vector<float> peak) {
68 void set_integrated_loudness (float l) {
69 _integrated_loudness = l;
72 void set_loudness_range (float r) {
76 AudioPoint get_point (int c, int p) const;
77 int points (int c) const;
78 int channels () const;
80 std::vector<PeakTime> sample_peak () const {
84 std::pair<PeakTime, int> overall_sample_peak () const;
86 std::vector<float> true_peak () const {
90 boost::optional<float> overall_true_peak () const;
92 boost::optional<float> integrated_loudness () const {
93 return _integrated_loudness;
96 boost::optional<float> loudness_range () const {
97 return _loudness_range;
100 boost::optional<double> analysis_gain () const {
101 return _analysis_gain;
104 void set_analysis_gain (double gain) {
105 _analysis_gain = gain;
108 int64_t samples_per_point () const {
109 return _samples_per_point;
112 void set_samples_per_point (int64_t spp) {
113 _samples_per_point = spp;
116 int sample_rate () const {
120 void set_sample_rate (int sr) {
124 void set_leqm (double leqm) {
128 boost::optional<double> leqm () const {
132 void write (boost::filesystem::path);
134 float gain_correction (std::shared_ptr<const Playlist> playlist);
137 std::vector<std::vector<AudioPoint>> _data;
138 std::vector<PeakTime> _sample_peak;
139 std::vector<float> _true_peak;
140 boost::optional<float> _integrated_loudness;
141 boost::optional<float> _loudness_range;
142 boost::optional<double> _leqm;
143 /** If this analysis was run on a single piece of
144 * content we store its gain in dB when the analysis
147 boost::optional<double> _analysis_gain;
148 int64_t _samples_per_point = 0;
149 int _sample_rate = 0;
151 static int const _current_state_version;