Ardour  9.0-pre0-582-g084a23a80d
lufs_meter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016,2023 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 #ifndef _lufs_meter_h_
19 #define _lufs_meter_h_
20 
21 #include <cstdint>
22 #include <functional>
23 #include <map>
24 
25 #include "pbd/stack_allocator.h"
26 
28 
29 namespace ARDOUR {
30 
32 {
33 public:
34  LUFSMeter (double samplerate, uint32_t n_channels);
35  LUFSMeter (LUFSMeter const& other) = delete;
37 
38  void run (float const** data, uint32_t n_samples);
39  void reset ();
40 
41  float integrated_loudness () const;
42  float momentary () const;
43  float max_momentary () const;
44  float dbtp () const;
45 
46 private:
47  void init ();
48 
49  float process (float const** data, const uint32_t n_samples, uint32_t offset);
50  float sumfrag (uint32_t) const;
51 
52  void calc_true_peak (float const** data, const uint32_t n_samples);
53  float upsample_x4 (int chn, float const x);
54  float upsample_x2 (int chn, float const x);
55  std::function< float(int, const float) > upsample;
56 
57  const float _g[5] = { 1.0, 1.0, 1.0, 1.41, 1.41 };
58 
59  /* config */
60  double _samplerate;
61  uint32_t _n_channels;
62  uint32_t _n_fragment;
63 
64  /* filter coeff */
65  float _a0, _a1, _a2;
66  float _b1, _b2;
67  float _c3, _c4;
68 
69  /* state */
70  uint32_t _frag_pos;
71  float _frag_pwr;
72  uint32_t _block_cnt;
73  float _block_pwr;
74  float _power[8];
75  uint32_t _pow_idx;
76  float _thresh_rel;
77 
78  float _momentary_l;
79 
80  float _maxloudn_M;
81  float _integrated;
82  float _dbtp;
83 
84 #if defined(_MSC_VER)
85  typedef std::map<int, uint32_t> History;
86 #else
87  typedef std::map<int, uint32_t, std::less<int>, PBD::StackAllocator<std::pair<const int, uint32_t>, 1000>> History;
88 #endif
89 
91 
92  struct FilterState {
93  void reset ();
94  void sanitize ();
95 
96  float z1, z2, z3, z4;
97  };
98 
99  FilterState _fst[5];
100  float* _z[5];
101 };
102 
103 } // namespace ARDOUR
104 #endif
float integrated_loudness() const
uint32_t _n_channels
Definition: lufs_meter.h:61
uint32_t _n_fragment
Definition: lufs_meter.h:62
float process(float const **data, const uint32_t n_samples, uint32_t offset)
float max_momentary() const
void calc_true_peak(float const **data, const uint32_t n_samples)
double _samplerate
Definition: lufs_meter.h:60
uint32_t _frag_pos
Definition: lufs_meter.h:70
float upsample_x2(int chn, float const x)
float momentary() const
std::map< int, uint32_t, std::less< int >, PBD::StackAllocator< std::pair< const int, uint32_t >, 1000 > > History
Definition: lufs_meter.h:87
LUFSMeter(LUFSMeter const &other)=delete
float sumfrag(uint32_t) const
uint32_t _block_cnt
Definition: lufs_meter.h:72
LUFSMeter(double samplerate, uint32_t n_channels)
uint32_t _pow_idx
Definition: lufs_meter.h:75
float upsample_x4(int chn, float const x)
void run(float const **data, uint32_t n_samples)
float dbtp() const
std::function< float(int, const float) > upsample
Definition: lufs_meter.h:55
#define LIBARDOUR_API