/*
- 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.
*/
+#include "util.h"
#include "audio_buffers.h"
#include "dcpomatic_assert.h"
#include <cassert>
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) {
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)) + ", ";
}
/*
- 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.
}
#endif
+
+double
+db_to_linear (double db)
+{
+ return pow(10, db / 20);
+}
+
+double
+linear_to_db (double linear)
+{
+ return 20 * log10(linear);
+}
+
/*
- 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.
return l;
}
+extern double db_to_linear (double db);
+extern double linear_to_db (double linear);
+
#endif
}
pair<AudioAnalysis::PeakTime, int> const peak = _analysis->overall_sample_peak ();
- float const peak_dB = 20 * log10 (peak.first.peak) + _analysis->gain_correction (_playlist);
+ float const peak_dB = linear_to_db(peak.first.peak) + _analysis->gain_correction(_playlist);
_sample_peak->SetLabel (
wxString::Format (
_("Sample peak is %.2fdB at %s on %s"),
if (_analysis->overall_true_peak()) {
float const peak = _analysis->overall_true_peak().get();
- float const peak_dB = 20 * log10 (peak) + _analysis->gain_correction (_playlist);
+ float const peak_dB = linear_to_db(peak) + _analysis->gain_correction(_playlist);
_true_peak->SetLabel (wxString::Format (_("True peak is %.2fdB"), peak_dB));
/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
*/
-#include <cmath>
-#include <wx/spinctrl.h>
#include "audio_gain_dialog.h"
#include "wx_util.h"
+#include "lib/util.h"
+#include <cmath>
+#include <wx/spinctrl.h>
AudioGainDialog::AudioGainDialog (wxWindow* parent, int c, int d, float v)
: TableDialog (parent, _("Channel gain"), 3, 1, true)
_gain->SetDigits (1);
_gain->SetIncrement (0.1);
- _gain->SetValue (20 * log10 (v));
+ _gain->SetValue (linear_to_db(v));
layout ();
}
return 0;
}
- return pow (10, _gain->GetValue () / 20);
+ return db_to_linear (_gain->GetValue());
}
)
);
- float const value_dB = 20 * log10 (_map.get(y, x));
+ float const value_dB = linear_to_db(_map.get(y, x));
int const range = 18;
int height = 0;
if (value_dB > -range) {
void
AudioMappingView::minus6dB ()
{
- _map.set (_menu_input, _menu_output, pow (10, -6.0 / 20));
+ _map.set (_menu_input, _menu_output, db_to_linear(-6));
map_values_changed ();
}
safe_output_channel_name(channels->second)
);
} else {
- float const dB = 20 * log10 (gain);
+ float const dB = linear_to_db(gain);
s = wxString::Format (
_("Audio will be passed from %s channel %s to %s channel %s with gain %.1fdB."),
_from,
playlist->add (_parent->film(), sel.front());
try {
shared_ptr<AudioAnalysis> analysis (new AudioAnalysis(_parent->film()->audio_analysis_path(playlist)));
- peak_dB = 20 * log10 (analysis->overall_sample_peak().first.peak) + analysis->gain_correction(playlist);
+ peak_dB = linear_to_db(analysis->overall_sample_peak().first.peak) + analysis->gain_correction(playlist);
} catch (...) {
}
p = 1e-4;
}
- return metrics.height - (20 * log10(p) - _minimum) * metrics.y_scale - metrics.y_origin;
+ return metrics.height - (linear_to_db(p) - _minimum) * metrics.y_scale - metrics.y_origin;
}
void
Point (
wxPoint (metrics.db_label_width + i * metrics.x_scale, y_for_linear (peak, metrics)),
DCPTime::from_frames (i * _analysis->samples_per_point(), _analysis->sample_rate()),
- 20 * log10(peak)
+ linear_to_db(peak)
)
);
}
Point (
wxPoint (metrics.db_label_width + i * metrics.x_scale, y_for_linear (p, metrics)),
DCPTime::from_frames (i * _analysis->samples_per_point(), _analysis->sample_rate()),
- 20 * log10(p)
+ linear_to_db(p)
)
);
}
{
AudioPoint p = _analysis->get_point (channel, point);
for (int i = 0; i < AudioPoint::COUNT; ++i) {
- p[i] *= pow (10, _gain_correction / 20);
+ p[i] *= db_to_linear(_gain_correction);
}
return p;
staircase->set_position (film, DCPTime::from_frames (2000, film->audio_frame_rate()));
staircase->set_trim_start (ContentTime::from_frames (12, 48000));
staircase->set_trim_end (ContentTime::from_frames (35, 48000));
- staircase->audio->set_gain (20 * log10(2));
+ staircase->audio->set_gain (linear_to_db(6));
/* And again at an offset of 50000 samples, trimmed both start and end, with a gain of 6dB */
staircase = content_factory("test/data/staircase.wav").front ();
staircase->set_position (film, DCPTime::from_frames(50000, film->audio_frame_rate()));
staircase->set_trim_start (ContentTime::from_frames (12, 48000));
staircase->set_trim_end (ContentTime::from_frames (35, 48000));
- staircase->audio->set_gain (20 * log10(2));
+ staircase->audio->set_gain (linear_to_db(6));
/* 1s of red at 5s in */
shared_ptr<Content> red = content_factory("test/data/flat_red.png").front ();