]> git.sesse.net Git - nageru/blob - ebu_r128_proc.h
Release Nageru 1.7.2.
[nageru] / ebu_r128_proc.h
1 // ------------------------------------------------------------------------
2 //
3 //  Copyright (C) 2010-2011 Fons Adriaensen <fons@linuxaudio.org>
4 //    
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 2 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 // ------------------------------------------------------------------------
20
21
22 #ifndef __EBU_R128_PROC_H
23 #define __EBU_R128_PROC_H
24
25
26 #define MAXCH 5
27
28
29 class Ebu_r128_fst
30 {
31 private:
32
33     friend class Ebu_r128_proc;
34
35     void reset (void) { _z1 = _z2 = _z3 = _z4 = 0; }
36
37     float _z1, _z2, _z3, _z4;
38 };
39
40
41 class Ebu_r128_hist
42 {
43 private:
44
45     Ebu_r128_hist (void);
46     ~Ebu_r128_hist (void);
47
48     friend class Ebu_r128_proc;
49
50     void  reset (void);
51     void  initstat (void);
52     void  addpoint (float v);
53     float integrate (int ind);
54     void  calc_integ (float *vi, float *th);
55     void  calc_range (float *v0, float *v1, float *th);
56
57     int  *_histc;
58     int   _count;
59     int   _error;
60
61     static float _bin_power [100];
62 };
63
64
65
66 class Ebu_r128_proc
67 {
68 public:
69
70     Ebu_r128_proc (void);
71     ~Ebu_r128_proc (void);
72
73     void  init (int nchan, float fsamp);
74     void  reset (void);
75     void  process (int nfram, float *input []);
76     void  integr_reset (void);
77     void  integr_pause (void) { _integr = false; }
78     void  integr_start (void) { _integr = true; }
79
80     float loudness_M (void) const { return _loudness_M; }
81     float maxloudn_M (void) const { return _maxloudn_M; }
82     float loudness_S (void) const { return _loudness_S; }
83     float maxloudn_S (void) const { return _maxloudn_S; }
84     float integrated (void) const { return _integrated; }
85     float integ_thr (void) const { return _integ_thr; }
86     float range_min (void) const { return _range_min; }
87     float range_max (void) const { return _range_max; }
88     float range_thr (void) const { return _range_thr; }
89
90     const int *histogram_M (void) const { return _hist_M._histc; }
91     const int *histogram_S (void) const { return _hist_S._histc; }
92     int hist_M_count (void) const { return _hist_M._count; }
93     int hist_S_count (void) const { return _hist_S._count; }
94
95 private:
96
97     float addfrags (int nfrag);
98     void  detect_init (float fsamp);
99     void  detect_reset (void);
100     float detect_process (int nfram);
101
102     bool              _integr;       // Integration on/off.
103     int               _nchan;        // Number of channels, 2 or 5.
104     float             _fsamp;        // Sample rate.
105     int               _fragm;        // Fragmenst size, 1/20 second.
106     int               _frcnt;        // Number of samples remaining in current fragment.
107     float             _frpwr;        // Power accumulated for current fragment.
108     float             _power [64];   // Array of fragment powers.
109     int               _wrind;        // Write index into _frpwr 
110     int               _div1;         // M period counter, 200 ms;
111     int               _div2;         // S period counter, 1s;
112     float             _loudness_M;
113     float             _maxloudn_M;
114     float             _loudness_S;
115     float             _maxloudn_S;
116     float             _integrated;
117     float             _integ_thr;
118     float             _range_min;
119     float             _range_max;
120     float             _range_thr;
121     
122     // Filter coefficients and states.
123     float             _a0, _a1, _a2;
124     float             _b1, _b2;
125     float             _c3, _c4;
126     float            *_ipp [MAXCH];
127     Ebu_r128_fst      _fst [MAXCH];
128     Ebu_r128_hist     _hist_M;
129     Ebu_r128_hist     _hist_S;
130
131     // Default channel gains.
132     static float      _chan_gain [5];
133 };
134
135
136 #endif