X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_filter.cc;h=3d3ecdfbb3deed7bfef315818646ffaf12e0dac3;hb=f0c10e92b849566e458bc323f8783a6fe83e52d2;hp=2cf1cf6047ac4b3e00adb5d6812ac8bd1ad5061f;hpb=e60bb3e51bd1508b149e6b8f6608f09b5196ae26;p=dcpomatic.git diff --git a/src/lib/audio_filter.cc b/src/lib/audio_filter.cc index 2cf1cf604..3d3ecdfbb 100644 --- a/src/lib/audio_filter.cc +++ b/src/lib/audio_filter.cc @@ -1,34 +1,36 @@ /* Copyright (C) 2014 Carl Hetherington - 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 . */ #include "audio_filter.h" #include "audio_buffers.h" +#include "util.h" #include -using std::vector; using std::min; using boost::shared_ptr; -vector +/** @return array of floats which the caller must destroy with delete[] */ +float * AudioFilter::sinc_blackman (float cutoff, bool invert) const { - vector ir (_M + 1); + float* ir = new float[_M + 1]; /* Impulse response */ @@ -66,8 +68,13 @@ AudioFilter::sinc_blackman (float cutoff, bool invert) const return ir; } +AudioFilter::~AudioFilter () +{ + delete[] _ir; +} + shared_ptr -AudioFilter::run (shared_ptr in) +AudioFilter::run (shared_ptr in) { shared_ptr out (new AudioBuffers (in->channels(), in->frames())); @@ -76,24 +83,30 @@ AudioFilter::run (shared_ptr in) _tail->make_silent (); } - for (int i = 0; i < in->channels(); ++i) { - for (int j = 0; j < in->frames(); ++j) { + int const channels = in->channels (); + 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); + for (int j = 0; j < frames; ++j) { float s = 0; for (int k = 0; k <= _M; ++k) { if ((j - k) < 0) { - s += _tail->data(i)[j - k + _M + 1] * _ir[k]; + s += tail_p[j - k + _M + 1] * _ir[k]; } else { - s += in->data(i)[j - k] * _ir[k]; + s += in_p[j - k] * _ir[k]; } } - out->data(i)[j] = s; + out_p[j] = s; } } 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); @@ -122,14 +135,18 @@ HighPassAudioFilter::HighPassAudioFilter (float transition_bandwidth, float cuto BandPassAudioFilter::BandPassAudioFilter (float transition_bandwidth, float lower, float higher) : AudioFilter (transition_bandwidth) { - vector lpf = sinc_blackman (lower, false); - vector hpf = sinc_blackman (higher, true); + float* lpf = sinc_blackman (lower, false); + float* hpf = sinc_blackman (higher, true); - _ir.resize (_M + 1); + delete[] _ir; + _ir = new float[_M + 1]; for (int i = 0; i <= _M; ++i) { _ir[i] = lpf[i] + hpf[i]; } + delete[] lpf; + delete[] hpf; + /* We now have a band-stop, so invert for band-pass */ for (int i = 0; i <= _M; ++i) { _ir[i] = -_ir[i];