Rename SafeStringStream -> locked_stringstream. Bump deps for removal of stringstream.
[dcpomatic.git] / src / lib / audio_analysis.h
1 /*
2     Copyright (C) 2012-2015 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 #ifndef DCPOMATIC_AUDIO_ANALYSIS_H
22 #define DCPOMATIC_AUDIO_ANALYSIS_H
23
24 #include "dcpomatic_time.h"
25 #include "audio_point.h"
26 #include <libcxml/cxml.h>
27 #include <boost/optional.hpp>
28 #include <boost/filesystem.hpp>
29 #include <vector>
30
31 namespace xmlpp {
32         class Element;
33 }
34
35 class Playlist;
36
37 class AudioAnalysis : public boost::noncopyable
38 {
39 public:
40         AudioAnalysis (int c);
41         AudioAnalysis (boost::filesystem::path);
42
43         void add_point (int c, AudioPoint const & p);
44
45         void set_sample_peak (float peak, DCPTime time) {
46                 _sample_peak = peak;
47                 _sample_peak_time = time;
48         }
49
50         void set_true_peak (float peak) {
51                 _true_peak = peak;
52         }
53
54         void set_integrated_loudness (float l) {
55                 _integrated_loudness = l;
56         }
57
58         void set_loudness_range (float r) {
59                 _loudness_range = r;
60         }
61
62         AudioPoint get_point (int c, int p) const;
63         int points (int c) const;
64         int channels () const;
65
66         boost::optional<float> sample_peak () const {
67                 return _sample_peak;
68         }
69
70         boost::optional<DCPTime> sample_peak_time () const {
71                 return _sample_peak_time;
72         }
73
74         boost::optional<float> true_peak () const {
75                 return _true_peak;
76         }
77
78         boost::optional<float> integrated_loudness () const {
79                 return _integrated_loudness;
80         }
81
82         boost::optional<float> loudness_range () const {
83                 return _loudness_range;
84         }
85
86         boost::optional<double> analysis_gain () const {
87                 return _analysis_gain;
88         }
89
90         void set_analysis_gain (double gain) {
91                 _analysis_gain = gain;
92         }
93
94         void write (boost::filesystem::path);
95
96         float gain_correction (boost::shared_ptr<const Playlist> playlist);
97
98 private:
99         std::vector<std::vector<AudioPoint> > _data;
100         boost::optional<float> _sample_peak;
101         boost::optional<DCPTime> _sample_peak_time;
102         boost::optional<float> _true_peak;
103         boost::optional<float> _integrated_loudness;
104         boost::optional<float> _loudness_range;
105         /** If this analysis was run on a single piece of
106          *  content we store its gain in dB when the analysis
107          *  happened.
108          */
109         boost::optional<double> _analysis_gain;
110 };
111
112 #endif