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->signal_latency ();
411 samplecnt_t samples_remain = _buffer_size + latency;
413 _impulse_fft->reset ();
415 while (samples_remain > 0) {
417 samplecnt_t n_samples = std::min (samples_remain, block_size);
418 _plugin->connect_and_run (_bufferset, sample_pos, sample_pos + n_samples, 1.0, in_map, out_map, n_samples, 0);
419 samples_remain -= n_samples;
421 /* zero input buffers */
422 if (sample_pos == 0 && samples_remain > 0) {
423 for (uint32_t i = 0; i < inputs; ++i) {
424 _bufferset.get_audio (i).data()[0] = 0.f;
429 if (samples_remain > 0) {
430 for (uint32_t i = 0; i < inputs; ++i) {
432 assert (_bufferset.get_audio (i).check_silence (block_size, unused));
437 if (sample_pos + n_samples > latency) {
438 samplecnt_t dst_off = sample_pos >= latency ? sample_pos - latency : 0;
439 samplecnt_t src_off = sample_pos >= latency ? 0 : latency - sample_pos;
440 samplecnt_t n_copy = std::min (n_samples, sample_pos + n_samples - latency);
442 assert (dst_off + n_copy <= _buffer_size);
443 assert (src_off + n_copy <= _block_size);
445 for (uint32_t i = 0; i < outputs; ++i) {
447 &(_collect_bufferset.get_audio (i).data()[dst_off]),
448 &(_bufferset.get_audio (inputs + i).data()[src_off]),
449 n_copy * sizeof (float));
453 sample_pos += n_samples;
456 for (uint32_t i = 0; i < outputs; ++i) {
457 _impulse_fft->analyze (_collect_bufferset.get_audio (i).data());
459 _impulse_fft->calculate ();
461 _analysis_area->queue_draw ();
463 ARDOUR_UI::instance ()->drop_process_buffers ();
467 PluginEqGui::update_pointer_info( float x)
469 /* find the bin corresponding to x (see plot_impulse_amplitude) */
470 int i = roundf ((powf (10, _log_max * x / _analysis_width) - 1.0) * _impulse_fft->bins() / _log_coeff);
471 float dB = power_to_dB (_impulse_fft->power_at_bin (i));
472 /* calc freq corresponding to bin */
473 const int freq = std::max (1, (int) roundf ((float)i / (float)_impulse_fft->bins() * _samplerate / 2.f));
475 _pointer_in_area_freq = round (_analysis_width * log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max);
477 std::stringstream ss;
480 ss << std::setprecision (1) << freq / 1000.0 << "kHz";
481 } else if (freq >= 1000) {
482 ss << std::setprecision (2) << freq / 1000.0 << "kHz";
484 ss << std::setprecision (0) << freq << "Hz";
486 ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << dB;
487 ss << std::setw (0) << "dB";
489 if (_phase_button->get_active ()) {
490 float phase = 180. * _impulse_fft->phase_at_bin (i) / M_PI;
491 ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << phase;
492 ss << std::setw (0) << "\u00B0";
494 _pointer_info->set_text (ss.str());
498 PluginEqGui::analysis_area_mouseover (GdkEventMotion *event)
500 update_pointer_info (event->x);
501 _pointer_in_area_xpos = event->x;
502 _analysis_area->queue_draw ();
507 PluginEqGui::analysis_area_mouseexit (GdkEventCrossing *)
509 _pointer_info->set_text ("");
510 _pointer_in_area_xpos = -1;
511 _analysis_area->queue_draw ();
516 PluginEqGui::expose_analysis_area (GdkEventExpose *)
518 redraw_analysis_area ();
523 PluginEqGui::draw_analysis_scales (cairo_t *ref_cr)
525 // TODO: check whether we need rounding
526 _analysis_scale_surface = cairo_surface_create_similar (cairo_get_target (ref_cr),
531 cairo_t *cr = cairo_create (_analysis_scale_surface);
533 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
534 cairo_rectangle (cr, 0.0, 0.0, _analysis_width, _analysis_height);
537 draw_scales_power (_analysis_area, cr);
539 if (_phase_button->get_active ()) {
540 draw_scales_phase (_analysis_area, cr);
547 PluginEqGui::redraw_analysis_area ()
551 cr = gdk_cairo_create (GDK_DRAWABLE(_analysis_area->get_window()->gobj()));
553 if (_analysis_scale_surface == 0) {
554 draw_analysis_scales (cr);
557 cairo_copy_page (cr);
559 cairo_set_source_surface (cr, _analysis_scale_surface, 0.0, 0.0);
562 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
564 if (_phase_button->get_active()) {
565 plot_impulse_phase (_analysis_area, cr);
568 plot_impulse_amplitude (_analysis_area, cr);
570 if (_pointer_in_area_xpos >= 0) {
571 update_pointer_info (_pointer_in_area_xpos);
574 if (_live_signal_combo->get_active_row_number() > 0) {
575 plot_signal_amplitude_difference (_analysis_area, cr);
578 if (_pointer_in_area_xpos >= 0 && _pointer_in_area_freq > 0) {
579 const double dashed[] = {0.0, 2.0};
580 cairo_set_dash (cr, dashed, 2, 0);
581 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
582 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
583 cairo_set_line_width (cr, 1.0);
584 cairo_move_to (cr, _pointer_in_area_freq - .5, -.5);
585 cairo_line_to (cr, _pointer_in_area_freq - .5, _analysis_height - .5);
592 #define PHASE_PROPORTION 0.5
595 PluginEqGui::draw_scales_phase (Gtk::Widget*, cairo_t *cr)
598 cairo_font_extents_t extents;
599 cairo_font_extents (cr, &extents);
602 cairo_text_extents_t t_ext;
604 for (uint32_t i = 0; i < 5; i++) {
606 y = _analysis_height / 2.0 - (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
608 cairo_set_source_rgb (cr, .8, .9, 0.2);
610 snprintf (buf,256, "0\u00b0");
612 snprintf (buf,256, "%d\u00b0", (i * 45));
614 cairo_text_extents (cr, buf, &t_ext);
615 cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
616 cairo_show_text (cr, buf);
624 cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
625 cairo_move_to (cr, 0.0, y);
626 cairo_line_to (cr, _analysis_width, y);
627 cairo_set_line_width (cr, 1);
630 y = _analysis_height / 2.0 + (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
633 snprintf (buf,256, "-%d\u00b0", (i * 45));
634 cairo_set_source_rgb (cr, .8, .9, 0.2);
635 cairo_text_extents (cr, buf, &t_ext);
636 cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
637 cairo_show_text (cr, buf);
641 cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
642 cairo_move_to (cr, 0.0, y);
643 cairo_line_to (cr, _analysis_width, y);
645 cairo_set_line_width (cr, 1);
651 PluginEqGui::plot_impulse_phase (Gtk::Widget *w, cairo_t *cr)
659 // float width = w->get_width();
660 float height = w->get_height ();
661 float analysis_height_2 = _analysis_height / 2.f;
663 cairo_set_source_rgba (cr, 0.95, 0.3, 0.2, 1.0);
664 for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
665 // x coordinate of bin i
666 x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
667 x *= _analysis_width;
668 y = analysis_height_2 - (_impulse_fft->phase_at_bin (i) / M_PI) * analysis_height_2 * PHASE_PROPORTION;
671 cairo_move_to (cr, x, y);
674 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
675 avgY = avgY / (float)avgNum;
676 if (avgY > (height * 10.0)) {
677 avgY = height * 10.0;
679 if (avgY < (-height * 10.0)) {
680 avgY = -height * 10.0;
683 cairo_line_to (cr, prevX, avgY);
694 cairo_set_line_width (cr, 2.0);
699 PluginEqGui::draw_scales_power (Gtk::Widget */*w*/, cairo_t *cr)
701 if (_impulse_fft == 0) {
705 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 };
706 float divisor = _samplerate / 2.0 / _impulse_fft->bins();
709 cairo_set_line_width (cr, 1.5);
710 cairo_set_font_size (cr, 9);
712 cairo_font_extents_t extents;
713 cairo_font_extents (cr, &extents);
714 // float fontXOffset = extents.descent + 1.0;
718 for (uint32_t i = 0; scales[i] != -1.0; ++i) {
719 float bin = scales[i] / divisor;
721 x = log10f (1.0 + bin / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
722 x *= _analysis_width;
724 if (scales[i] < 1000.0) {
725 snprintf (buf, 256, "%0.0f", scales[i]);
727 snprintf (buf, 256, "%0.0fk", scales[i]/1000.0);
730 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
732 cairo_move_to (cr, x - extents.height, 3.0);
734 cairo_rotate (cr, M_PI / 2.0);
735 cairo_show_text (cr, buf);
736 cairo_rotate (cr, -M_PI / 2.0);
739 cairo_set_source_rgb (cr, 0.3, 0.3, 0.3);
740 cairo_move_to (cr, x, _analysis_height);
741 cairo_line_to (cr, x, 0.0);
747 //double dashes[] = { 1.0, 3.0, 4.5, 3.0 };
748 double dashes[] = { 3.0, 5.0 };
750 for (float dB = 0.0; dB < _max_dB; dB += _step_dB) {
751 snprintf (buf, 256, "+%0.0f", dB);
753 y = (_max_dB - dB) / (_max_dB - _min_dB);
754 //std::cerr << " y = " << y << std::endl;
755 y *= _analysis_height;
758 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
759 cairo_move_to (cr, 1.0, y + extents.height + 1.0);
760 cairo_show_text (cr, buf);
764 cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
765 cairo_move_to (cr, 0, y);
766 cairo_line_to (cr, _analysis_width, y);
770 cairo_set_dash (cr, dashes, 2, 0.0);
774 for (float dB = - _step_dB; dB > _min_dB; dB -= _step_dB) {
775 snprintf (buf, 256, "%0.0f", dB);
777 y = (_max_dB - dB) / (_max_dB - _min_dB);
778 y *= _analysis_height;
780 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
781 cairo_move_to (cr, 1.0, y - extents.descent - 1.0);
782 cairo_show_text (cr, buf);
785 cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
786 cairo_move_to (cr, 0, y);
787 cairo_line_to (cr, _analysis_width, y);
791 cairo_set_dash (cr, 0, 0, 0.0);
795 PluginEqGui::plot_impulse_amplitude (Gtk::Widget *w, cairo_t *cr)
802 // float width = w->get_width();
803 float height = w->get_height ();
805 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
806 cairo_set_line_width (cr, 2.5);
808 for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
809 // x coordinate of bin i
810 x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
811 x *= _analysis_width;
813 float yCoeff = (power_to_dB (_impulse_fft->power_at_bin (i)) - _min_dB) / (_max_dB - _min_dB);
815 y = _analysis_height - _analysis_height * yCoeff;
818 cairo_move_to (cr, x, y);
821 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
822 avgY = avgY / (float)avgNum;
823 if (avgY > (height * 10.0)) {
824 avgY = height * 10.0;
826 if (avgY < (-height * 10.0)) {
827 avgY = -height * 10.0;
829 cairo_line_to (cr, prevX, avgY);
844 PluginEqGui::plot_signal_amplitude_difference (Gtk::Widget *w, cairo_t *cr)
852 float height = w->get_height();
854 cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
855 cairo_set_line_width (cr, 1.5);
857 for (uint32_t i = 0; i < _signal_input_fft->bins() - 1; ++i) {
858 // x coordinate of bin i
859 x = log10f (1.0 + (float)i / (float)_signal_input_fft->bins() * _log_coeff) / _log_max;
860 x *= _analysis_width;
862 float power_out = _signal_output_fft->power_at_bin (i) + 1e-30;
863 float power_in = _signal_input_fft ->power_at_bin (i) + 1e-30;
865 switch (_live_signal_combo->get_active_row_number()) {
867 power = power_to_dB (power_in);
870 power = power_to_dB (power_out);
873 power = power_to_dB (power_in) + 40;
876 power = power_to_dB (power_out) + 40;
879 power = power_to_dB (power_out / power_in);
883 assert (!ISINF(power));
884 assert (!ISNAN(power));
886 float yCoeff = (power - _min_dB) / (_max_dB - _min_dB);
888 y = _analysis_height - _analysis_height*yCoeff;
891 cairo_move_to (cr, x, y);
895 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
896 avgY = avgY / (float)avgNum;
897 if (avgY > (height * 10.0)) {
898 avgY = height * 10.0;
900 if (avgY < (-height * 10.0)) {
901 avgY = -height * 10.0;
903 cairo_line_to (cr, prevX, avgY);