LMMS
Loading...
Searching...
No Matches
RMS.h
Go to the documentation of this file.
1/*
2 dsp/RMS.h
3
4 Copyright 2004 Tim Goetze <tim@quitte.de>
5
6 http://quitte.de/dsp/
7
8 root-mean-square accumulator.
9
10*/
11/*
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA or point your web browser to http://www.gnu.org.
26*/
27
28#ifndef _DSP_RMS_H_
29#define _DSP_RMS_H_
30
31namespace DSP {
32
33class RMS
34{
35 protected:
37 int write;
38
39 public:
40 double sum;
41
43 {
44 write = 0;
45 reset();
46 }
47
48 void reset()
49 {
50 sum = 0.;
51 memset (buffer, 0, sizeof (buffer));
52 }
53
54 /* caution: pass in the *squared* sample value */
56 {
57 sum -= buffer[write];
58 sum += (buffer[write] = x);
59 write = (write + 1) & 63;
60 }
61
63 {
64 store (x);
65 return rms();
66 }
67
69 {
70 /* fabs it before sqrt, just in case ... */
71 return sqrt (fabs (sum) / 64);
72 }
73};
74
75} /* namespace DSP */
76
77#endif /* _DSP_RMS_H_ */
LADSPA_Data sample_t
Definition basics.h:100
RMS()
Definition RMS.h:42
sample_t rms()
Definition RMS.h:68
void reset()
Definition RMS.h:48
int write
Definition RMS.h:37
void store(sample_t x)
Definition RMS.h:55
sample_t buffer[64]
Definition RMS.h:36
sample_t process(sample_t x)
Definition RMS.h:62
double sum
Definition RMS.h:40
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition BiQuad.h:31