1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __ardour_export_analysis_h__
20 #define __ardour_export_analysis_h__
21 
22 #include <map>
23 #include <set>
24 #include <cstring>
25 #include <boost/shared_ptr.hpp>
26 
27 #include "ardour/types.h"
28 
29 namespace ARDOUR {
30 	struct ExportAnalysis {
31 	public:
ExportAnalysisExportAnalysis32 		ExportAnalysis ()
33 			: peak (0)
34 			, truepeak (0)
35 			, loudness_range (0)
36 			, integrated_loudness (0)
37 			, max_loudness_short (0)
38 			, max_loudness_momentary (0)
39 			, loudness_hist_max (0)
40 			, have_loudness (false)
41 			, have_lufs_graph (false)
42 			, have_dbtp (false)
43 			, norm_gain_factor (1.0)
44 			, normalized (false)
45 			, n_channels (1)
46 			, n_samples (0)
47 		{
48 			memset (peaks, 0, sizeof(peaks));
49 			memset (spectrum, 0, sizeof(spectrum));
50 			memset (loudness_hist, 0, sizeof(loudness_hist));
51 			memset (freq, 0, sizeof(freq));
52 			memset (limiter_pk, 0, sizeof(limiter_pk));
53 			assert (sizeof(lgraph_i) == sizeof(lgraph_s));
54 			assert (sizeof(lgraph_i) == sizeof(lgraph_m));
55 			for (size_t i = 0; i < sizeof(lgraph_i) / sizeof (float); ++i) {
56 				/* d compare to ebu_r128_proc.cc */
57 				lgraph_i [i] = -200;
58 				lgraph_s [i] = -200;
59 				lgraph_m [i] = -200;
60 			}
61 		}
62 
ExportAnalysisExportAnalysis63 		ExportAnalysis (const ExportAnalysis& other)
64 			: peak (other.peak)
65 			, truepeak (other.truepeak)
66 			, loudness_range (other.loudness_range)
67 			, integrated_loudness (other.integrated_loudness)
68 			, max_loudness_short (other.max_loudness_short)
69 			, max_loudness_momentary (other.max_loudness_momentary)
70 			, loudness_hist_max (other.loudness_hist_max)
71 			, have_loudness (other.have_loudness)
72 			, have_lufs_graph (other.have_lufs_graph)
73 			, have_dbtp (other.have_dbtp)
74 			, norm_gain_factor (other.norm_gain_factor)
75 			, normalized (other.normalized)
76 			, n_channels (other.n_channels)
77 			, n_samples (other.n_samples)
78 		{
79 			truepeakpos[0] = other.truepeakpos[0];
80 			truepeakpos[1] = other.truepeakpos[1];
81 			memcpy (peaks, other.peaks, sizeof(peaks));
82 			memcpy (spectrum, other.spectrum, sizeof(spectrum));
83 			memcpy (loudness_hist, other.loudness_hist, sizeof(loudness_hist));
84 			memcpy (freq, other.freq, sizeof(freq));
85 			memcpy (lgraph_i, other.lgraph_i, sizeof(lgraph_i));
86 			memcpy (lgraph_s, other.lgraph_s, sizeof(lgraph_s));
87 			memcpy (lgraph_m, other.lgraph_m, sizeof(lgraph_m));
88 			memcpy (limiter_pk, other.limiter_pk, sizeof(limiter_pk));
89 		}
90 
91 		float peak;
92 		float truepeak;
93 		float loudness_range;
94 		float integrated_loudness;
95 		float max_loudness_short;
96 		float max_loudness_momentary;
97 		int   loudness_hist[540];
98 		int   loudness_hist_max;
99 		bool  have_loudness;
100 		bool  have_lufs_graph;
101 		bool  have_dbtp;
102 		float norm_gain_factor;
103 		bool  normalized;
104 
105 		uint32_t n_channels;
106 		uint32_t n_samples;
107 		uint32_t freq[6]; // y-pos, 50, 100, 500, 1k, 5k, 10k [Hz]
108 
109 		PeakData peaks[2][800];
110 		float spectrum[800][200];
111 		float lgraph_i[800];
112 		float lgraph_s[800];
113 		float lgraph_m[800];
114 		float limiter_pk[800];
115 		std::set<samplecnt_t> truepeakpos[2]; // bins with >= -1dBTB
116 	};
117 
118 	typedef boost::shared_ptr<ExportAnalysis> ExportAnalysisPtr;
119 	typedef std::map<std::string, ExportAnalysisPtr> AnalysisResults;
120 
121 } // namespace ARDOUR
122 #endif
123