2008-10-13 15:45:20 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2008-2009 Sampo Savolainen <v2@iki.fi>
|
|
|
|
* Copyright (C) 2008-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2016 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
|
2019-02-27 19:26:21 -05:00
|
|
|
*
|
2019-08-02 17:26:43 -04:00
|
|
|
* This program 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.
|
2019-02-27 19:26:21 -05:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
2019-08-02 17:26:43 -04:00
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2019-02-27 19:26:21 -05:00
|
|
|
*/
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2016-07-23 15:10:44 -04:00
|
|
|
#include <algorithm>
|
2014-03-04 09:25:58 -05:00
|
|
|
#include <math.h>
|
2016-07-23 15:10:44 -04:00
|
|
|
#include <iomanip>
|
2014-01-11 15:02:10 -05:00
|
|
|
#include <iostream>
|
2016-07-23 15:10:44 -04:00
|
|
|
#include <sstream>
|
2014-01-11 15:02:10 -05:00
|
|
|
|
2013-10-03 04:48:19 -04:00
|
|
|
#ifdef COMPILER_MSVC
|
2019-02-27 19:26:21 -05:00
|
|
|
# include <float.h>
|
2014-01-10 17:11:10 -05:00
|
|
|
/* isinf() & isnan() are C99 standards, which older MSVC doesn't provide */
|
2019-02-27 19:26:21 -05:00
|
|
|
# define ISINF(val) !((bool)_finite((double)val))
|
|
|
|
# define ISNAN(val) (bool)_isnan((double)val)
|
2014-03-04 09:25:58 -05:00
|
|
|
#else
|
2019-02-27 19:26:21 -05:00
|
|
|
# define ISINF(val) std::isinf((val))
|
|
|
|
# define ISNAN(val) std::isnan((val))
|
2014-01-11 15:02:10 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gtkmm/box.h>
|
|
|
|
#include <gtkmm/button.h>
|
|
|
|
#include <gtkmm/checkbutton.h>
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-04-21 16:33:28 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/audio_buffer.h"
|
|
|
|
#include "ardour/data_type.h"
|
2009-05-04 11:50:51 -04:00
|
|
|
#include "ardour/chan_mapping.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ardour/plugin_insert.h"
|
2009-10-30 11:30:22 -04:00
|
|
|
#include "ardour/session.h"
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2014-01-11 15:02:10 -05:00
|
|
|
#include "plugin_eq_gui.h"
|
|
|
|
#include "fft.h"
|
|
|
|
#include "ardour_ui.h"
|
|
|
|
#include "gui_thread.h"
|
2022-11-01 13:00:51 -04:00
|
|
|
#include "ui_config.h"
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2011-04-22 23:34:42 -04:00
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
using namespace ARDOUR;
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
PluginEqGui::PluginEqGui (std::shared_ptr<ARDOUR::PluginInsert> pluginInsert)
|
2019-02-27 21:43:22 -05:00
|
|
|
: _min_dB (-12.0)
|
|
|
|
, _max_dB (+12.0)
|
|
|
|
, _step_dB (3.0)
|
|
|
|
, _block_size (0)
|
|
|
|
, _buffer_size (0)
|
|
|
|
, _signal_buffer_size (0)
|
|
|
|
, _impulse_fft (0)
|
|
|
|
, _signal_input_fft (0)
|
|
|
|
, _signal_output_fft (0)
|
|
|
|
, _plugin_insert (pluginInsert)
|
|
|
|
, _pointer_in_area_xpos (-1)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2008-10-20 14:57:34 -04:00
|
|
|
_signal_analysis_running = false;
|
2017-09-18 12:39:17 -04:00
|
|
|
_samplerate = ARDOUR_UI::instance()->the_session()->sample_rate();
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_log_coeff = (1.0 - 2.0 * (1000.0 / (_samplerate / 2.0))) / powf (1000.0 / (_samplerate / 2.0), 2.0);
|
|
|
|
_log_max = log10f (1 + _log_coeff);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
// Setup analysis drawing area
|
2008-10-15 15:21:26 -04:00
|
|
|
_analysis_scale_surface = 0;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
_analysis_area = new Gtk::DrawingArea();
|
2010-08-28 10:56:13 -04:00
|
|
|
_analysis_width = 256.0;
|
2022-11-01 13:00:51 -04:00
|
|
|
_analysis_height = std::max<float> (256.0, 256.0 * UIConfiguration::instance().get_ui_scale ());
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_area->set_size_request (_analysis_width, _analysis_height);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_area->add_events (Gdk::POINTER_MOTION_MASK | Gdk::LEAVE_NOTIFY_MASK | Gdk::BUTTON_PRESS_MASK);
|
2016-07-23 15:10:44 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
_analysis_area->signal_expose_event().connect (sigc::mem_fun (*this, &PluginEqGui::expose_analysis_area));
|
|
|
|
_analysis_area->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginEqGui::resize_analysis_area));
|
|
|
|
_analysis_area->signal_motion_notify_event().connect (sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseover));
|
|
|
|
_analysis_area->signal_leave_notify_event().connect (sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseexit));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
// dB selection
|
2019-02-27 21:43:22 -05:00
|
|
|
dBScaleModel = Gtk::ListStore::create (dBColumns);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2015-10-12 13:34:00 -04:00
|
|
|
dBScaleCombo = new Gtk::ComboBox (dBScaleModel, false);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
#define ADD_DB_ROW(MIN,MAX,STEP,NAME) \
|
|
|
|
{ \
|
|
|
|
Gtk::TreeModel::Row row = *(dBScaleModel->append()); \
|
|
|
|
row[dBColumns.dBMin] = (MIN); \
|
|
|
|
row[dBColumns.dBMax] = (MAX); \
|
|
|
|
row[dBColumns.dBStep] = (STEP); \
|
|
|
|
row[dBColumns.name] = NAME; \
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_DB_ROW( -6, +6, 1, "-6dB .. +6dB");
|
|
|
|
ADD_DB_ROW(-12, +12, 3, "-12dB .. +12dB");
|
2022-11-01 13:00:51 -04:00
|
|
|
ADD_DB_ROW(-15, +15, 3, "-15dB .. +15dB");
|
2008-10-13 15:45:20 -04:00
|
|
|
ADD_DB_ROW(-24, +24, 5, "-24dB .. +24dB");
|
|
|
|
ADD_DB_ROW(-36, +36, 6, "-36dB .. +36dB");
|
2008-10-20 14:57:34 -04:00
|
|
|
ADD_DB_ROW(-64, +64,12, "-64dB .. +64dB");
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
#undef ADD_DB_ROW
|
|
|
|
|
|
|
|
dBScaleCombo -> pack_start(dBColumns.name);
|
|
|
|
dBScaleCombo -> set_active(1);
|
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
dBScaleCombo -> signal_changed().connect (sigc::mem_fun(*this, &PluginEqGui::change_dB_scale));
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-04-21 16:33:28 -04:00
|
|
|
Gtk::Label *dBComboLabel = new Gtk::Label (_("Range:"));
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-04-21 16:33:28 -04:00
|
|
|
Gtk::HBox *dBSelectBin = new Gtk::HBox (false, 4);
|
2019-02-27 21:12:04 -05:00
|
|
|
dBSelectBin->add (*manage(dBComboLabel));
|
|
|
|
dBSelectBin->add (*manage(dBScaleCombo));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-04-21 16:33:28 -04:00
|
|
|
_live_signal_combo = new Gtk::ComboBoxText ();
|
2022-01-26 15:11:15 -05:00
|
|
|
_live_signal_combo->append (_("Off"));
|
|
|
|
_live_signal_combo->append (_("Output / Input"));
|
|
|
|
_live_signal_combo->append (_("Input"));
|
|
|
|
_live_signal_combo->append (_("Output"));
|
|
|
|
_live_signal_combo->append (_("Input +40dB"));
|
|
|
|
_live_signal_combo->append (_("Output +40dB"));
|
2019-04-21 16:33:28 -04:00
|
|
|
_live_signal_combo->set_active (0);
|
|
|
|
|
|
|
|
Gtk::Label *live_signal_label = new Gtk::Label (_("Live signal:"));
|
|
|
|
|
|
|
|
Gtk::HBox *liveSelectBin = new Gtk::HBox (false, 4);
|
|
|
|
liveSelectBin->add (*manage(live_signal_label));
|
|
|
|
liveSelectBin->add (*manage(_live_signal_combo));
|
2018-04-30 16:24:35 -04:00
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
// Phase checkbutton
|
2010-11-21 17:37:58 -05:00
|
|
|
_phase_button = new Gtk::CheckButton (_("Show phase"));
|
2019-02-27 21:43:22 -05:00
|
|
|
_phase_button->set_active (true);
|
2019-02-27 21:12:04 -05:00
|
|
|
_phase_button->signal_toggled().connect (sigc::mem_fun(*this, &PluginEqGui::redraw_scales));
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2016-07-23 15:10:44 -04:00
|
|
|
// Freq/dB info for mouse over
|
|
|
|
_pointer_info = new Gtk::Label ("", 1, 0.5);
|
2019-02-27 21:43:22 -05:00
|
|
|
_pointer_info->set_name ("PluginAnalysisInfoLabel");
|
2023-01-16 15:41:22 -05:00
|
|
|
Gtkmm2ext::set_size_request_to_display_given_text (*_pointer_info, u8"10.0kHz_000.0dB_180.0\u00B0", 0, 0);
|
2016-07-23 15:10:44 -04:00
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
// populate table
|
2018-04-30 16:24:35 -04:00
|
|
|
attach (*manage(_analysis_area), 0, 4, 0, 1);
|
|
|
|
attach (*manage(dBSelectBin), 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
|
2019-04-21 16:33:28 -04:00
|
|
|
attach (*manage(liveSelectBin), 1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 4, 0);
|
|
|
|
attach (*manage(_phase_button), 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 4, 0);
|
2018-04-30 16:24:35 -04:00
|
|
|
attach (*manage(_pointer_info), 3, 4, 1, 2, Gtk::FILL, Gtk::SHRINK);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::~PluginEqGui ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2020-10-05 13:30:54 -04:00
|
|
|
stop_updating ();
|
2011-04-19 12:05:28 -04:00
|
|
|
stop_listening ();
|
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
if (_analysis_scale_surface) {
|
|
|
|
cairo_surface_destroy (_analysis_scale_surface);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
delete _impulse_fft;
|
2011-04-19 12:05:28 -04:00
|
|
|
_impulse_fft = 0;
|
2008-10-20 14:57:34 -04:00
|
|
|
delete _signal_input_fft;
|
2011-04-19 12:05:28 -04:00
|
|
|
_signal_input_fft = 0;
|
2008-10-20 14:57:34 -04:00
|
|
|
delete _signal_output_fft;
|
2011-04-19 12:05:28 -04:00
|
|
|
_signal_output_fft = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
// all gui objects are *manage'd by the inherited Table object
|
|
|
|
}
|
|
|
|
|
2018-10-24 22:25:15 -04:00
|
|
|
static inline float
|
2019-02-27 21:43:22 -05:00
|
|
|
power_to_dB (float a)
|
2018-10-24 22:25:15 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
return 10.0 * log10f (a);
|
2018-10-24 22:25:15 -04:00
|
|
|
}
|
|
|
|
|
2011-04-19 12:05:28 -04:00
|
|
|
void
|
|
|
|
PluginEqGui::start_listening ()
|
|
|
|
{
|
|
|
|
if (!_plugin) {
|
2019-02-27 19:26:21 -05:00
|
|
|
_plugin = _plugin_insert->get_impulse_analysis_plugin ();
|
2011-04-19 12:05:28 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
_plugin->activate ();
|
|
|
|
set_buffer_size (8192, 16384);
|
|
|
|
_block_size = 0; // re-initialize the plugin next time.
|
|
|
|
|
|
|
|
/* Connect the realtime signal collection callback */
|
2012-04-25 08:58:19 -04:00
|
|
|
_plugin_insert->AnalysisDataGathered.connect (analysis_connection, invalidator (*this), boost::bind (&PluginEqGui::signal_collect_callback, this, _1, _2), gui_context());
|
2011-04-19 12:05:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginEqGui::stop_listening ()
|
|
|
|
{
|
|
|
|
analysis_connection.disconnect ();
|
2020-10-05 13:30:54 -04:00
|
|
|
if (_plugin) {
|
|
|
|
_plugin->deactivate ();
|
|
|
|
_plugin->drop_references ();
|
2020-10-05 23:24:34 -04:00
|
|
|
_plugin.reset ();
|
2020-10-05 13:30:54 -04:00
|
|
|
}
|
2011-04-19 12:05:28 -04:00
|
|
|
}
|
2008-10-15 15:21:26 -04:00
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::on_hide ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
stop_updating ();
|
2020-10-05 13:30:54 -04:00
|
|
|
stop_listening ();
|
2019-02-27 21:43:22 -05:00
|
|
|
Gtk::Table::on_hide ();
|
2008-10-15 15:21:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::stop_updating ()
|
2008-10-15 15:21:26 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
if (_update_connection.connected ()) {
|
|
|
|
_update_connection.disconnect ();
|
2008-10-15 15:21:26 -04:00
|
|
|
}
|
2019-04-21 16:33:28 -04:00
|
|
|
_signal_analysis_running = false;
|
2008-10-15 15:21:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::start_updating ()
|
2008-10-15 15:21:26 -04:00
|
|
|
{
|
2022-01-26 15:21:06 -05:00
|
|
|
if (!_update_connection.connected() && get_visible()) {
|
2019-08-24 11:11:10 -04:00
|
|
|
_update_connection = Glib::signal_timeout().connect (sigc::mem_fun (this, &PluginEqGui::timeout_callback), 250, Glib::PRIORITY_DEFAULT_IDLE);
|
2008-10-15 15:21:26 -04:00
|
|
|
}
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::on_show ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
Gtk::Table::on_show ();
|
2008-10-15 15:21:26 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
start_updating ();
|
2020-10-05 13:30:54 -04:00
|
|
|
start_listening ();
|
2008-10-15 15:21:26 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
Gtk::Widget *toplevel = get_toplevel ();
|
2011-04-19 12:05:28 -04:00
|
|
|
if (toplevel) {
|
2019-02-27 21:43:22 -05:00
|
|
|
if (!_window_unmap_connection.connected ()) {
|
|
|
|
_window_unmap_connection = toplevel->signal_unmap().connect (sigc::mem_fun (this, &PluginEqGui::stop_updating));
|
2011-04-19 12:05:28 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
if (!_window_map_connection.connected ()) {
|
|
|
|
_window_map_connection = toplevel->signal_map().connect (sigc::mem_fun (this, &PluginEqGui::start_updating));
|
2011-04-19 12:05:28 -04:00
|
|
|
}
|
2008-10-15 15:21:26 -04:00
|
|
|
}
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::change_dB_scale ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
Gtk::TreeModel::iterator iter = dBScaleCombo -> get_active ();
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
Gtk::TreeModel::Row row;
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
if (iter && (row = *iter)) {
|
2008-10-15 15:21:26 -04:00
|
|
|
_min_dB = row[dBColumns.dBMin];
|
|
|
|
_max_dB = row[dBColumns.dBMax];
|
|
|
|
_step_dB = row[dBColumns.dBStep];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
redraw_scales ();
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::redraw_scales ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
if (_analysis_scale_surface) {
|
|
|
|
cairo_surface_destroy (_analysis_scale_surface);
|
|
|
|
_analysis_scale_surface = 0;
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_area->queue_draw ();
|
2008-10-20 14:57:34 -04:00
|
|
|
|
|
|
|
// TODO: Add graph legend!
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::set_buffer_size (uint32_t size, uint32_t signal_size)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2011-04-19 12:05:28 -04:00
|
|
|
if (_buffer_size == size && _signal_buffer_size == signal_size) {
|
2008-10-13 15:45:20 -04:00
|
|
|
return;
|
2011-04-19 12:05:28 -04:00
|
|
|
}
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2016-07-14 12:48:31 -04:00
|
|
|
GTKArdour::FFT *tmp1 = _impulse_fft;
|
|
|
|
GTKArdour::FFT *tmp2 = _signal_input_fft;
|
|
|
|
GTKArdour::FFT *tmp3 = _signal_output_fft;
|
2008-10-20 14:57:34 -04:00
|
|
|
|
|
|
|
try {
|
2019-02-27 21:43:22 -05:00
|
|
|
_impulse_fft = new GTKArdour::FFT (size);
|
|
|
|
_signal_input_fft = new GTKArdour::FFT (signal_size);
|
|
|
|
_signal_output_fft = new GTKArdour::FFT (signal_size);
|
2019-02-27 21:12:04 -05:00
|
|
|
} catch (...) {
|
2008-10-20 14:57:34 -04:00
|
|
|
// Don't care about lost memory, we're screwed anyhow
|
|
|
|
_impulse_fft = tmp1;
|
|
|
|
_signal_input_fft = tmp2;
|
|
|
|
_signal_output_fft = tmp3;
|
|
|
|
throw;
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2008-12-18 14:31:00 -05:00
|
|
|
delete tmp1;
|
|
|
|
delete tmp2;
|
|
|
|
delete tmp3;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-10-20 14:57:34 -04:00
|
|
|
_buffer_size = size;
|
|
|
|
_signal_buffer_size = signal_size;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
/* allocate separate in+out buffers, VST cannot process in-place */
|
2016-07-14 12:43:19 -04:00
|
|
|
ARDOUR::ChanCount acount (_plugin->get_info()->n_inputs + _plugin->get_info()->n_outputs);
|
|
|
|
ARDOUR::ChanCount ccount = ARDOUR::ChanCount::max (_plugin->get_info()->n_inputs, _plugin->get_info()->n_outputs);
|
2011-04-19 12:05:28 -04:00
|
|
|
|
2010-10-09 08:17:46 -04:00
|
|
|
for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
|
2016-07-14 12:43:19 -04:00
|
|
|
_bufferset.ensure_buffers (*i, acount.get (*i), _buffer_size);
|
|
|
|
_collect_bufferset.ensure_buffers (*i, ccount.get (*i), _buffer_size);
|
2010-10-09 08:17:46 -04:00
|
|
|
}
|
|
|
|
|
2016-07-14 12:43:19 -04:00
|
|
|
_bufferset.set_count (acount);
|
|
|
|
_collect_bufferset.set_count (ccount);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2011-04-19 12:05:28 -04:00
|
|
|
PluginEqGui::resize_analysis_area (Gtk::Allocation& size)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2008-10-15 15:21:26 -04:00
|
|
|
_analysis_width = (float)size.get_width();
|
|
|
|
_analysis_height = (float)size.get_height();
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
if (_analysis_scale_surface) {
|
|
|
|
cairo_surface_destroy (_analysis_scale_surface);
|
|
|
|
_analysis_scale_surface = 0;
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-27 21:12:04 -05:00
|
|
|
PluginEqGui::timeout_callback ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2008-10-20 14:57:34 -04:00
|
|
|
if (!_signal_analysis_running) {
|
|
|
|
_signal_analysis_running = true;
|
2019-02-27 21:12:04 -05:00
|
|
|
_plugin_insert -> collect_signal_for_analysis (_signal_buffer_size);
|
2008-10-20 14:57:34 -04:00
|
|
|
}
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
run_impulse_analysis ();
|
2008-10-13 15:45:20 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:12:04 -05:00
|
|
|
PluginEqGui::signal_collect_callback (ARDOUR::BufferSet* in, ARDOUR::BufferSet* out)
|
2008-10-20 14:57:34 -04:00
|
|
|
{
|
2016-07-14 12:48:31 -04:00
|
|
|
ENSURE_GUI_THREAD (*this, &PluginEqGui::signal_collect_callback, in, out);
|
2008-10-20 14:57:34 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_signal_input_fft ->reset ();
|
|
|
|
_signal_output_fft->reset ();
|
2008-10-20 14:57:34 -04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < _plugin_insert->input_streams().n_audio(); ++i) {
|
2019-02-27 21:43:22 -05:00
|
|
|
_signal_input_fft ->analyze (in ->get_audio (i).data(), GTKArdour::FFT::HANN);
|
2008-10-20 14:57:34 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-10-20 14:57:34 -04:00
|
|
|
for (uint32_t i = 0; i < _plugin_insert->output_streams().n_audio(); ++i) {
|
2019-02-27 21:43:22 -05:00
|
|
|
_signal_output_fft->analyze (out->get_audio (i).data(), GTKArdour::FFT::HANN);
|
2008-10-20 14:57:34 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_signal_input_fft ->calculate ();
|
|
|
|
_signal_output_fft->calculate ();
|
2008-10-20 14:57:34 -04:00
|
|
|
|
|
|
|
_signal_analysis_running = false;
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_area->queue_draw ();
|
2008-10-20 14:57:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::run_impulse_analysis ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2011-11-01 19:19:03 -04:00
|
|
|
/* Allocate some thread-local buffers so that Plugin::connect_and_run can use them */
|
|
|
|
ARDOUR_UI::instance()->get_process_buffers ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
uint32_t inputs = _plugin->get_info()->n_inputs.n_audio();
|
|
|
|
uint32_t outputs = _plugin->get_info()->n_outputs.n_audio();
|
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
/* Create the impulse, can't use silence() because consecutive calls won't work */
|
2008-10-13 15:45:20 -04:00
|
|
|
for (uint32_t i = 0; i < inputs; ++i) {
|
2019-02-27 21:43:22 -05:00
|
|
|
ARDOUR::AudioBuffer& buf = _bufferset.get_audio (i);
|
|
|
|
ARDOUR::Sample* d = buf.data ();
|
|
|
|
memset (d, 0, sizeof (ARDOUR::Sample) * _buffer_size);
|
2008-10-13 15:45:20 -04:00
|
|
|
*d = 1.0;
|
|
|
|
}
|
2009-03-07 06:17:06 -05:00
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
/* Silence collect buffers to copy data to */
|
|
|
|
for (uint32_t i = 0; i < outputs; ++i) {
|
2019-02-27 21:43:22 -05:00
|
|
|
ARDOUR::AudioBuffer &buf = _collect_bufferset.get_audio (i);
|
|
|
|
ARDOUR::Sample *d = buf.data ();
|
|
|
|
memset (d, 0, sizeof (ARDOUR::Sample) * _buffer_size);
|
2019-02-27 19:26:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create default linear I/O maps */
|
|
|
|
ARDOUR::ChanMapping in_map (_plugin->get_info()->n_inputs);
|
|
|
|
ARDOUR::ChanMapping out_map (_plugin->get_info()->n_outputs);
|
|
|
|
/* map output buffers after input buffers (no inplace for VST) */
|
2016-07-14 12:43:19 -04:00
|
|
|
out_map.offset_to (DataType::AUDIO, inputs);
|
2009-03-07 06:17:06 -05:00
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
/* run at most at session's block size chunks.
|
|
|
|
*
|
|
|
|
* This is important since VSTs may call audioMasterGetBlockSize
|
2021-10-30 16:24:16 -04:00
|
|
|
* or access various other /real/ session parameters using the
|
2019-02-27 19:26:21 -05:00
|
|
|
* audioMasterCallback
|
|
|
|
*/
|
|
|
|
samplecnt_t block_size = ARDOUR_UI::instance()->the_session()->get_block_size();
|
|
|
|
if (_block_size != block_size) {
|
|
|
|
_block_size = block_size;
|
|
|
|
_plugin->set_block_size (block_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
samplepos_t sample_pos = 0;
|
2019-07-17 10:22:44 -04:00
|
|
|
samplecnt_t latency = _plugin_insert->effective_latency ();
|
2019-02-27 19:26:21 -05:00
|
|
|
samplecnt_t samples_remain = _buffer_size + latency;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-07-17 10:22:44 -04:00
|
|
|
/* Note: https://discourse.ardour.org/t/plugins-ladspa-questions/101292/15
|
|
|
|
* Capture the complete response from the beginning, and more than "latency" samples,
|
|
|
|
* Then unwrap the phase-response corresponding to reported latency, leaving the
|
|
|
|
* magnitude unchanged.
|
|
|
|
*/
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_impulse_fft->reset ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
while (samples_remain > 0) {
|
2009-03-07 06:17:06 -05:00
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
samplecnt_t n_samples = std::min (samples_remain, block_size);
|
2019-02-27 21:43:22 -05:00
|
|
|
_plugin->connect_and_run (_bufferset, sample_pos, sample_pos + n_samples, 1.0, in_map, out_map, n_samples, 0);
|
2019-02-27 19:26:21 -05:00
|
|
|
samples_remain -= n_samples;
|
|
|
|
|
|
|
|
/* zero input buffers */
|
|
|
|
if (sample_pos == 0 && samples_remain > 0) {
|
|
|
|
for (uint32_t i = 0; i < inputs; ++i) {
|
2019-02-27 21:43:22 -05:00
|
|
|
_bufferset.get_audio (i).data()[0] = 0.f;
|
2019-02-27 19:26:21 -05:00
|
|
|
}
|
2009-03-07 06:17:06 -05:00
|
|
|
}
|
2019-02-27 19:26:21 -05:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (samples_remain > 0) {
|
|
|
|
for (uint32_t i = 0; i < inputs; ++i) {
|
|
|
|
pframes_t unused;
|
2019-02-27 21:43:22 -05:00
|
|
|
assert (_bufferset.get_audio (i).check_silence (block_size, unused));
|
2009-03-07 06:17:06 -05:00
|
|
|
}
|
2019-02-27 19:26:21 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (sample_pos + n_samples > latency) {
|
|
|
|
samplecnt_t dst_off = sample_pos >= latency ? sample_pos - latency : 0;
|
|
|
|
samplecnt_t src_off = sample_pos >= latency ? 0 : latency - sample_pos;
|
|
|
|
samplecnt_t n_copy = std::min (n_samples, sample_pos + n_samples - latency);
|
|
|
|
|
|
|
|
assert (dst_off + n_copy <= _buffer_size);
|
|
|
|
assert (src_off + n_copy <= _block_size);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < outputs; ++i) {
|
2019-02-27 21:43:22 -05:00
|
|
|
memcpy (
|
|
|
|
&(_collect_bufferset.get_audio (i).data()[dst_off]),
|
|
|
|
&(_bufferset.get_audio (inputs + i).data()[src_off]),
|
|
|
|
n_copy * sizeof (float));
|
2009-03-07 06:17:06 -05:00
|
|
|
}
|
2019-02-27 19:26:21 -05:00
|
|
|
}
|
2009-03-07 06:17:06 -05:00
|
|
|
|
2019-02-27 19:26:21 -05:00
|
|
|
sample_pos += n_samples;
|
2009-03-07 06:17:06 -05:00
|
|
|
}
|
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
for (uint32_t i = 0; i < outputs; ++i) {
|
2019-02-27 21:43:22 -05:00
|
|
|
_impulse_fft->analyze (_collect_bufferset.get_audio (i).data());
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
2019-02-27 21:43:22 -05:00
|
|
|
_impulse_fft->calculate ();
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_area->queue_draw ();
|
2011-11-01 19:19:03 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
ARDOUR_UI::instance ()->drop_process_buffers ();
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2016-07-23 15:10:44 -04:00
|
|
|
void
|
2023-07-18 11:47:56 -04:00
|
|
|
PluginEqGui::update_pointer_info (float x)
|
2016-07-23 15:10:44 -04:00
|
|
|
{
|
2018-10-24 22:25:15 -04:00
|
|
|
/* find the bin corresponding to x (see plot_impulse_amplitude) */
|
|
|
|
int i = roundf ((powf (10, _log_max * x / _analysis_width) - 1.0) * _impulse_fft->bins() / _log_coeff);
|
|
|
|
float dB = power_to_dB (_impulse_fft->power_at_bin (i));
|
|
|
|
/* calc freq corresponding to bin */
|
2019-02-27 21:43:22 -05:00
|
|
|
const int freq = std::max (1, (int) roundf ((float)i / (float)_impulse_fft->bins() * _samplerate / 2.f));
|
2018-10-24 22:25:15 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
_pointer_in_area_freq = round (_analysis_width * log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max);
|
2018-10-24 22:25:15 -04:00
|
|
|
|
2016-07-23 15:10:44 -04:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::fixed;
|
|
|
|
if (freq >= 10000) {
|
2016-07-24 18:46:49 -04:00
|
|
|
ss << std::setprecision (1) << freq / 1000.0 << "kHz";
|
2016-07-23 15:10:44 -04:00
|
|
|
} else if (freq >= 1000) {
|
2016-07-24 18:46:49 -04:00
|
|
|
ss << std::setprecision (2) << freq / 1000.0 << "kHz";
|
2016-07-23 15:10:44 -04:00
|
|
|
} else {
|
|
|
|
ss << std::setprecision (0) << freq << "Hz";
|
|
|
|
}
|
2019-02-27 21:43:22 -05:00
|
|
|
ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << dB;
|
|
|
|
ss << std::setw (0) << "dB";
|
2018-10-24 22:25:15 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
if (_phase_button->get_active ()) {
|
2018-10-24 22:25:15 -04:00
|
|
|
float phase = 180. * _impulse_fft->phase_at_bin (i) / M_PI;
|
2019-02-27 21:43:22 -05:00
|
|
|
ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << phase;
|
2023-01-16 15:41:22 -05:00
|
|
|
ss << std::setw (0) << u8"\u00B0";
|
2018-10-24 22:25:15 -04:00
|
|
|
}
|
2019-02-27 21:43:22 -05:00
|
|
|
_pointer_info->set_text (ss.str());
|
2016-07-23 15:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::analysis_area_mouseover (GdkEventMotion *event)
|
2016-07-23 15:10:44 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
update_pointer_info (event->x);
|
2018-10-24 22:25:15 -04:00
|
|
|
_pointer_in_area_xpos = event->x;
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_area->queue_draw ();
|
2016-07-23 15:10:44 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::analysis_area_mouseexit (GdkEventCrossing *)
|
2016-07-23 15:10:44 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
_pointer_info->set_text ("");
|
2018-10-24 22:25:15 -04:00
|
|
|
_pointer_in_area_xpos = -1;
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_area->queue_draw ();
|
2016-07-23 15:10:44 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-13 15:45:20 -04:00
|
|
|
bool
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::expose_analysis_area (GdkEventExpose *)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2019-02-27 21:43:22 -05:00
|
|
|
redraw_analysis_area ();
|
2011-04-19 12:05:28 -04:00
|
|
|
return true;
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::draw_analysis_scales (cairo_t *ref_cr)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
|
|
|
// TODO: check whether we need rounding
|
2019-02-27 21:43:22 -05:00
|
|
|
_analysis_scale_surface = cairo_surface_create_similar (cairo_get_target (ref_cr),
|
2016-07-14 12:48:31 -04:00
|
|
|
CAIRO_CONTENT_COLOR,
|
|
|
|
_analysis_width,
|
|
|
|
_analysis_height);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
cairo_t *cr = cairo_create (_analysis_scale_surface);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
|
|
|
|
cairo_rectangle (cr, 0.0, 0.0, _analysis_width, _analysis_height);
|
|
|
|
cairo_fill (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
draw_scales_power (_analysis_area, cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
if (_phase_button->get_active ()) {
|
|
|
|
draw_scales_phase (_analysis_area, cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_destroy (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::redraw_analysis_area ()
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cr = gdk_cairo_create (GDK_DRAWABLE(_analysis_area->get_window()->gobj()));
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
if (_analysis_scale_surface == 0) {
|
2019-02-27 21:43:22 -05:00
|
|
|
draw_analysis_scales (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_copy_page (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_surface (cr, _analysis_scale_surface, 0.0, 0.0);
|
|
|
|
cairo_paint (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2018-10-24 22:25:15 -04:00
|
|
|
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
|
|
|
|
2008-10-15 15:21:26 -04:00
|
|
|
if (_phase_button->get_active()) {
|
2019-02-27 21:12:04 -05:00
|
|
|
plot_impulse_phase (_analysis_area, cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
2018-10-24 22:25:15 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
plot_impulse_amplitude (_analysis_area, cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2018-10-24 22:25:15 -04:00
|
|
|
if (_pointer_in_area_xpos >= 0) {
|
|
|
|
update_pointer_info (_pointer_in_area_xpos);
|
|
|
|
}
|
|
|
|
|
2019-04-21 16:33:28 -04:00
|
|
|
if (_live_signal_combo->get_active_row_number() > 0) {
|
2019-02-27 21:43:22 -05:00
|
|
|
plot_signal_amplitude_difference (_analysis_area, cr);
|
2018-04-30 16:24:35 -04:00
|
|
|
}
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2018-10-24 22:25:15 -04:00
|
|
|
if (_pointer_in_area_xpos >= 0 && _pointer_in_area_freq > 0) {
|
|
|
|
const double dashed[] = {0.0, 2.0};
|
|
|
|
cairo_set_dash (cr, dashed, 2, 0);
|
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
|
|
|
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
|
|
|
|
cairo_set_line_width (cr, 1.0);
|
2023-07-18 11:47:56 -04:00
|
|
|
cairo_move_to (cr, _pointer_in_area_freq + .5, .5);
|
2023-07-17 22:55:13 -04:00
|
|
|
cairo_line_to (cr, _pointer_in_area_freq + .5, _analysis_height + .5);
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_stroke (cr);
|
2018-10-24 22:25:15 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_destroy (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2008-10-20 14:57:34 -04:00
|
|
|
#define PHASE_PROPORTION 0.5
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::draw_scales_phase (Gtk::Widget*, cairo_t *cr)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
|
|
|
float y;
|
|
|
|
cairo_font_extents_t extents;
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_font_extents (cr, &extents);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
cairo_text_extents_t t_ext;
|
|
|
|
|
2019-02-27 22:15:37 -05:00
|
|
|
for (uint32_t i = 0; i < 5; i++) {
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
y = _analysis_height / 2.0 - (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, .8, .9, 0.2);
|
2008-10-13 15:45:20 -04:00
|
|
|
if (i == 0) {
|
2023-01-16 15:41:22 -05:00
|
|
|
snprintf (buf,256, u8"0\u00b0");
|
2008-10-13 15:45:20 -04:00
|
|
|
} else {
|
2023-01-16 15:41:22 -05:00
|
|
|
snprintf (buf,256, u8"%d\u00b0", (i * 45));
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_text_extents (cr, buf, &t_ext);
|
|
|
|
cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
|
|
|
|
cairo_show_text (cr, buf);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-02-27 22:15:37 -05:00
|
|
|
if (i == 0) {
|
2008-10-13 15:45:20 -04:00
|
|
|
continue;
|
2019-02-27 22:15:37 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2023-07-17 22:55:13 -04:00
|
|
|
y = roundf (y) + .5;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 22:15:37 -05:00
|
|
|
cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_move_to (cr, 0.0, y);
|
|
|
|
cairo_line_to (cr, _analysis_width, y);
|
2019-02-27 22:15:37 -05:00
|
|
|
cairo_set_line_width (cr, 1);
|
|
|
|
cairo_stroke (cr);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
y = _analysis_height / 2.0 + (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
|
2023-07-18 11:47:56 -04:00
|
|
|
y = roundf (y);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
// label
|
2023-01-16 15:41:22 -05:00
|
|
|
snprintf (buf,256, u8"-%d\u00b0", (i * 45));
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, .8, .9, 0.2);
|
|
|
|
cairo_text_extents (cr, buf, &t_ext);
|
|
|
|
cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
|
|
|
|
cairo_show_text (cr, buf);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
// line
|
2023-07-18 11:47:56 -04:00
|
|
|
y += .5;
|
2019-02-27 22:15:37 -05:00
|
|
|
cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_move_to (cr, 0.0, y);
|
|
|
|
cairo_line_to (cr, _analysis_width, y);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 22:15:37 -05:00
|
|
|
cairo_set_line_width (cr, 1);
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2019-02-27 21:12:04 -05:00
|
|
|
PluginEqGui::plot_impulse_phase (Gtk::Widget *w, cairo_t *cr)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
|
|
|
float x,y;
|
|
|
|
|
|
|
|
int prevX = 0;
|
|
|
|
float avgY = 0.0;
|
|
|
|
int avgNum = 0;
|
|
|
|
|
2008-12-12 09:43:24 -05:00
|
|
|
// float width = w->get_width();
|
2019-02-27 21:43:22 -05:00
|
|
|
float height = w->get_height ();
|
2019-02-27 22:15:37 -05:00
|
|
|
float analysis_height_2 = _analysis_height / 2.f;
|
2008-10-20 14:57:34 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgba (cr, 0.95, 0.3, 0.2, 1.0);
|
|
|
|
for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
|
2008-10-13 15:45:20 -04:00
|
|
|
// x coordinate of bin i
|
2019-02-27 21:43:22 -05:00
|
|
|
x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
|
2008-10-15 15:21:26 -04:00
|
|
|
x *= _analysis_width;
|
2023-07-18 11:47:56 -04:00
|
|
|
x = roundf (x);
|
2019-02-27 22:15:37 -05:00
|
|
|
y = analysis_height_2 - (_impulse_fft->phase_at_bin (i) / M_PI) * analysis_height_2 * PHASE_PROPORTION;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
if (i == 0) {
|
2023-07-18 11:47:56 -04:00
|
|
|
cairo_move_to (cr, x + .5, y);
|
2008-10-13 15:45:20 -04:00
|
|
|
avgY = 0;
|
|
|
|
avgNum = 0;
|
2023-07-18 11:47:56 -04:00
|
|
|
} else if (x > prevX || i == _impulse_fft->bins() - 1) {
|
2019-02-27 21:12:04 -05:00
|
|
|
avgY = avgY / (float)avgNum;
|
|
|
|
if (avgY > (height * 10.0)) {
|
|
|
|
avgY = height * 10.0;
|
|
|
|
}
|
|
|
|
if (avgY < (-height * 10.0)) {
|
|
|
|
avgY = -height * 10.0;
|
|
|
|
}
|
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
cairo_line_to (cr, prevX + .5, avgY);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
avgY = 0;
|
|
|
|
avgNum = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
prevX = x;
|
2008-10-13 15:45:20 -04:00
|
|
|
avgY += y;
|
|
|
|
avgNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, 2.0);
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::draw_scales_power (Gtk::Widget */*w*/, cairo_t *cr)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
2011-04-19 12:05:28 -04:00
|
|
|
if (_impulse_fft == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-04-19 12:05:28 -04:00
|
|
|
static float scales[] = { 30.0, 70.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0, 15000.0, 20000.0, -1.0 };
|
2008-10-15 15:21:26 -04:00
|
|
|
float divisor = _samplerate / 2.0 / _impulse_fft->bins();
|
2008-10-13 15:45:20 -04:00
|
|
|
float x;
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, 1.5);
|
2022-11-01 13:00:51 -04:00
|
|
|
cairo_set_font_size (cr, ceil (10.0 * UIConfiguration::instance().get_ui_scale ()));
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
cairo_font_extents_t extents;
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_font_extents (cr, &extents);
|
2008-12-12 09:43:24 -05:00
|
|
|
// float fontXOffset = extents.descent + 1.0;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
for (uint32_t i = 0; scales[i] != -1.0; ++i) {
|
|
|
|
float bin = scales[i] / divisor;
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
x = log10f (1.0 + bin / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
|
2008-10-15 15:21:26 -04:00
|
|
|
x *= _analysis_width;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
if (scales[i] < 1000.0) {
|
2019-02-27 21:43:22 -05:00
|
|
|
snprintf (buf, 256, "%0.0f", scales[i]);
|
2008-10-13 15:45:20 -04:00
|
|
|
} else {
|
2019-02-27 21:43:22 -05:00
|
|
|
snprintf (buf, 256, "%0.0fk", scales[i]/1000.0);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
x = round (x);
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_move_to (cr, x - extents.height, 3.0);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_rotate (cr, M_PI / 2.0);
|
|
|
|
cairo_show_text (cr, buf);
|
|
|
|
cairo_rotate (cr, -M_PI / 2.0);
|
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
x += .5;
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.3, 0.3, 0.3);
|
|
|
|
cairo_move_to (cr, x, _analysis_height);
|
|
|
|
cairo_line_to (cr, x, 0.0);
|
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//double dashes[] = { 1.0, 3.0, 4.5, 3.0 };
|
|
|
|
double dashes[] = { 3.0, 5.0 };
|
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
for (float dB = 0.0; dB < _max_dB; dB += _step_dB) {
|
2023-07-18 11:47:56 -04:00
|
|
|
float y;
|
2019-02-27 21:12:04 -05:00
|
|
|
snprintf (buf, 256, "+%0.0f", dB);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
y = (_max_dB - dB) / (_max_dB - _min_dB);
|
2008-10-13 15:45:20 -04:00
|
|
|
//std::cerr << " y = " << y << std::endl;
|
2008-10-15 15:21:26 -04:00
|
|
|
y *= _analysis_height;
|
2023-07-18 11:47:56 -04:00
|
|
|
y = roundf (y);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
if (dB != 0.0) {
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
|
|
|
|
cairo_move_to (cr, 1.0, y + extents.height + 1.0);
|
|
|
|
cairo_show_text (cr, buf);
|
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
y += .5;
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
|
|
|
|
cairo_move_to (cr, 0, y);
|
|
|
|
cairo_line_to (cr, _analysis_width, y);
|
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
if (dB == 0.0) {
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_dash (cr, dashes, 2, 0.0);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
for (float dB = - _step_dB; dB > _min_dB; dB -= _step_dB) {
|
2023-07-18 11:47:56 -04:00
|
|
|
float y;
|
2019-02-27 21:43:22 -05:00
|
|
|
snprintf (buf, 256, "%0.0f", dB);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
y = (_max_dB - dB) / (_max_dB - _min_dB);
|
2008-10-15 15:21:26 -04:00
|
|
|
y *= _analysis_height;
|
2023-07-18 11:47:56 -04:00
|
|
|
y = roundf (y);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
|
|
|
|
cairo_move_to (cr, 1.0, y - extents.descent - 1.0);
|
|
|
|
cairo_show_text (cr, buf);
|
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
y += .5;
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
|
|
|
|
cairo_move_to (cr, 0, y);
|
|
|
|
cairo_line_to (cr, _analysis_width, y);
|
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_dash (cr, 0, 0, 0.0);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2019-02-27 21:12:04 -05:00
|
|
|
PluginEqGui::plot_impulse_amplitude (Gtk::Widget *w, cairo_t *cr)
|
2008-10-13 15:45:20 -04:00
|
|
|
{
|
|
|
|
float x,y;
|
|
|
|
int prevX = 0;
|
|
|
|
float avgY = 0.0;
|
|
|
|
int avgNum = 0;
|
|
|
|
|
2008-12-12 09:43:24 -05:00
|
|
|
// float width = w->get_width();
|
2019-02-27 21:43:22 -05:00
|
|
|
float height = w->get_height ();
|
2008-10-20 14:57:34 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
|
2008-10-13 15:45:20 -04:00
|
|
|
cairo_set_line_width (cr, 2.5);
|
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
|
2008-10-13 15:45:20 -04:00
|
|
|
// x coordinate of bin i
|
2019-02-27 21:12:04 -05:00
|
|
|
x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
|
2008-10-15 15:21:26 -04:00
|
|
|
x *= _analysis_width;
|
2023-07-18 11:47:56 -04:00
|
|
|
x = roundf (x);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
float yCoeff = (power_to_dB (_impulse_fft->power_at_bin (i)) - _min_dB) / (_max_dB - _min_dB);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
y = _analysis_height - _analysis_height * yCoeff;
|
2008-10-13 15:45:20 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
if (i == 0) {
|
2023-07-18 11:47:56 -04:00
|
|
|
cairo_move_to (cr, x + .5, y);
|
2008-10-13 15:45:20 -04:00
|
|
|
avgY = 0;
|
|
|
|
avgNum = 0;
|
2023-07-18 11:47:56 -04:00
|
|
|
} else if (x > prevX || i == _impulse_fft->bins() - 1) {
|
2019-02-27 21:12:04 -05:00
|
|
|
avgY = avgY / (float)avgNum;
|
|
|
|
if (avgY > (height * 10.0)) {
|
|
|
|
avgY = height * 10.0;
|
|
|
|
}
|
|
|
|
if (avgY < (-height * 10.0)) {
|
|
|
|
avgY = -height * 10.0;
|
|
|
|
}
|
2023-07-18 11:47:56 -04:00
|
|
|
cairo_line_to (cr, prevX + .5, avgY);
|
2008-10-13 15:45:20 -04:00
|
|
|
|
|
|
|
avgY = 0;
|
|
|
|
avgNum = 0;
|
|
|
|
}
|
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
prevX = x;
|
2008-10-13 15:45:20 -04:00
|
|
|
avgY += y;
|
|
|
|
avgNum++;
|
|
|
|
}
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_stroke (cr);
|
2008-10-13 15:45:20 -04:00
|
|
|
}
|
|
|
|
|
2008-10-20 14:57:34 -04:00
|
|
|
void
|
2019-02-27 21:43:22 -05:00
|
|
|
PluginEqGui::plot_signal_amplitude_difference (Gtk::Widget *w, cairo_t *cr)
|
2008-10-20 14:57:34 -04:00
|
|
|
{
|
|
|
|
float x,y;
|
|
|
|
|
|
|
|
int prevX = 0;
|
|
|
|
float avgY = 0.0;
|
|
|
|
int avgNum = 0;
|
|
|
|
|
|
|
|
float height = w->get_height();
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
|
2016-07-25 11:45:14 -04:00
|
|
|
cairo_set_line_width (cr, 1.5);
|
2008-10-20 14:57:34 -04:00
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
for (uint32_t i = 0; i < _signal_input_fft->bins() - 1; ++i) {
|
2008-10-20 14:57:34 -04:00
|
|
|
// x coordinate of bin i
|
2019-02-27 21:43:22 -05:00
|
|
|
x = log10f (1.0 + (float)i / (float)_signal_input_fft->bins() * _log_coeff) / _log_max;
|
2008-10-20 14:57:34 -04:00
|
|
|
x *= _analysis_width;
|
2023-07-18 11:47:56 -04:00
|
|
|
x = roundf (x);
|
2008-10-20 14:57:34 -04:00
|
|
|
|
2016-07-25 11:45:14 -04:00
|
|
|
float power_out = _signal_output_fft->power_at_bin (i) + 1e-30;
|
|
|
|
float power_in = _signal_input_fft ->power_at_bin (i) + 1e-30;
|
2019-04-21 16:33:28 -04:00
|
|
|
float power;
|
|
|
|
switch (_live_signal_combo->get_active_row_number()) {
|
|
|
|
case 2:
|
|
|
|
power = power_to_dB (power_in);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
power = power_to_dB (power_out);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
power = power_to_dB (power_in) + 40;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
power = power_to_dB (power_out) + 40;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
power = power_to_dB (power_out / power_in);
|
|
|
|
break;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-07-25 11:45:14 -04:00
|
|
|
assert (!ISINF(power));
|
|
|
|
assert (!ISNAN(power));
|
2008-10-20 14:57:34 -04:00
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
float yCoeff = (power - _min_dB) / (_max_dB - _min_dB);
|
2008-10-20 14:57:34 -04:00
|
|
|
|
|
|
|
y = _analysis_height - _analysis_height*yCoeff;
|
|
|
|
|
2019-02-27 21:12:04 -05:00
|
|
|
if (i == 0) {
|
2023-07-18 11:47:56 -04:00
|
|
|
cairo_move_to (cr, x + .5, y);
|
2008-10-20 14:57:34 -04:00
|
|
|
|
|
|
|
avgY = 0;
|
|
|
|
avgNum = 0;
|
2023-07-18 11:47:56 -04:00
|
|
|
} else if (x > prevX || i == _impulse_fft->bins() - 1) {
|
2019-02-27 21:43:22 -05:00
|
|
|
avgY = avgY / (float)avgNum;
|
2019-02-27 21:12:04 -05:00
|
|
|
if (avgY > (height * 10.0)) {
|
|
|
|
avgY = height * 10.0;
|
|
|
|
}
|
|
|
|
if (avgY < (-height * 10.0)) {
|
|
|
|
avgY = -height * 10.0;
|
|
|
|
}
|
2023-07-18 11:47:56 -04:00
|
|
|
cairo_line_to (cr, prevX + .5, avgY);
|
2008-10-20 14:57:34 -04:00
|
|
|
|
|
|
|
avgY = 0;
|
|
|
|
avgNum = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-10-20 14:57:34 -04:00
|
|
|
}
|
|
|
|
|
2023-07-18 11:47:56 -04:00
|
|
|
prevX = x;
|
2008-10-20 14:57:34 -04:00
|
|
|
avgY += y;
|
|
|
|
avgNum++;
|
|
|
|
}
|
|
|
|
|
2019-02-27 21:43:22 -05:00
|
|
|
cairo_stroke (cr);
|
2008-10-20 14:57:34 -04:00
|
|
|
}
|