2 Copyright (C) 2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <ardour/meter.h>
22 #include <ardour/buffer_set.h>
23 #include <ardour/peak.h>
24 #include <ardour/dB.h>
25 #include <ardour/session.h>
30 /** Get peaks from @a bufs
31 * Input acceptance is lenient - the first n audio buffers from @a bufs will
32 * be metered, where n was set by the last call to setup(), excess meters will
36 PeakMeter::run (BufferSet& bufs, jack_nframes_t nframes, jack_nframes_t offset)
38 size_t meterable = std::min(bufs.count().get(DataType::AUDIO), _peak_power.size());
41 for (size_t n = 0; n < meterable; ++n) {
42 _peak_power[n] = compute_peak (bufs.get_audio(n).data(nframes, offset), nframes, _peak_power[n]);
45 // Zero any excess peaks
46 for (size_t n = meterable; n < _peak_power.size(); ++n) {
54 for (size_t i = 0; i < _peak_power.size(); ++i) {
60 PeakMeter::setup (const ChanCount& in)
62 uint32_t limit = in.get(DataType::AUDIO);
64 while (_peak_power.size() < limit) {
65 _peak_power.push_back (0);
66 _visible_peak_power.push_back (0);
69 assert(_peak_power.size() == limit);
70 assert(_visible_peak_power.size() == limit);
73 /** To be driven by the Meter signal from IO.
74 * Caller MUST hold io_lock!
79 assert(_visible_peak_power.size() == _peak_power.size());
81 const size_t limit = _peak_power.size();
83 for (size_t n = 0; n < limit; ++n) {
85 /* XXX we should use atomic exchange here */
87 /* grab peak since last read */
89 float new_peak = _peak_power[n];
92 /* compute new visible value using falloff */
95 new_peak = coefficient_to_dB (new_peak);
97 new_peak = minus_infinity();
100 if (_session.meter_falloff() == 0.0f || new_peak > _visible_peak_power[n]) {
101 _visible_peak_power[n] = new_peak;
104 new_peak = _visible_peak_power[n] - _session.meter_falloff();
105 _visible_peak_power[n] = std::max (new_peak, -INFINITY);
110 } // namespace ARDOUR