C++11 tidying.
[dcpomatic.git] / src / lib / audio_analysis.h
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #ifndef DCPOMATIC_AUDIO_ANALYSIS_H
23 #define DCPOMATIC_AUDIO_ANALYSIS_H
24
25
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>
31 #include <vector>
32
33
34 namespace xmlpp {
35         class Element;
36 }
37
38
39 class Playlist;
40
41
42 class AudioAnalysis
43 {
44 public:
45         explicit AudioAnalysis (int c);
46         explicit AudioAnalysis (boost::filesystem::path);
47
48         void add_point (int c, AudioPoint const & p);
49
50         struct PeakTime {
51                 PeakTime (float p, dcpomatic::DCPTime t)
52                         : peak (p)
53                         , time (t)
54                 {}
55
56                 float peak;
57                 dcpomatic::DCPTime time;
58         };
59
60         void set_sample_peak (std::vector<PeakTime> peak) {
61                 _sample_peak = peak;
62         }
63
64         void set_true_peak (std::vector<float> peak) {
65                 _true_peak = peak;
66         }
67
68         void set_integrated_loudness (float l) {
69                 _integrated_loudness = l;
70         }
71
72         void set_loudness_range (float r) {
73                 _loudness_range = r;
74         }
75
76         AudioPoint get_point (int c, int p) const;
77         int points (int c) const;
78         int channels () const;
79
80         std::vector<PeakTime> sample_peak () const {
81                 return _sample_peak;
82         }
83
84         std::pair<PeakTime, int> overall_sample_peak () const;
85
86         std::vector<float> true_peak () const {
87                 return _true_peak;
88         }
89
90         boost::optional<float> overall_true_peak () const;
91
92         boost::optional<float> integrated_loudness () const {
93                 return _integrated_loudness;
94         }
95
96         boost::optional<float> loudness_range () const {
97                 return _loudness_range;
98         }
99
100         boost::optional<double> analysis_gain () const {
101                 return _analysis_gain;
102         }
103
104         void set_analysis_gain (double gain) {
105                 _analysis_gain = gain;
106         }
107
108         int64_t samples_per_point () const {
109                 return _samples_per_point;
110         }
111
112         void set_samples_per_point (int64_t spp) {
113                 _samples_per_point = spp;
114         }
115
116         int sample_rate () const {
117                 return _sample_rate;
118         }
119
120         void set_sample_rate (int sr) {
121                 _sample_rate = sr;
122         }
123
124         void set_leqm (double leqm) {
125                 _leqm = leqm;
126         }
127
128         boost::optional<double> leqm () const {
129                 return _leqm;
130         }
131
132         void write (boost::filesystem::path);
133
134         float gain_correction (std::shared_ptr<const Playlist> playlist);
135
136 private:
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
145          *  happened.
146          */
147         boost::optional<double> _analysis_gain;
148         int64_t _samples_per_point = 0;
149         int _sample_rate = 0;
150
151         static int const _current_state_version;
152 };
153
154
155 #endif