Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
true_peak_dsp.h
1// SPDX-FileCopyrightText: © 2020, 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 * Copyright (C) 2013 Robin Gareus <robin@gareus.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24#pragma once
25
26#include <memory>
27#include <vector>
28
29namespace zrythm::dsp
30{
31
32class TruePeakDsp
33{
34public:
35 TruePeakDsp ();
36 ~TruePeakDsp ();
37
44 void process (float * p, int n);
45
46 void process_max (float * p, int n);
47
48 float read_f ();
49
57 std::pair<float, float> read ();
58
59 void reset ();
60
64 void init (float samplerate);
65
66private:
67 float m_ = 0.0f;
68 float p_ = 0.0f;
69 float z1_ = 0.0f;
70 float z2_ = 0.0f;
71 bool res_ = true;
72 std::vector<float> buf_;
73
74 float w1_ = 0.0f; // attack filter coefficient
75 float w2_ = 0.0f; // attack filter coefficient
76 float w3_ = 0.0f; // release filter coefficient
77 float g_ = 1.0f; // gain factor
78
79 // Forward declared implementation struct to hide zita::Resampler
80 struct Impl;
81 std::unique_ptr<Impl> impl_;
82};
83
84} // namespace zrythm::dsp
void init(float samplerate)
Init with the samplerate.
void process(float *p, int n)
Process.
std::pair< float, float > read()
Returns m_ and p_.