summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-02-27 22:26:57 +0100
committerCarl Hetherington <cth@carlh.net>2020-02-27 22:26:57 +0100
commitbcc4e2f7dc4cd5658e199ddacb7202b00ec72cf1 (patch)
tree70a6d59908b1d1391e2f9ecd2c8bd17890b3bbc5 /src/lib
parenta2ceaa313a2b8ba28516c935f7f8b82d69957b77 (diff)
Add and use dB/linear conversion functions.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_buffers.cc5
-rw-r--r--src/lib/hints.cc2
-rw-r--r--src/lib/util.cc15
-rw-r--r--src/lib/util.h5
4 files changed, 22 insertions, 5 deletions
diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc
index cceb12672..cfe762659 100644
--- a/src/lib/audio_buffers.cc
+++ b/src/lib/audio_buffers.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+#include "util.h"
#include "audio_buffers.h"
#include "dcpomatic_assert.h"
#include <cassert>
@@ -309,7 +310,7 @@ AudioBuffers::accumulate_frames (AudioBuffers const * from, int32_t frames, int3
void
AudioBuffers::apply_gain (float dB)
{
- float const linear = pow (10, dB / 20);
+ float const linear = db_to_linear (dB);
for (int i = 0; i < _channels; ++i) {
for (int j = 0; j < _frames; ++j) {
diff --git a/src/lib/hints.cc b/src/lib/hints.cc
index 6cb037ed0..3edceeee3 100644
--- a/src/lib/hints.cc
+++ b/src/lib/hints.cc
@@ -235,7 +235,7 @@ Hints::thread ()
for (size_t i = 0; i < sample_peak.size(); ++i) {
float const peak = max (sample_peak[i].peak, true_peak.empty() ? 0 : true_peak[i]);
- float const peak_dB = 20 * log10 (peak) + an->gain_correction (film->playlist ());
+ float const peak_dB = linear_to_db(peak) + an->gain_correction(film->playlist());
if (peak_dB > -3) {
ch += dcp::raw_convert<string> (short_audio_channel_name (i)) + ", ";
}
diff --git a/src/lib/util.cc b/src/lib/util.cc
index bbb444367..e4f552c4d 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -1171,3 +1171,16 @@ write_swaroop_chain (shared_ptr<const dcp::CertificateChain> chain, boost::files
}
#endif
+
+double
+db_to_linear (double db)
+{
+ return pow(10, db / 20);
+}
+
+double
+linear_to_db (double linear)
+{
+ return 20 * log10(linear);
+}
+
diff --git a/src/lib/util.h b/src/lib/util.h
index c8dcb29d6..12c79ea5a 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -128,4 +128,7 @@ vector_to_list (std::vector<T> v)
return l;
}
+extern double db_to_linear (double db);
+extern double linear_to_db (double linear);
+
#endif