Include tidying src/lib/a-j*.h
[dcpomatic.git] / src / lib / audio_analysis.h
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef DCPOMATIC_AUDIO_ANALYSIS_H
21 #define DCPOMATIC_AUDIO_ANALYSIS_H
22
23 #include "dcpomatic_time.h"
24 #include <libcxml/cxml.h>
25 #include <boost/optional.hpp>
26 #include <boost/filesystem.hpp>
27 #include <vector>
28
29 namespace xmlpp {
30         class Element;
31 }
32
33 class AudioPoint
34 {
35 public:
36         enum Type {
37                 PEAK,
38                 RMS,
39                 COUNT
40         };
41
42         AudioPoint ();
43         AudioPoint (cxml::ConstNodePtr node);
44         AudioPoint (AudioPoint const &);
45         AudioPoint& operator= (AudioPoint const &);
46
47         void as_xml (xmlpp::Element *) const;
48
49         float& operator[] (int t) {
50                 return _data[t];
51         }
52
53 private:
54         float _data[COUNT];
55 };
56
57 class AudioAnalysis : public boost::noncopyable
58 {
59 public:
60         AudioAnalysis (int c);
61         AudioAnalysis (boost::filesystem::path);
62
63         void add_point (int c, AudioPoint const & p);
64         void set_peak (float peak, DCPTime time) {
65                 _peak = peak;
66                 _peak_time = time;
67         }
68
69         AudioPoint get_point (int c, int p) const;
70         int points (int c) const;
71         int channels () const;
72
73         boost::optional<float> peak () const {
74                 return _peak;
75         }
76
77         boost::optional<DCPTime> peak_time () const {
78                 return _peak_time;
79         }
80
81         boost::optional<double> analysis_gain () const {
82                 return _analysis_gain;
83         }
84
85         void set_analysis_gain (double gain) {
86                 _analysis_gain = gain;
87         }
88
89         void write (boost::filesystem::path);
90
91 private:
92         std::vector<std::vector<AudioPoint> > _data;
93         boost::optional<float> _peak;
94         boost::optional<DCPTime> _peak_time;
95         /** If this analysis was run on a single piece of
96          *  content we store its gain in dB when the analysis
97          *  happened.
98          */
99         boost::optional<double> _analysis_gain;
100 };
101
102 #endif