2 * Copyright (C) 2018 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2008 Paul Davis
4 * Original Author: Sampo Savolainen
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 /* isinf() & isnan() are C99 standards, which older MSVC doesn't provide */
30 # define ISINF(val) !((bool)_finite((double)val))
31 # define ISNAN(val) (bool)_isnan((double)val)
33 # define ISINF(val) std::isinf((val))
34 # define ISNAN(val) std::isnan((val))
37 #include <gtkmm/box.h>
38 #include <gtkmm/button.h>
39 #include <gtkmm/checkbutton.h>
41 #include "gtkmm2ext/utils.h"
43 #include "ardour/audio_buffer.h"
44 #include "ardour/data_type.h"
45 #include "ardour/chan_mapping.h"
46 #include "ardour/plugin_insert.h"
47 #include "ardour/session.h"
49 #include "plugin_eq_gui.h"
51 #include "ardour_ui.h"
52 #include "gui_thread.h"
56 using namespace ARDOUR;
58 PluginEqGui::PluginEqGui (boost::shared_ptr<ARDOUR::PluginInsert> pluginInsert)
64 , _signal_buffer_size (0)
66 , _signal_input_fft (0)
67 , _signal_output_fft (0)
68 , _plugin_insert (pluginInsert)
69 , _pointer_in_area_xpos (-1)
71 _signal_analysis_running = false;
72 _samplerate = ARDOUR_UI::instance()->the_session()->sample_rate();
74 _log_coeff = (1.0 - 2.0 * (1000.0 / (_samplerate / 2.0))) / powf (1000.0 / (_samplerate / 2.0), 2.0);
75 _log_max = log10f (1 + _log_coeff);
77 // Setup analysis drawing area
78 _analysis_scale_surface = 0;
80 _analysis_area = new Gtk::DrawingArea();
81 _analysis_width = 256.0;
82 _analysis_height = 256.0;
83 _analysis_area->set_size_request (_analysis_width, _analysis_height);
85 _analysis_area->add_events (Gdk::POINTER_MOTION_MASK | Gdk::LEAVE_NOTIFY_MASK | Gdk::BUTTON_PRESS_MASK);
87 _analysis_area->signal_expose_event().connect (sigc::mem_fun (*this, &PluginEqGui::expose_analysis_area));
88 _analysis_area->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginEqGui::resize_analysis_area));
89 _analysis_area->signal_motion_notify_event().connect (sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseover));
90 _analysis_area->signal_leave_notify_event().connect (sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseexit));
93 dBScaleModel = Gtk::ListStore::create (dBColumns);
95 dBScaleCombo = new Gtk::ComboBox (dBScaleModel, false);
97 #define ADD_DB_ROW(MIN,MAX,STEP,NAME) \
99 Gtk::TreeModel::Row row = *(dBScaleModel->append()); \
100 row[dBColumns.dBMin] = (MIN); \
101 row[dBColumns.dBMax] = (MAX); \
102 row[dBColumns.dBStep] = (STEP); \
103 row[dBColumns.name] = NAME; \
106 ADD_DB_ROW( -6, +6, 1, "-6dB .. +6dB");
107 ADD_DB_ROW(-12, +12, 3, "-12dB .. +12dB");
108 ADD_DB_ROW(-24, +24, 5, "-24dB .. +24dB");
109 ADD_DB_ROW(-36, +36, 6, "-36dB .. +36dB");
110 ADD_DB_ROW(-64, +64,12, "-64dB .. +64dB");
114 dBScaleCombo -> pack_start(dBColumns.name);
115 dBScaleCombo -> set_active(1);
117 dBScaleCombo -> signal_changed().connect (sigc::mem_fun(*this, &PluginEqGui::change_dB_scale));
119 Gtk::Label *dBComboLabel = new Gtk::Label (_("Range:"));
121 Gtk::HBox *dBSelectBin = new Gtk::HBox (false, 4);
122 dBSelectBin->add (*manage(dBComboLabel));
123 dBSelectBin->add (*manage(dBScaleCombo));
125 _live_signal_combo = new Gtk::ComboBoxText ();
126 _live_signal_combo->append_text (_("Off"));
127 _live_signal_combo->append_text (_("Output / Input"));
128 _live_signal_combo->append_text (_("Input"));
129 _live_signal_combo->append_text (_("Output"));
130 _live_signal_combo->append_text (_("Input +40dB"));
131 _live_signal_combo->append_text (_("Output +40dB"));
132 _live_signal_combo->set_active (0);
134 Gtk::Label *live_signal_label = new Gtk::Label (_("Live signal:"));
136 Gtk::HBox *liveSelectBin = new Gtk::HBox (false, 4);
137 liveSelectBin->add (*manage(live_signal_label));
138 liveSelectBin->add (*manage(_live_signal_combo));
141 _phase_button = new Gtk::CheckButton (_("Show phase"));
142 _phase_button->set_active (true);
143 _phase_button->signal_toggled().connect (sigc::mem_fun(*this, &PluginEqGui::redraw_scales));
145 // Freq/dB info for mouse over
146 _pointer_info = new Gtk::Label ("", 1, 0.5);
147 _pointer_info->set_name ("PluginAnalysisInfoLabel");
148 Gtkmm2ext::set_size_request_to_display_given_text (*_pointer_info, "10.0kHz_000.0dB_180.0\u00B0", 0, 0);
151 attach (*manage(_analysis_area), 0, 4, 0, 1);
152 attach (*manage(dBSelectBin), 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
153 attach (*manage(liveSelectBin), 1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 4, 0);
154 attach (*manage(_phase_button), 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 4, 0);
155 attach (*manage(_pointer_info), 3, 4, 1, 2, Gtk::FILL, Gtk::SHRINK);
158 PluginEqGui::~PluginEqGui ()
162 if (_analysis_scale_surface) {
163 cairo_surface_destroy (_analysis_scale_surface);
168 delete _signal_input_fft;
169 _signal_input_fft = 0;
170 delete _signal_output_fft;
171 _signal_output_fft = 0;
173 // all gui objects are *manage'd by the inherited Table object
177 power_to_dB (float a)
179 return 10.0 * log10f (a);
183 PluginEqGui::start_listening ()
186 _plugin = _plugin_insert->get_impulse_analysis_plugin ();
189 _plugin->activate ();
190 set_buffer_size (8192, 16384);
191 _block_size = 0; // re-initialize the plugin next time.
193 /* Connect the realtime signal collection callback */
194 _plugin_insert->AnalysisDataGathered.connect (analysis_connection, invalidator (*this), boost::bind (&PluginEqGui::signal_collect_callback, this, _1, _2), gui_context());
198 PluginEqGui::stop_listening ()
200 analysis_connection.disconnect ();
201 _plugin->deactivate ();
205 PluginEqGui::on_hide ()
208 Gtk::Table::on_hide ();
212 PluginEqGui::stop_updating ()
214 if (_update_connection.connected ()) {
215 _update_connection.disconnect ();
217 _signal_analysis_running = false;
221 PluginEqGui::start_updating ()
223 if (!_update_connection.connected() && is_visible()) {
224 _update_connection = Glib::signal_timeout().connect (sigc::mem_fun (this, &PluginEqGui::timeout_callback), 250);
229 PluginEqGui::on_show ()
231 Gtk::Table::on_show ();
235 Gtk::Widget *toplevel = get_toplevel ();
237 if (!_window_unmap_connection.connected ()) {
238 _window_unmap_connection = toplevel->signal_unmap().connect (sigc::mem_fun (this, &PluginEqGui::stop_updating));
241 if (!_window_map_connection.connected ()) {
242 _window_map_connection = toplevel->signal_map().connect (sigc::mem_fun (this, &PluginEqGui::start_updating));
248 PluginEqGui::change_dB_scale ()
250 Gtk::TreeModel::iterator iter = dBScaleCombo -> get_active ();
252 Gtk::TreeModel::Row row;
254 if (iter && (row = *iter)) {
255 _min_dB = row[dBColumns.dBMin];
256 _max_dB = row[dBColumns.dBMax];
257 _step_dB = row[dBColumns.dBStep];
264 PluginEqGui::redraw_scales ()
267 if (_analysis_scale_surface) {
268 cairo_surface_destroy (_analysis_scale_surface);
269 _analysis_scale_surface = 0;
272 _analysis_area->queue_draw ();
274 // TODO: Add graph legend!
278 PluginEqGui::set_buffer_size (uint32_t size, uint32_t signal_size)
280 if (_buffer_size == size && _signal_buffer_size == signal_size) {
284 GTKArdour::FFT *tmp1 = _impulse_fft;
285 GTKArdour::FFT *tmp2 = _signal_input_fft;
286 GTKArdour::FFT *tmp3 = _signal_output_fft;
289 _impulse_fft = new GTKArdour::FFT (size);
290 _signal_input_fft = new GTKArdour::FFT (signal_size);
291 _signal_output_fft = new GTKArdour::FFT (signal_size);
293 // Don't care about lost memory, we're screwed anyhow
295 _signal_input_fft = tmp2;
296 _signal_output_fft = tmp3;
305 _signal_buffer_size = signal_size;
307 /* allocate separate in+out buffers, VST cannot process in-place */
308 ARDOUR::ChanCount acount (_plugin->get_info()->n_inputs + _plugin->get_info()->n_outputs);
309 ARDOUR::ChanCount ccount = ARDOUR::ChanCount::max (_plugin->get_info()->n_inputs, _plugin->get_info()->n_outputs);
311 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
312 _bufferset.ensure_buffers (*i, acount.get (*i), _buffer_size);
313 _collect_bufferset.ensure_buffers (*i, ccount.get (*i), _buffer_size);
316 _bufferset.set_count (acount);
317 _collect_bufferset.set_count (ccount);
321 PluginEqGui::resize_analysis_area (Gtk::Allocation& size)
323 _analysis_width = (float)size.get_width();
324 _analysis_height = (float)size.get_height();
326 if (_analysis_scale_surface) {
327 cairo_surface_destroy (_analysis_scale_surface);
328 _analysis_scale_surface = 0;
333 PluginEqGui::timeout_callback ()
335 if (!_signal_analysis_running) {
336 _signal_analysis_running = true;
337 _plugin_insert -> collect_signal_for_analysis (_signal_buffer_size);
340 run_impulse_analysis ();
345 PluginEqGui::signal_collect_callback (ARDOUR::BufferSet* in, ARDOUR::BufferSet* out)
347 ENSURE_GUI_THREAD (*this, &PluginEqGui::signal_collect_callback, in, out);
349 _signal_input_fft ->reset ();
350 _signal_output_fft->reset ();
352 for (uint32_t i = 0; i < _plugin_insert->input_streams().n_audio(); ++i) {
353 _signal_input_fft ->analyze (in ->get_audio (i).data(), GTKArdour::FFT::HANN);
356 for (uint32_t i = 0; i < _plugin_insert->output_streams().n_audio(); ++i) {
357 _signal_output_fft->analyze (out->get_audio (i).data(), GTKArdour::FFT::HANN);
360 _signal_input_fft ->calculate ();
361 _signal_output_fft->calculate ();
363 _signal_analysis_running = false;
364 _analysis_area->queue_draw ();
368 PluginEqGui::run_impulse_analysis ()
370 /* Allocate some thread-local buffers so that Plugin::connect_and_run can use them */
371 ARDOUR_UI::instance()->get_process_buffers ();
373 uint32_t inputs = _plugin->get_info()->n_inputs.n_audio();
374 uint32_t outputs = _plugin->get_info()->n_outputs.n_audio();
376 /* Create the impulse, can't use silence() because consecutive calls won't work */
377 for (uint32_t i = 0; i < inputs; ++i) {
378 ARDOUR::AudioBuffer& buf = _bufferset.get_audio (i);
379 ARDOUR::Sample* d = buf.data ();
380 memset (d, 0, sizeof (ARDOUR::Sample) * _buffer_size);
384 /* Silence collect buffers to copy data to */
385 for (uint32_t i = 0; i < outputs; ++i) {
386 ARDOUR::AudioBuffer &buf = _collect_bufferset.get_audio (i);
387 ARDOUR::Sample *d = buf.data ();
388 memset (d, 0, sizeof (ARDOUR::Sample) * _buffer_size);
391 /* create default linear I/O maps */
392 ARDOUR::ChanMapping in_map (_plugin->get_info()->n_inputs);
393 ARDOUR::ChanMapping out_map (_plugin->get_info()->n_outputs);
394 /* map output buffers after input buffers (no inplace for VST) */
395 out_map.offset_to (DataType::AUDIO, inputs);
397 /* run at most at session's block size chunks.
399 * This is important since VSTs may call audioMasterGetBlockSize
400 * or access various other /real/ session paramaters using the
401 * audioMasterCallback
403 samplecnt_t block_size = ARDOUR_UI::instance()->the_session()->get_block_size();
404 if (_block_size != block_size) {
405 _block_size = block_size;
406 _plugin->set_block_size (block_size);
409 samplepos_t sample_pos = 0;
410 samplecnt_t latency = _plugin_insert->effective_latency ();
411 samplecnt_t samples_remain = _buffer_size + latency;
413 /* Note: https://discourse.ardour.org/t/plugins-ladspa-questions/101292/15
414 * Capture the complete response from the beginning, and more than "latency" samples,
415 * Then unwrap the phase-response corresponding to reported latency, leaving the
416 * magnitude unchanged.
419 _impulse_fft->reset ();
421 while (samples_remain > 0) {
423 samplecnt_t n_samples = std::min (samples_remain, block_size);
424 _plugin->connect_and_run (_bufferset, sample_pos, sample_pos + n_samples, 1.0, in_map, out_map, n_samples, 0);
425 samples_remain -= n_samples;
427 /* zero input buffers */
428 if (sample_pos == 0 && samples_remain > 0) {
429 for (uint32_t i = 0; i < inputs; ++i) {
430 _bufferset.get_audio (i).data()[0] = 0.f;
435 if (samples_remain > 0) {
436 for (uint32_t i = 0; i < inputs; ++i) {
438 assert (_bufferset.get_audio (i).check_silence (block_size, unused));
443 if (sample_pos + n_samples > latency) {
444 samplecnt_t dst_off = sample_pos >= latency ? sample_pos - latency : 0;
445 samplecnt_t src_off = sample_pos >= latency ? 0 : latency - sample_pos;
446 samplecnt_t n_copy = std::min (n_samples, sample_pos + n_samples - latency);
448 assert (dst_off + n_copy <= _buffer_size);
449 assert (src_off + n_copy <= _block_size);
451 for (uint32_t i = 0; i < outputs; ++i) {
453 &(_collect_bufferset.get_audio (i).data()[dst_off]),
454 &(_bufferset.get_audio (inputs + i).data()[src_off]),
455 n_copy * sizeof (float));
459 sample_pos += n_samples;
462 for (uint32_t i = 0; i < outputs; ++i) {
463 _impulse_fft->analyze (_collect_bufferset.get_audio (i).data());
465 _impulse_fft->calculate ();
467 _analysis_area->queue_draw ();
469 ARDOUR_UI::instance ()->drop_process_buffers ();
473 PluginEqGui::update_pointer_info( float x)
475 /* find the bin corresponding to x (see plot_impulse_amplitude) */
476 int i = roundf ((powf (10, _log_max * x / _analysis_width) - 1.0) * _impulse_fft->bins() / _log_coeff);
477 float dB = power_to_dB (_impulse_fft->power_at_bin (i));
478 /* calc freq corresponding to bin */
479 const int freq = std::max (1, (int) roundf ((float)i / (float)_impulse_fft->bins() * _samplerate / 2.f));
481 _pointer_in_area_freq = round (_analysis_width * log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max);
483 std::stringstream ss;
486 ss << std::setprecision (1) << freq / 1000.0 << "kHz";
487 } else if (freq >= 1000) {
488 ss << std::setprecision (2) << freq / 1000.0 << "kHz";
490 ss << std::setprecision (0) << freq << "Hz";
492 ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << dB;
493 ss << std::setw (0) << "dB";
495 if (_phase_button->get_active ()) {
496 float phase = 180. * _impulse_fft->phase_at_bin (i) / M_PI;
497 ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << phase;
498 ss << std::setw (0) << "\u00B0";
500 _pointer_info->set_text (ss.str());
504 PluginEqGui::analysis_area_mouseover (GdkEventMotion *event)
506 update_pointer_info (event->x);
507 _pointer_in_area_xpos = event->x;
508 _analysis_area->queue_draw ();
513 PluginEqGui::analysis_area_mouseexit (GdkEventCrossing *)
515 _pointer_info->set_text ("");
516 _pointer_in_area_xpos = -1;
517 _analysis_area->queue_draw ();
522 PluginEqGui::expose_analysis_area (GdkEventExpose *)
524 redraw_analysis_area ();
529 PluginEqGui::draw_analysis_scales (cairo_t *ref_cr)
531 // TODO: check whether we need rounding
532 _analysis_scale_surface = cairo_surface_create_similar (cairo_get_target (ref_cr),
537 cairo_t *cr = cairo_create (_analysis_scale_surface);
539 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
540 cairo_rectangle (cr, 0.0, 0.0, _analysis_width, _analysis_height);
543 draw_scales_power (_analysis_area, cr);
545 if (_phase_button->get_active ()) {
546 draw_scales_phase (_analysis_area, cr);
553 PluginEqGui::redraw_analysis_area ()
557 cr = gdk_cairo_create (GDK_DRAWABLE(_analysis_area->get_window()->gobj()));
559 if (_analysis_scale_surface == 0) {
560 draw_analysis_scales (cr);
563 cairo_copy_page (cr);
565 cairo_set_source_surface (cr, _analysis_scale_surface, 0.0, 0.0);
568 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
570 if (_phase_button->get_active()) {
571 plot_impulse_phase (_analysis_area, cr);
574 plot_impulse_amplitude (_analysis_area, cr);
576 if (_pointer_in_area_xpos >= 0) {
577 update_pointer_info (_pointer_in_area_xpos);
580 if (_live_signal_combo->get_active_row_number() > 0) {
581 plot_signal_amplitude_difference (_analysis_area, cr);
584 if (_pointer_in_area_xpos >= 0 && _pointer_in_area_freq > 0) {
585 const double dashed[] = {0.0, 2.0};
586 cairo_set_dash (cr, dashed, 2, 0);
587 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
588 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
589 cairo_set_line_width (cr, 1.0);
590 cairo_move_to (cr, _pointer_in_area_freq - .5, -.5);
591 cairo_line_to (cr, _pointer_in_area_freq - .5, _analysis_height - .5);
598 #define PHASE_PROPORTION 0.5
601 PluginEqGui::draw_scales_phase (Gtk::Widget*, cairo_t *cr)
604 cairo_font_extents_t extents;
605 cairo_font_extents (cr, &extents);
608 cairo_text_extents_t t_ext;
610 for (uint32_t i = 0; i < 5; i++) {
612 y = _analysis_height / 2.0 - (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
614 cairo_set_source_rgb (cr, .8, .9, 0.2);
616 snprintf (buf,256, "0\u00b0");
618 snprintf (buf,256, "%d\u00b0", (i * 45));
620 cairo_text_extents (cr, buf, &t_ext);
621 cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
622 cairo_show_text (cr, buf);
630 cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
631 cairo_move_to (cr, 0.0, y);
632 cairo_line_to (cr, _analysis_width, y);
633 cairo_set_line_width (cr, 1);
636 y = _analysis_height / 2.0 + (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
639 snprintf (buf,256, "-%d\u00b0", (i * 45));
640 cairo_set_source_rgb (cr, .8, .9, 0.2);
641 cairo_text_extents (cr, buf, &t_ext);
642 cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
643 cairo_show_text (cr, buf);
647 cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
648 cairo_move_to (cr, 0.0, y);
649 cairo_line_to (cr, _analysis_width, y);
651 cairo_set_line_width (cr, 1);
657 PluginEqGui::plot_impulse_phase (Gtk::Widget *w, cairo_t *cr)
665 // float width = w->get_width();
666 float height = w->get_height ();
667 float analysis_height_2 = _analysis_height / 2.f;
669 cairo_set_source_rgba (cr, 0.95, 0.3, 0.2, 1.0);
670 for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
671 // x coordinate of bin i
672 x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
673 x *= _analysis_width;
674 y = analysis_height_2 - (_impulse_fft->phase_at_bin (i) / M_PI) * analysis_height_2 * PHASE_PROPORTION;
677 cairo_move_to (cr, x, y);
680 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
681 avgY = avgY / (float)avgNum;
682 if (avgY > (height * 10.0)) {
683 avgY = height * 10.0;
685 if (avgY < (-height * 10.0)) {
686 avgY = -height * 10.0;
689 cairo_line_to (cr, prevX, avgY);
700 cairo_set_line_width (cr, 2.0);
705 PluginEqGui::draw_scales_power (Gtk::Widget */*w*/, cairo_t *cr)
707 if (_impulse_fft == 0) {
711 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 };
712 float divisor = _samplerate / 2.0 / _impulse_fft->bins();
715 cairo_set_line_width (cr, 1.5);
716 cairo_set_font_size (cr, 9);
718 cairo_font_extents_t extents;
719 cairo_font_extents (cr, &extents);
720 // float fontXOffset = extents.descent + 1.0;
724 for (uint32_t i = 0; scales[i] != -1.0; ++i) {
725 float bin = scales[i] / divisor;
727 x = log10f (1.0 + bin / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
728 x *= _analysis_width;
730 if (scales[i] < 1000.0) {
731 snprintf (buf, 256, "%0.0f", scales[i]);
733 snprintf (buf, 256, "%0.0fk", scales[i]/1000.0);
736 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
738 cairo_move_to (cr, x - extents.height, 3.0);
740 cairo_rotate (cr, M_PI / 2.0);
741 cairo_show_text (cr, buf);
742 cairo_rotate (cr, -M_PI / 2.0);
745 cairo_set_source_rgb (cr, 0.3, 0.3, 0.3);
746 cairo_move_to (cr, x, _analysis_height);
747 cairo_line_to (cr, x, 0.0);
753 //double dashes[] = { 1.0, 3.0, 4.5, 3.0 };
754 double dashes[] = { 3.0, 5.0 };
756 for (float dB = 0.0; dB < _max_dB; dB += _step_dB) {
757 snprintf (buf, 256, "+%0.0f", dB);
759 y = (_max_dB - dB) / (_max_dB - _min_dB);
760 //std::cerr << " y = " << y << std::endl;
761 y *= _analysis_height;
764 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
765 cairo_move_to (cr, 1.0, y + extents.height + 1.0);
766 cairo_show_text (cr, buf);
770 cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
771 cairo_move_to (cr, 0, y);
772 cairo_line_to (cr, _analysis_width, y);
776 cairo_set_dash (cr, dashes, 2, 0.0);
780 for (float dB = - _step_dB; dB > _min_dB; dB -= _step_dB) {
781 snprintf (buf, 256, "%0.0f", dB);
783 y = (_max_dB - dB) / (_max_dB - _min_dB);
784 y *= _analysis_height;
786 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
787 cairo_move_to (cr, 1.0, y - extents.descent - 1.0);
788 cairo_show_text (cr, buf);
791 cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
792 cairo_move_to (cr, 0, y);
793 cairo_line_to (cr, _analysis_width, y);
797 cairo_set_dash (cr, 0, 0, 0.0);
801 PluginEqGui::plot_impulse_amplitude (Gtk::Widget *w, cairo_t *cr)
808 // float width = w->get_width();
809 float height = w->get_height ();
811 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
812 cairo_set_line_width (cr, 2.5);
814 for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
815 // x coordinate of bin i
816 x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
817 x *= _analysis_width;
819 float yCoeff = (power_to_dB (_impulse_fft->power_at_bin (i)) - _min_dB) / (_max_dB - _min_dB);
821 y = _analysis_height - _analysis_height * yCoeff;
824 cairo_move_to (cr, x, y);
827 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
828 avgY = avgY / (float)avgNum;
829 if (avgY > (height * 10.0)) {
830 avgY = height * 10.0;
832 if (avgY < (-height * 10.0)) {
833 avgY = -height * 10.0;
835 cairo_line_to (cr, prevX, avgY);
850 PluginEqGui::plot_signal_amplitude_difference (Gtk::Widget *w, cairo_t *cr)
858 float height = w->get_height();
860 cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
861 cairo_set_line_width (cr, 1.5);
863 for (uint32_t i = 0; i < _signal_input_fft->bins() - 1; ++i) {
864 // x coordinate of bin i
865 x = log10f (1.0 + (float)i / (float)_signal_input_fft->bins() * _log_coeff) / _log_max;
866 x *= _analysis_width;
868 float power_out = _signal_output_fft->power_at_bin (i) + 1e-30;
869 float power_in = _signal_input_fft ->power_at_bin (i) + 1e-30;
871 switch (_live_signal_combo->get_active_row_number()) {
873 power = power_to_dB (power_in);
876 power = power_to_dB (power_out);
879 power = power_to_dB (power_in) + 40;
882 power = power_to_dB (power_out) + 40;
885 power = power_to_dB (power_out / power_in);
889 assert (!ISINF(power));
890 assert (!ISNAN(power));
892 float yCoeff = (power - _min_dB) / (_max_dB - _min_dB);
894 y = _analysis_height - _analysis_height*yCoeff;
897 cairo_move_to (cr, x, y);
901 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
902 avgY = avgY / (float)avgNum;
903 if (avgY > (height * 10.0)) {
904 avgY = height * 10.0;
906 if (avgY < (-height * 10.0)) {
907 avgY = -height * 10.0;
909 cairo_line_to (cr, prevX, avgY);