2 Copyright (C) 2012 Paul Davis
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.
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.
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.
21 #include "audiographer/general/normalizer.h"
23 namespace AudioGrapher
26 Normalizer::Normalizer (float target_dB)
31 target = pow (10.0f, target_dB * 0.05f);
34 Normalizer::~Normalizer()
39 /// Sets the peak found in the material to be normalized \see PeakReader \n RT safe
40 void Normalizer::set_peak (float peak)
42 if (peak == 0.0f || peak == target) {
51 /** Allocates a buffer for using with const ProcessContexts
52 * This function does not need to be called if
53 * non-const ProcessContexts are given to \a process() .
56 void Normalizer::alloc_buffer(framecnt_t frames)
59 buffer = new float[frames];
63 /// Process a const ProcessContext \see alloc_buffer() \n RT safe
64 void Normalizer::process (ProcessContext<float> const & c)
66 if (throw_level (ThrowProcess) && c.frames() > buffer_size) {
67 throw Exception (*this, "Too many frames given to process()");
71 memcpy (buffer, c.data(), c.frames() * sizeof(float));
72 Routines::apply_gain_to_buffer (buffer, c.frames(), gain);
75 ProcessContext<float> c_out (c, buffer);
76 ListedSource<float>::output (c_out);
79 /// Process a non-const ProcsesContext in-place \n RT safe
80 void Normalizer::process (ProcessContext<float> & c)
83 Routines::apply_gain_to_buffer (c.data(), c.frames(), gain);
85 ListedSource<float>::output(c);