Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
kmeter_dsp.h
1// SPDX-FileCopyrightText: © 2020-2021, 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense OR GPL-2.0-or-later
3/*
4 * This file incorporates work covered by the following copyright and
5 * permission notice:
6 *
7 * ---
8 *
9 * Copyright (C) 2013 Robin Gareus <robin@gareus.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 *
25 * SPDX-License-Identifier: GPL-2.0-or-later
26 *
27 * ---
28 */
29
30#pragma once
31
32#include <utility>
33
34namespace zrythm::dsp
35{
36
53{
54public:
61 void process (const float * p, int n);
62
63 float read_f ();
64
70 std::pair<float, float> read ();
71
72 void reset ();
73
77 void init (float samplerate);
78
79private:
80 float z1_{}; // filter state
81 float z2_{}; // filter state
82 float rms_{}; // max rms value since last read()
83 float peak_{}; // max peak value since last read()
84 int cnt_{}; // digital peak hold counter
85 int fpp_{}; // frames per period
86 float fall_{}; // peak fallback
87 bool flag_{}; // flag set by read(), resets _rms
88
89 float omega_{}; // ballistics filter constant.
90 int hold_{}; // peak hold timeoute
91 float fsamp_{}; // sample-rate
92};
93
94} // namespace zrythm::dsp
Implements a K-System meter DSP.
Definition kmeter_dsp.h:53
void process(const float *p, int n)
Process.
std::pair< float, float > read()
Returns the current RMS and peak values.
void init(float samplerate)
Init with the samplerate.