From cf2ed48d21ddbc32bda262064480e88e69dc031a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 4 Apr 2022 22:37:31 +0200 Subject: [PATCH] Cleanup: move some methods from util to maths_util. --- src/lib/audio_buffers.cc | 2 +- src/lib/audio_content.cc | 1 + src/lib/hints.cc | 2 +- src/lib/image.cc | 2 ++ src/lib/maths_util.cc | 37 ++++++++++++++++++++++++++++++++++ src/lib/maths_util.h | 39 ++++++++++++++++++++++++++++++++++++ src/lib/player.cc | 1 + src/lib/util.cc | 12 ----------- src/lib/util.h | 15 -------------- src/lib/wscript | 1 + src/wx/audio_dialog.cc | 4 ++++ src/wx/audio_gain_dialog.cc | 6 ++++-- src/wx/audio_mapping_view.cc | 12 +++++------ src/wx/audio_panel.cc | 1 + src/wx/audio_plot.cc | 13 ++++++------ 15 files changed, 105 insertions(+), 43 deletions(-) create mode 100644 src/lib/maths_util.cc create mode 100644 src/lib/maths_util.h diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc index 9f91810e0..1d3598270 100644 --- a/src/lib/audio_buffers.cc +++ b/src/lib/audio_buffers.cc @@ -19,9 +19,9 @@ */ -#include "util.h" #include "audio_buffers.h" #include "dcpomatic_assert.h" +#include "maths_util.h" #include #include #include diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index f2510b494..32e713ff2 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -25,6 +25,7 @@ #include "exceptions.h" #include "film.h" #include "frame_rate_change.h" +#include "maths_util.h" #include #include #include diff --git a/src/lib/hints.cc b/src/lib/hints.cc index 0f1cfece8..027510eca 100644 --- a/src/lib/hints.cc +++ b/src/lib/hints.cc @@ -31,11 +31,11 @@ #include "font.h" #include "font_data.h" #include "hints.h" +#include "maths_util.h" #include "player.h" #include "ratio.h" #include "text_content.h" #include "types.h" -#include "util.h" #include "video_content.h" #include "writer.h" #include diff --git a/src/lib/image.cc b/src/lib/image.cc index d0878efbd..297578866 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -25,9 +25,11 @@ #include "compose.hpp" +#include "dcpomatic_assert.h" #include "dcpomatic_socket.h" #include "exceptions.h" #include "image.h" +#include "maths_util.h" #include "rect.h" #include "timer.h" #include "util.h" diff --git a/src/lib/maths_util.cc b/src/lib/maths_util.cc new file mode 100644 index 000000000..35e3879c4 --- /dev/null +++ b/src/lib/maths_util.cc @@ -0,0 +1,37 @@ +/* + Copyright (C) 2012-2021 Carl Hetherington + + 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. + + 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 DCP-o-matic. If not, see . + +*/ + + +#include + + +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/maths_util.h b/src/lib/maths_util.h new file mode 100644 index 000000000..8adefbbc4 --- /dev/null +++ b/src/lib/maths_util.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2012-2021 Carl Hetherington + + 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. + + 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 DCP-o-matic. If not, see . + +*/ + + +#include + + +#ifndef M_PI +#define M_PI (3.14159265358979323846) +#endif + + +extern double db_to_linear (double db); +extern double linear_to_db (double linear); + + +template +T clamp (T val, T minimum, T maximum) +{ + return std::max(std::min(val, maximum), minimum); +} + diff --git a/src/lib/player.cc b/src/lib/player.cc index 6853048de..abd051bed 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -40,6 +40,7 @@ #include "image_decoder.h" #include "job.h" #include "log.h" +#include "maths_util.h" #include "piece.h" #include "player.h" #include "player_video.h" diff --git a/src/lib/util.cc b/src/lib/util.cc index 6bcacf9f2..eeaa4cd91 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1085,18 +1085,6 @@ copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, std::fun free (buffer); } -double -db_to_linear (double db) -{ - return pow(10, db / 20); -} - -double -linear_to_db (double linear) -{ - return 20 * log10(linear); -} - dcp::Size scale_for_display (dcp::Size s, dcp::Size display_container, dcp::Size film_container, PixelQuanta quanta) diff --git a/src/lib/util.h b/src/lib/util.h index bd9eaf96e..fd11fffbd 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -51,10 +51,6 @@ namespace dcp { class SoundAsset; } -#ifndef M_PI -#define M_PI (3.14159265358979323846) -#endif - /** The maximum number of audio channels that we can have in a DCP */ #define MAX_DCP_AUDIO_CHANNELS 16 /** Message broadcast to find possible encoding servers */ @@ -152,15 +148,4 @@ list_to_vector (std::list v) return l; } -extern double db_to_linear (double db); -extern double linear_to_db (double linear); - - -template -T clamp (T val, T minimum, T maximum) -{ - return std::max(std::min(val, maximum), minimum); -} - - #endif diff --git a/src/lib/wscript b/src/lib/wscript index 914fc69f9..6d7e2330e 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -132,6 +132,7 @@ sources = """ kdm_with_metadata.cc log.cc log_entry.cc + maths_util.cc mid_side_decoder.cc overlaps.cc pixel_quanta.cc diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index 9e0d7a30f..c64f64e31 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -18,6 +18,7 @@ */ + #include "audio_dialog.h" #include "audio_plot.h" #include "check_box.h" @@ -28,10 +29,12 @@ #include "lib/audio_content.h" #include "lib/film.h" #include "lib/job_manager.h" +#include "lib/maths_util.h" #include #include #include + using std::cout; using std::list; using std::make_shared; @@ -48,6 +51,7 @@ using namespace dcpomatic; using namespace boost::placeholders; #endif + /** @param parent Parent window. * @param film Film we are using. * @param content Content to analyse, or 0 to analyse all of the film's audio. diff --git a/src/wx/audio_gain_dialog.cc b/src/wx/audio_gain_dialog.cc index fb9bd2544..2c0f17c0a 100644 --- a/src/wx/audio_gain_dialog.cc +++ b/src/wx/audio_gain_dialog.cc @@ -18,11 +18,13 @@ */ + #include "audio_gain_dialog.h" #include "wx_util.h" -#include "lib/util.h" -#include +#include "lib/maths_util.h" #include +#include + AudioGainDialog::AudioGainDialog (wxWindow* parent, int c, int d, float v) : TableDialog (parent, _("Channel gain"), 3, 1, true) diff --git a/src/wx/audio_mapping_view.cc b/src/wx/audio_mapping_view.cc index 7c12a1646..81fa1a70d 100644 --- a/src/wx/audio_mapping_view.cc +++ b/src/wx/audio_mapping_view.cc @@ -24,11 +24,11 @@ */ +#include "audio_gain_dialog.h" #include "audio_mapping_view.h" #include "wx_util.h" -#include "audio_gain_dialog.h" #include "lib/audio_mapping.h" -#include "lib/util.h" +#include "lib/maths_util.h" #include "lib/warnings.h" #include #include @@ -43,13 +43,13 @@ DCPOMATIC_ENABLE_WARNINGS using std::cout; using std::list; -using std::string; -using std::min; +using std::make_pair; using std::max; -using std::vector; +using std::min; using std::pair; -using std::make_pair; using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index 75659aebd..af030e915 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -35,6 +35,7 @@ #include "lib/job_manager.h" #include "lib/dcp_content.h" #include "lib/audio_content.h" +#include "lib/maths_util.h" #include #include diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index 90a4aa91d..e08e07e05 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -20,27 +20,28 @@ #include "audio_plot.h" -#include "wx_util.h" #include "film_viewer.h" +#include "wx_util.h" #include "lib/audio_decoder.h" #include "lib/audio_analysis.h" #include "lib/compose.hpp" +#include "lib/maths_util.h" #include #include -#include #include +#include using std::cout; -using std::vector; using std::list; +using std::map; using std::max; using std::min; -using std::map; -using boost::bind; -using boost::optional; using std::shared_ptr; +using std::vector; using std::weak_ptr; +using boost::bind; +using boost::optional; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif -- 2.30.2