C++11 tidying.
[dcpomatic.git] / src / lib / audio_filter.cc
index 2c92236b6f55fe1b2a0c4ffd3bab3afaad30f5bb..281ac966831c8e80de73609a96a12132a763d67a 100644 (file)
@@ -1,28 +1,34 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
+
 #include "audio_filter.h"
 #include "audio_buffers.h"
+#include "util.h"
 #include <cmath>
 
+
+using std::make_shared;
 using std::min;
-using boost::shared_ptr;
+using std::shared_ptr;
+
 
 /** @return array of floats which the caller must destroy with delete[] */
 float *
@@ -66,15 +72,17 @@ AudioFilter::sinc_blackman (float cutoff, bool invert) const
        return ir;
 }
 
+
 AudioFilter::~AudioFilter ()
 {
        delete[] _ir;
 }
 
+
 shared_ptr<AudioBuffers>
 AudioFilter::run (shared_ptr<const AudioBuffers> in)
 {
-       shared_ptr<AudioBuffers> out (new AudioBuffers (in->channels(), in->frames()));
+       auto out = make_shared<AudioBuffers>(in->channels(), in->frames());
 
        if (!_tail) {
                _tail.reset (new AudioBuffers (in->channels(), _M + 1));
@@ -85,9 +93,9 @@ AudioFilter::run (shared_ptr<const AudioBuffers> in)
        int const frames = in->frames ();
 
        for (int i = 0; i < channels; ++i) {
-               float* tail_p = _tail->data (i);
-               float* in_p = in->data (i);
-               float* out_p = out->data (i);
+               auto tail_p = _tail->data (i);
+               auto in_p = in->data (i);
+               auto out_p = out->data (i);
                for (int j = 0; j < frames; ++j) {
                        float s = 0;
                        for (int k = 0; k <= _M; ++k) {
@@ -104,19 +112,21 @@ AudioFilter::run (shared_ptr<const AudioBuffers> in)
 
        int const amount = min (in->frames(), _tail->frames());
        if (amount < _tail->frames ()) {
-               _tail->move (amount, 0, _tail->frames() - amount);
+               _tail->move (_tail->frames() - amount, amount, 0);
        }
        _tail->copy_from (in.get(), amount, in->frames() - amount, _tail->frames () - amount);
 
        return out;
 }
 
+
 void
 AudioFilter::flush ()
 {
        _tail.reset ();
 }
 
+
 LowPassAudioFilter::LowPassAudioFilter (float transition_bandwidth, float cutoff)
        : AudioFilter (transition_bandwidth)
 {
@@ -130,11 +140,12 @@ HighPassAudioFilter::HighPassAudioFilter (float transition_bandwidth, float cuto
        _ir = sinc_blackman (cutoff, true);
 }
 
+
 BandPassAudioFilter::BandPassAudioFilter (float transition_bandwidth, float lower, float higher)
        : AudioFilter (transition_bandwidth)
 {
-       float* lpf = sinc_blackman (lower, false);
-       float* hpf = sinc_blackman (higher, true);
+       auto lpf = sinc_blackman (lower, false);
+       auto hpf = sinc_blackman (higher, true);
 
        delete[] _ir;
        _ir = new float[_M + 1];