Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
peak_dsp.h
1// SPDX-FileCopyrightText: © 2020-2021, 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
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 3, 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 * ---
26 */
27
28#ifndef ZRYTHM_DSP_PEAK_DSP
29#define ZRYTHM_DSP_PEAK_DSP
30
31#include <utility>
32
33namespace zrythm::dsp
34{
35
51{
52public:
58 [[gnu::hot]] void process (float * p, int n);
59
60 float read_f ();
61
67 std::pair<float, float> read ();
68
69 void reset ();
70
74 void init (float samplerate);
75
76private:
77 float rms_{}; // max rms value since last read()
78 float peak_{}; // max peak value since last read()
79 int cnt_{}; // digital peak hold counter
80 int fpp_{}; // frames per period
81 float fall_{}; // peak fallback
82 bool flag_{}; // flag set by read(), resets rms_
83
84 int hold_{}; // peak hold timeoute
85 float fsamp_{}; // sample-rate};
86};
87
88}; // namespace zrythm::dsp
89
90#endif
Performs digital peak processing on an audio signal.
Definition peak_dsp.h:51
std::pair< float, float > read()
Returns RMS and Peak values.
void init(float samplerate)
Init with the samplerate.
void process(float *p, int n)
Processes audio samples.