projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix font_id_map errors when importing DCP subtitles that have no
[dcpomatic.git]
/
src
/
lib
/
audio_filter.cc
diff --git
a/src/lib/audio_filter.cc
b/src/lib/audio_filter.cc
index 59b5684ea62e2cd7e447599b215c6d1b6a44fc0e..94994ba81036fd1fad2fa16785d37d76ec0d76bb 100644
(file)
--- a/
src/lib/audio_filter.cc
+++ b/
src/lib/audio_filter.cc
@@
-1,37
+1,44
@@
/*
/*
- 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.
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
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 <cmath>
+
#include "audio_filter.h"
#include "audio_buffers.h"
#include "audio_filter.h"
#include "audio_buffers.h"
+#include "maths_util.h"
+#include "util.h"
+#include <cmath>
-using std::vector;
+
+using std::make_shared;
using std::min;
using std::min;
-using boost::shared_ptr;
+using std::shared_ptr;
+
-vector<float>
+
std::
vector<float>
AudioFilter::sinc_blackman (float cutoff, bool invert) const
{
AudioFilter::sinc_blackman (float cutoff, bool invert) const
{
- vector<float> ir (_M + 1);
-
+ auto ir = std::vector<float>();
+ ir.resize(_M + 1);
+
/* Impulse response */
/* Impulse response */
-
+
for (int i = 0; i <= _M; ++i) {
if (i == (_M / 2)) {
ir[i] = 2 * M_PI * cutoff;
for (int i = 0; i <= _M; ++i) {
if (i == (_M / 2)) {
ir[i] = 2 * M_PI * cutoff;
@@
-42,70
+49,79
@@
AudioFilter::sinc_blackman (float cutoff, bool invert) const
ir[i] *= (0.42 - 0.5 * cos (2 * M_PI * i / _M) + 0.08 * cos (4 * M_PI * i / _M));
}
}
ir[i] *= (0.42 - 0.5 * cos (2 * M_PI * i / _M) + 0.08 * cos (4 * M_PI * i / _M));
}
}
-
+
/* Normalise */
/* Normalise */
-
+
float sum = 0;
for (int i = 0; i <= _M; ++i) {
sum += ir[i];
}
float sum = 0;
for (int i = 0; i <= _M; ++i) {
sum += ir[i];
}
-
+
for (int i = 0; i <= _M; ++i) {
ir[i] /= sum;
}
for (int i = 0; i <= _M; ++i) {
ir[i] /= sum;
}
-
+
/* Frequency inversion (swapping low-pass for high-pass, or whatever) */
/* Frequency inversion (swapping low-pass for high-pass, or whatever) */
-
+
if (invert) {
for (int i = 0; i <= _M; ++i) {
ir[i] = -ir[i];
}
ir[_M / 2] += 1;
}
if (invert) {
for (int i = 0; i <= _M; ++i) {
ir[i] = -ir[i];
}
ir[_M / 2] += 1;
}
-
+
return ir;
}
return ir;
}
+
shared_ptr<AudioBuffers>
shared_ptr<AudioBuffers>
-AudioFilter::run (shared_ptr<AudioBuffers> in)
+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) {
if (!_tail) {
- _tail
.reset (new AudioBuffers (in->channels(), _M + 1)
);
+ _tail
= make_shared<AudioBuffers>(in->channels(), _M + 1
);
_tail->make_silent ();
}
_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) {
+ 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) {
if ((j - k) < 0) {
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 {
} 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 ()) {
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);
}
_tail->copy_from (in.get(), amount, in->frames() - amount, _tail->frames () - amount);
-
+
return out;
}
return out;
}
+
void
AudioFilter::flush ()
{
_tail.reset ();
}
void
AudioFilter::flush ()
{
_tail.reset ();
}
+
LowPassAudioFilter::LowPassAudioFilter (float transition_bandwidth, float cutoff)
: AudioFilter (transition_bandwidth)
{
LowPassAudioFilter::LowPassAudioFilter (float transition_bandwidth, float cutoff)
: AudioFilter (transition_bandwidth)
{
@@
-119,21
+135,22
@@
HighPassAudioFilter::HighPassAudioFilter (float transition_bandwidth, float cuto
_ir = sinc_blackman (cutoff, true);
}
_ir = sinc_blackman (cutoff, true);
}
+
BandPassAudioFilter::BandPassAudioFilter (float transition_bandwidth, float lower, float higher)
: AudioFilter (transition_bandwidth)
{
BandPassAudioFilter::BandPassAudioFilter (float transition_bandwidth, float lower, float higher)
: AudioFilter (transition_bandwidth)
{
-
vector<float>
lpf = sinc_blackman (lower, false);
-
vector<float>
hpf = sinc_blackman (higher, true);
-
- _ir.resize
(_M + 1);
+
auto
lpf = sinc_blackman (lower, false);
+
auto
hpf = sinc_blackman (higher, true);
+
+ _ir.resize(_M + 1);
for (int i = 0; i <= _M; ++i) {
_ir[i] = lpf[i] + hpf[i];
}
for (int i = 0; i <= _M; ++i) {
_ir[i] = lpf[i] + hpf[i];
}
-
+
/* We now have a band-stop, so invert for band-pass */
for (int i = 0; i <= _M; ++i) {
_ir[i] = -_ir[i];
}
/* We now have a band-stop, so invert for band-pass */
for (int i = 0; i <= _M; ++i) {
_ir[i] = -_ir[i];
}
-
+
_ir[_M / 2] += 1;
}
_ir[_M / 2] += 1;
}