ardour
iec2ppmdsp.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Fons Adriaensen <fons@linuxaudio.org>
3  Adopted for Ardour 2013 by Robin Gareus <robin@gareus.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 #include <math.h>
21 #include "ardour/iec2ppmdsp.h"
22 
23 
24 float Iec2ppmdsp::_w1;
25 float Iec2ppmdsp::_w2;
26 float Iec2ppmdsp::_w3;
27 float Iec2ppmdsp::_g;
28 
29 
31  _z1 (0),
32  _z2 (0),
33  _m (0),
34  _res (true)
35 {
36 }
37 
38 
40 {
41 }
42 
43 
44 void Iec2ppmdsp::process (float const *p, int n)
45 {
46  float z1, z2, m, t;
47 
48  z1 = _z1 > 20 ? 20 : (_z1 < 0 ? 0 : _z1);
49  z2 = _z2 > 20 ? 20 : (_z2 < 0 ? 0 : _z2);
50  m = _res ? 0: _m;
51  _res = false;
52 
53  n /= 4;
54  while (n--)
55  {
56  z1 *= _w3;
57  z2 *= _w3;
58  t = fabsf (*p++);
59  if (t > z1) z1 += _w1 * (t - z1);
60  if (t > z2) z2 += _w2 * (t - z2);
61  t = fabsf (*p++);
62  if (t > z1) z1 += _w1 * (t - z1);
63  if (t > z2) z2 += _w2 * (t - z2);
64  t = fabsf (*p++);
65  if (t > z1) z1 += _w1 * (t - z1);
66  if (t > z2) z2 += _w2 * (t - z2);
67  t = fabsf (*p++);
68  if (t > z1) z1 += _w1 * (t - z1);
69  if (t > z2) z2 += _w2 * (t - z2);
70  t = z1 + z2;
71  if (t > m) m = t;
72  }
73 
74  _z1 = z1 + 1e-10f;
75  _z2 = z2 + 1e-10f;
76  _m = m;
77 }
78 
79 
80 float Iec2ppmdsp::read (void)
81 {
82  _res = true;
83  return _g * _m;
84 }
85 
87 {
88  _z1 = _z2 = _m = .0f;
89  _res = true;
90 }
91 
92 void Iec2ppmdsp::init (float fsamp)
93 {
94  _w1 = 200.0f / fsamp;
95  _w2 = 860.0f / fsamp;
96  _w3 = 1.0f - 4.0f / fsamp;
97  _g = 0.5141f;
98 }
99 
100 /* vi:set ts=8 sts=8 sw=4: */
float _m
Definition: iec2ppmdsp.h:42
float read(void)
Definition: iec2ppmdsp.cc:80
~Iec2ppmdsp(void)
Definition: iec2ppmdsp.cc:39
tuple f
Definition: signals.py:35
static float _w1
Definition: iec2ppmdsp.h:45
void process(float const *p, int n)
Definition: iec2ppmdsp.cc:44
Iec2ppmdsp(void)
Definition: iec2ppmdsp.cc:30
static float _w3
Definition: iec2ppmdsp.h:47
void reset()
Definition: iec2ppmdsp.cc:86
static float _g
Definition: iec2ppmdsp.h:48
static void init(float fsamp)
Definition: iec2ppmdsp.cc:92
float _z1
Definition: iec2ppmdsp.h:40
float _z2
Definition: iec2ppmdsp.h:41
bool _res
Definition: iec2ppmdsp.h:43
static float _w2
Definition: iec2ppmdsp.h:46