2 * Copyright (C) 2008-2009 Sampo Savolainen <v2@iki.fi>
3 * Copyright (C) 2008-2011 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
6 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
7 * Copyright (C) 2016 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 /* isinf() & isnan() are C99 standards, which older MSVC doesn't provide */
33 # define ISINF(val) !((bool)_finite((double)val))
34 # define ISNAN(val) (bool)_isnan((double)val)
36 # define ISINF(val) std::isinf((val))
37 # define ISNAN(val) std::isnan((val))
40 #include <gtkmm/box.h>
41 #include <gtkmm/button.h>
42 #include <gtkmm/checkbutton.h>
44 #include "gtkmm2ext/utils.h"
46 #include "ardour/audio_buffer.h"
47 #include "ardour/data_type.h"
48 #include "ardour/chan_mapping.h"
49 #include "ardour/plugin_insert.h"
50 #include "ardour/session.h"
52 #include "plugin_eq_gui.h"
54 #include "ardour_ui.h"
55 #include "gui_thread.h"
59 using namespace ARDOUR;
61 PluginEqGui::PluginEqGui (boost::shared_ptr<ARDOUR::PluginInsert> pluginInsert)
67 , _signal_buffer_size (0)
69 , _signal_input_fft (0)
70 , _signal_output_fft (0)
71 , _plugin_insert (pluginInsert)
72 , _pointer_in_area_xpos (-1)
74 _signal_analysis_running = false;
75 _samplerate = ARDOUR_UI::instance()->the_session()->sample_rate();
77 _log_coeff = (1.0 - 2.0 * (1000.0 / (_samplerate / 2.0))) / powf (1000.0 / (_samplerate / 2.0), 2.0);
78 _log_max = log10f (1 + _log_coeff);
80 // Setup analysis drawing area
81 _analysis_scale_surface = 0;
83 _analysis_area = new Gtk::DrawingArea();
84 _analysis_width = 256.0;
85 _analysis_height = 256.0;
86 _analysis_area->set_size_request (_analysis_width, _analysis_height);
88 _analysis_area->add_events (Gdk::POINTER_MOTION_MASK | Gdk::LEAVE_NOTIFY_MASK | Gdk::BUTTON_PRESS_MASK);
90 _analysis_area->signal_expose_event().connect (sigc::mem_fun (*this, &PluginEqGui::expose_analysis_area));
91 _analysis_area->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginEqGui::resize_analysis_area));
92 _analysis_area->signal_motion_notify_event().connect (sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseover));
93 _analysis_area->signal_leave_notify_event().connect (sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseexit));
96 dBScaleModel = Gtk::ListStore::create (dBColumns);
98 dBScaleCombo = new Gtk::ComboBox (dBScaleModel, false);
100 #define ADD_DB_ROW(MIN,MAX,STEP,NAME) \
102 Gtk::TreeModel::Row row = *(dBScaleModel->append()); \
103 row[dBColumns.dBMin] = (MIN); \
104 row[dBColumns.dBMax] = (MAX); \
105 row[dBColumns.dBStep] = (STEP); \
106 row[dBColumns.name] = NAME; \
109 ADD_DB_ROW( -6, +6, 1, "-6dB .. +6dB");
110 ADD_DB_ROW(-12, +12, 3, "-12dB .. +12dB");
111 ADD_DB_ROW(-24, +24, 5, "-24dB .. +24dB");
112 ADD_DB_ROW(-36, +36, 6, "-36dB .. +36dB");
113 ADD_DB_ROW(-64, +64,12, "-64dB .. +64dB");
117 dBScaleCombo -> pack_start(dBColumns.name);
118 dBScaleCombo -> set_active(1);
120 dBScaleCombo -> signal_changed().connect (sigc::mem_fun(*this, &PluginEqGui::change_dB_scale));
122 Gtk::Label *dBComboLabel = new Gtk::Label (_("Range:"));
124 Gtk::HBox *dBSelectBin = new Gtk::HBox (false, 4);
125 dBSelectBin->add (*manage(dBComboLabel));
126 dBSelectBin->add (*manage(dBScaleCombo));
128 _live_signal_combo = new Gtk::ComboBoxText ();
129 _live_signal_combo->append_text (_("Off"));
130 _live_signal_combo->append_text (_("Output / Input"));
131 _live_signal_combo->append_text (_("Input"));
132 _live_signal_combo->append_text (_("Output"));
133 _live_signal_combo->append_text (_("Input +40dB"));
134 _live_signal_combo->append_text (_("Output +40dB"));
135 _live_signal_combo->set_active (0);
137 Gtk::Label *live_signal_label = new Gtk::Label (_("Live signal:"));
139 Gtk::HBox *liveSelectBin = new Gtk::HBox (false, 4);
140 liveSelectBin->add (*manage(live_signal_label));
141 liveSelectBin->add (*manage(_live_signal_combo));
144 _phase_button = new Gtk::CheckButton (_("Show phase"));
145 _phase_button->set_active (true);
146 _phase_button->signal_toggled().connect (sigc::mem_fun(*this, &PluginEqGui::redraw_scales));
148 // Freq/dB info for mouse over
149 _pointer_info = new Gtk::Label ("", 1, 0.5);
150 _pointer_info->set_name ("PluginAnalysisInfoLabel");
151 Gtkmm2ext::set_size_request_to_display_given_text (*_pointer_info, "10.0kHz_000.0dB_180.0\u00B0", 0, 0);
154 attach (*manage(_analysis_area), 0, 4, 0, 1);
155 attach (*manage(dBSelectBin), 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
156 attach (*manage(liveSelectBin), 1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 4, 0);
157 attach (*manage(_phase_button), 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 4, 0);
158 attach (*manage(_pointer_info), 3, 4, 1, 2, Gtk::FILL, Gtk::SHRINK);
161 PluginEqGui::~PluginEqGui ()
165 if (_analysis_scale_surface) {
166 cairo_surface_destroy (_analysis_scale_surface);
171 delete _signal_input_fft;
172 _signal_input_fft = 0;
173 delete _signal_output_fft;
174 _signal_output_fft = 0;
176 // all gui objects are *manage'd by the inherited Table object
180 power_to_dB (float a)
182 return 10.0 * log10f (a);
186 PluginEqGui::start_listening ()
189 _plugin = _plugin_insert->get_impulse_analysis_plugin ();
192 _plugin->activate ();
193 set_buffer_size (8192, 16384);
194 _block_size = 0; // re-initialize the plugin next time.
196 /* Connect the realtime signal collection callback */
197 _plugin_insert->AnalysisDataGathered.connect (analysis_connection, invalidator (*this), boost::bind (&PluginEqGui::signal_collect_callback, this, _1, _2), gui_context());
201 PluginEqGui::stop_listening ()
203 analysis_connection.disconnect ();
204 _plugin->deactivate ();
208 PluginEqGui::on_hide ()
211 Gtk::Table::on_hide ();
215 PluginEqGui::stop_updating ()
217 if (_update_connection.connected ()) {
218 _update_connection.disconnect ();
220 _signal_analysis_running = false;
224 PluginEqGui::start_updating ()
226 if (!_update_connection.connected() && is_visible()) {
227 _update_connection = Glib::signal_timeout().connect (sigc::mem_fun (this, &PluginEqGui::timeout_callback), 250, Glib::PRIORITY_DEFAULT_IDLE);
232 PluginEqGui::on_show ()
234 Gtk::Table::on_show ();
238 Gtk::Widget *toplevel = get_toplevel ();
240 if (!_window_unmap_connection.connected ()) {
241 _window_unmap_connection = toplevel->signal_unmap().connect (sigc::mem_fun (this, &PluginEqGui::stop_updating));
244 if (!_window_map_connection.connected ()) {
245 _window_map_connection = toplevel->signal_map().connect (sigc::mem_fun (this, &PluginEqGui::start_updating));
251 PluginEqGui::change_dB_scale ()
253 Gtk::TreeModel::iterator iter = dBScaleCombo -> get_active ();
255 Gtk::TreeModel::Row row;
257 if (iter && (row = *iter)) {
258 _min_dB = row[dBColumns.dBMin];
259 _max_dB = row[dBColumns.dBMax];
260 _step_dB = row[dBColumns.dBStep];
267 PluginEqGui::redraw_scales ()
270 if (_analysis_scale_surface) {
271 cairo_surface_destroy (_analysis_scale_surface);
272 _analysis_scale_surface = 0;
275 _analysis_area->queue_draw ();
277 // TODO: Add graph legend!
281 PluginEqGui::set_buffer_size (uint32_t size, uint32_t signal_size)
283 if (_buffer_size == size && _signal_buffer_size == signal_size) {
287 GTKArdour::FFT *tmp1 = _impulse_fft;
288 GTKArdour::FFT *tmp2 = _signal_input_fft;
289 GTKArdour::FFT *tmp3 = _signal_output_fft;
292 _impulse_fft = new GTKArdour::FFT (size);
293 _signal_input_fft = new GTKArdour::FFT (signal_size);
294 _signal_output_fft = new GTKArdour::FFT (signal_size);
296 // Don't care about lost memory, we're screwed anyhow
298 _signal_input_fft = tmp2;
299 _signal_output_fft = tmp3;
308 _signal_buffer_size = signal_size;
310 /* allocate separate in+out buffers, VST cannot process in-place */
311 ARDOUR::ChanCount acount (_plugin->get_info()->n_inputs + _plugin->get_info()->n_outputs);
312 ARDOUR::ChanCount ccount = ARDOUR::ChanCount::max (_plugin->get_info()->n_inputs, _plugin->get_info()->n_outputs);
314 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
315 _bufferset.ensure_buffers (*i, acount.get (*i), _buffer_size);
316 _collect_bufferset.ensure_buffers (*i, ccount.get (*i), _buffer_size);
319 _bufferset.set_count (acount);
320 _collect_bufferset.set_count (ccount);
324 PluginEqGui::resize_analysis_area (Gtk::Allocation& size)
326 _analysis_width = (float)size.get_width();
327 _analysis_height = (float)size.get_height();
329 if (_analysis_scale_surface) {
330 cairo_surface_destroy (_analysis_scale_surface);
331 _analysis_scale_surface = 0;
336 PluginEqGui::timeout_callback ()
338 if (!_signal_analysis_running) {
339 _signal_analysis_running = true;
340 _plugin_insert -> collect_signal_for_analysis (_signal_buffer_size);
343 run_impulse_analysis ();
348 PluginEqGui::signal_collect_callback (ARDOUR::BufferSet* in, ARDOUR::BufferSet* out)
350 ENSURE_GUI_THREAD (*this, &PluginEqGui::signal_collect_callback, in, out);
352 _signal_input_fft ->reset ();
353 _signal_output_fft->reset ();
355 for (uint32_t i = 0; i < _plugin_insert->input_streams().n_audio(); ++i) {
356 _signal_input_fft ->analyze (in ->get_audio (i).data(), GTKArdour::FFT::HANN);
359 for (uint32_t i = 0; i < _plugin_insert->output_streams().n_audio(); ++i) {
360 _signal_output_fft->analyze (out->get_audio (i).data(), GTKArdour::FFT::HANN);
363 _signal_input_fft ->calculate ();
364 _signal_output_fft->calculate ();
366 _signal_analysis_running = false;
367 _analysis_area->queue_draw ();
371 PluginEqGui::run_impulse_analysis ()
373 /* Allocate some thread-local buffers so that Plugin::connect_and_run can use them */
374 ARDOUR_UI::instance()->get_process_buffers ();
376 uint32_t inputs = _plugin->get_info()->n_inputs.n_audio();
377 uint32_t outputs = _plugin->get_info()->n_outputs.n_audio();
379 /* Create the impulse, can't use silence() because consecutive calls won't work */
380 for (uint32_t i = 0; i < inputs; ++i) {
381 ARDOUR::AudioBuffer& buf = _bufferset.get_audio (i);
382 ARDOUR::Sample* d = buf.data ();
383 memset (d, 0, sizeof (ARDOUR::Sample) * _buffer_size);
387 /* Silence collect buffers to copy data to */
388 for (uint32_t i = 0; i < outputs; ++i) {
389 ARDOUR::AudioBuffer &buf = _collect_bufferset.get_audio (i);
390 ARDOUR::Sample *d = buf.data ();
391 memset (d, 0, sizeof (ARDOUR::Sample) * _buffer_size);
394 /* create default linear I/O maps */
395 ARDOUR::ChanMapping in_map (_plugin->get_info()->n_inputs);
396 ARDOUR::ChanMapping out_map (_plugin->get_info()->n_outputs);
397 /* map output buffers after input buffers (no inplace for VST) */
398 out_map.offset_to (DataType::AUDIO, inputs);
400 /* run at most at session's block size chunks.
402 * This is important since VSTs may call audioMasterGetBlockSize
403 * or access various other /real/ session paramaters using the
404 * audioMasterCallback
406 samplecnt_t block_size = ARDOUR_UI::instance()->the_session()->get_block_size();
407 if (_block_size != block_size) {
408 _block_size = block_size;
409 _plugin->set_block_size (block_size);
412 samplepos_t sample_pos = 0;
413 samplecnt_t latency = _plugin_insert->effective_latency ();
414 samplecnt_t samples_remain = _buffer_size + latency;
416 /* Note: https://discourse.ardour.org/t/plugins-ladspa-questions/101292/15
417 * Capture the complete response from the beginning, and more than "latency" samples,
418 * Then unwrap the phase-response corresponding to reported latency, leaving the
419 * magnitude unchanged.
422 _impulse_fft->reset ();
424 while (samples_remain > 0) {
426 samplecnt_t n_samples = std::min (samples_remain, block_size);
427 _plugin->connect_and_run (_bufferset, sample_pos, sample_pos + n_samples, 1.0, in_map, out_map, n_samples, 0);
428 samples_remain -= n_samples;
430 /* zero input buffers */
431 if (sample_pos == 0 && samples_remain > 0) {
432 for (uint32_t i = 0; i < inputs; ++i) {
433 _bufferset.get_audio (i).data()[0] = 0.f;
438 if (samples_remain > 0) {
439 for (uint32_t i = 0; i < inputs; ++i) {
441 assert (_bufferset.get_audio (i).check_silence (block_size, unused));
446 if (sample_pos + n_samples > latency) {
447 samplecnt_t dst_off = sample_pos >= latency ? sample_pos - latency : 0;
448 samplecnt_t src_off = sample_pos >= latency ? 0 : latency - sample_pos;
449 samplecnt_t n_copy = std::min (n_samples, sample_pos + n_samples - latency);
451 assert (dst_off + n_copy <= _buffer_size);
452 assert (src_off + n_copy <= _block_size);
454 for (uint32_t i = 0; i < outputs; ++i) {
456 &(_collect_bufferset.get_audio (i).data()[dst_off]),
457 &(_bufferset.get_audio (inputs + i).data()[src_off]),
458 n_copy * sizeof (float));
462 sample_pos += n_samples;
465 for (uint32_t i = 0; i < outputs; ++i) {
466 _impulse_fft->analyze (_collect_bufferset.get_audio (i).data());
468 _impulse_fft->calculate ();
470 _analysis_area->queue_draw ();
472 ARDOUR_UI::instance ()->drop_process_buffers ();
476 PluginEqGui::update_pointer_info( float x)
478 /* find the bin corresponding to x (see plot_impulse_amplitude) */
479 int i = roundf ((powf (10, _log_max * x / _analysis_width) - 1.0) * _impulse_fft->bins() / _log_coeff);
480 float dB = power_to_dB (_impulse_fft->power_at_bin (i));
481 /* calc freq corresponding to bin */
482 const int freq = std::max (1, (int) roundf ((float)i / (float)_impulse_fft->bins() * _samplerate / 2.f));
484 _pointer_in_area_freq = round (_analysis_width * log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max);
486 std::stringstream ss;
489 ss << std::setprecision (1) << freq / 1000.0 << "kHz";
490 } else if (freq >= 1000) {
491 ss << std::setprecision (2) << freq / 1000.0 << "kHz";
493 ss << std::setprecision (0) << freq << "Hz";
495 ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << dB;
496 ss << std::setw (0) << "dB";
498 if (_phase_button->get_active ()) {
499 float phase = 180. * _impulse_fft->phase_at_bin (i) / M_PI;
500 ss << " " << std::setw (6) << std::setprecision (1) << std::showpos << phase;
501 ss << std::setw (0) << "\u00B0";
503 _pointer_info->set_text (ss.str());
507 PluginEqGui::analysis_area_mouseover (GdkEventMotion *event)
509 update_pointer_info (event->x);
510 _pointer_in_area_xpos = event->x;
511 _analysis_area->queue_draw ();
516 PluginEqGui::analysis_area_mouseexit (GdkEventCrossing *)
518 _pointer_info->set_text ("");
519 _pointer_in_area_xpos = -1;
520 _analysis_area->queue_draw ();
525 PluginEqGui::expose_analysis_area (GdkEventExpose *)
527 redraw_analysis_area ();
532 PluginEqGui::draw_analysis_scales (cairo_t *ref_cr)
534 // TODO: check whether we need rounding
535 _analysis_scale_surface = cairo_surface_create_similar (cairo_get_target (ref_cr),
540 cairo_t *cr = cairo_create (_analysis_scale_surface);
542 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
543 cairo_rectangle (cr, 0.0, 0.0, _analysis_width, _analysis_height);
546 draw_scales_power (_analysis_area, cr);
548 if (_phase_button->get_active ()) {
549 draw_scales_phase (_analysis_area, cr);
556 PluginEqGui::redraw_analysis_area ()
560 cr = gdk_cairo_create (GDK_DRAWABLE(_analysis_area->get_window()->gobj()));
562 if (_analysis_scale_surface == 0) {
563 draw_analysis_scales (cr);
566 cairo_copy_page (cr);
568 cairo_set_source_surface (cr, _analysis_scale_surface, 0.0, 0.0);
571 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
573 if (_phase_button->get_active()) {
574 plot_impulse_phase (_analysis_area, cr);
577 plot_impulse_amplitude (_analysis_area, cr);
579 if (_pointer_in_area_xpos >= 0) {
580 update_pointer_info (_pointer_in_area_xpos);
583 if (_live_signal_combo->get_active_row_number() > 0) {
584 plot_signal_amplitude_difference (_analysis_area, cr);
587 if (_pointer_in_area_xpos >= 0 && _pointer_in_area_freq > 0) {
588 const double dashed[] = {0.0, 2.0};
589 cairo_set_dash (cr, dashed, 2, 0);
590 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
591 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
592 cairo_set_line_width (cr, 1.0);
593 cairo_move_to (cr, _pointer_in_area_freq - .5, -.5);
594 cairo_line_to (cr, _pointer_in_area_freq - .5, _analysis_height - .5);
601 #define PHASE_PROPORTION 0.5
604 PluginEqGui::draw_scales_phase (Gtk::Widget*, cairo_t *cr)
607 cairo_font_extents_t extents;
608 cairo_font_extents (cr, &extents);
611 cairo_text_extents_t t_ext;
613 for (uint32_t i = 0; i < 5; i++) {
615 y = _analysis_height / 2.0 - (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
617 cairo_set_source_rgb (cr, .8, .9, 0.2);
619 snprintf (buf,256, "0\u00b0");
621 snprintf (buf,256, "%d\u00b0", (i * 45));
623 cairo_text_extents (cr, buf, &t_ext);
624 cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
625 cairo_show_text (cr, buf);
633 cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
634 cairo_move_to (cr, 0.0, y);
635 cairo_line_to (cr, _analysis_width, y);
636 cairo_set_line_width (cr, 1);
639 y = _analysis_height / 2.0 + (float)i * (_analysis_height / 8.0) * PHASE_PROPORTION;
642 snprintf (buf,256, "-%d\u00b0", (i * 45));
643 cairo_set_source_rgb (cr, .8, .9, 0.2);
644 cairo_text_extents (cr, buf, &t_ext);
645 cairo_move_to (cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
646 cairo_show_text (cr, buf);
650 cairo_set_source_rgba (cr, .8, .9, .2, 0.4);
651 cairo_move_to (cr, 0.0, y);
652 cairo_line_to (cr, _analysis_width, y);
654 cairo_set_line_width (cr, 1);
660 PluginEqGui::plot_impulse_phase (Gtk::Widget *w, cairo_t *cr)
668 // float width = w->get_width();
669 float height = w->get_height ();
670 float analysis_height_2 = _analysis_height / 2.f;
672 cairo_set_source_rgba (cr, 0.95, 0.3, 0.2, 1.0);
673 for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
674 // x coordinate of bin i
675 x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
676 x *= _analysis_width;
677 y = analysis_height_2 - (_impulse_fft->phase_at_bin (i) / M_PI) * analysis_height_2 * PHASE_PROPORTION;
680 cairo_move_to (cr, x, y);
683 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
684 avgY = avgY / (float)avgNum;
685 if (avgY > (height * 10.0)) {
686 avgY = height * 10.0;
688 if (avgY < (-height * 10.0)) {
689 avgY = -height * 10.0;
692 cairo_line_to (cr, prevX, avgY);
703 cairo_set_line_width (cr, 2.0);
708 PluginEqGui::draw_scales_power (Gtk::Widget */*w*/, cairo_t *cr)
710 if (_impulse_fft == 0) {
714 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 };
715 float divisor = _samplerate / 2.0 / _impulse_fft->bins();
718 cairo_set_line_width (cr, 1.5);
719 cairo_set_font_size (cr, 9);
721 cairo_font_extents_t extents;
722 cairo_font_extents (cr, &extents);
723 // float fontXOffset = extents.descent + 1.0;
727 for (uint32_t i = 0; scales[i] != -1.0; ++i) {
728 float bin = scales[i] / divisor;
730 x = log10f (1.0 + bin / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
731 x *= _analysis_width;
733 if (scales[i] < 1000.0) {
734 snprintf (buf, 256, "%0.0f", scales[i]);
736 snprintf (buf, 256, "%0.0fk", scales[i]/1000.0);
739 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
741 cairo_move_to (cr, x - extents.height, 3.0);
743 cairo_rotate (cr, M_PI / 2.0);
744 cairo_show_text (cr, buf);
745 cairo_rotate (cr, -M_PI / 2.0);
748 cairo_set_source_rgb (cr, 0.3, 0.3, 0.3);
749 cairo_move_to (cr, x, _analysis_height);
750 cairo_line_to (cr, x, 0.0);
756 //double dashes[] = { 1.0, 3.0, 4.5, 3.0 };
757 double dashes[] = { 3.0, 5.0 };
759 for (float dB = 0.0; dB < _max_dB; dB += _step_dB) {
760 snprintf (buf, 256, "+%0.0f", dB);
762 y = (_max_dB - dB) / (_max_dB - _min_dB);
763 //std::cerr << " y = " << y << std::endl;
764 y *= _analysis_height;
767 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
768 cairo_move_to (cr, 1.0, y + extents.height + 1.0);
769 cairo_show_text (cr, buf);
773 cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
774 cairo_move_to (cr, 0, y);
775 cairo_line_to (cr, _analysis_width, y);
779 cairo_set_dash (cr, dashes, 2, 0.0);
783 for (float dB = - _step_dB; dB > _min_dB; dB -= _step_dB) {
784 snprintf (buf, 256, "%0.0f", dB);
786 y = (_max_dB - dB) / (_max_dB - _min_dB);
787 y *= _analysis_height;
789 cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
790 cairo_move_to (cr, 1.0, y - extents.descent - 1.0);
791 cairo_show_text (cr, buf);
794 cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
795 cairo_move_to (cr, 0, y);
796 cairo_line_to (cr, _analysis_width, y);
800 cairo_set_dash (cr, 0, 0, 0.0);
804 PluginEqGui::plot_impulse_amplitude (Gtk::Widget *w, cairo_t *cr)
811 // float width = w->get_width();
812 float height = w->get_height ();
814 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
815 cairo_set_line_width (cr, 2.5);
817 for (uint32_t i = 0; i < _impulse_fft->bins() - 1; ++i) {
818 // x coordinate of bin i
819 x = log10f (1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
820 x *= _analysis_width;
822 float yCoeff = (power_to_dB (_impulse_fft->power_at_bin (i)) - _min_dB) / (_max_dB - _min_dB);
824 y = _analysis_height - _analysis_height * yCoeff;
827 cairo_move_to (cr, x, y);
830 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
831 avgY = avgY / (float)avgNum;
832 if (avgY > (height * 10.0)) {
833 avgY = height * 10.0;
835 if (avgY < (-height * 10.0)) {
836 avgY = -height * 10.0;
838 cairo_line_to (cr, prevX, avgY);
853 PluginEqGui::plot_signal_amplitude_difference (Gtk::Widget *w, cairo_t *cr)
861 float height = w->get_height();
863 cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
864 cairo_set_line_width (cr, 1.5);
866 for (uint32_t i = 0; i < _signal_input_fft->bins() - 1; ++i) {
867 // x coordinate of bin i
868 x = log10f (1.0 + (float)i / (float)_signal_input_fft->bins() * _log_coeff) / _log_max;
869 x *= _analysis_width;
871 float power_out = _signal_output_fft->power_at_bin (i) + 1e-30;
872 float power_in = _signal_input_fft ->power_at_bin (i) + 1e-30;
874 switch (_live_signal_combo->get_active_row_number()) {
876 power = power_to_dB (power_in);
879 power = power_to_dB (power_out);
882 power = power_to_dB (power_in) + 40;
885 power = power_to_dB (power_out) + 40;
888 power = power_to_dB (power_out / power_in);
892 assert (!ISINF(power));
893 assert (!ISNAN(power));
895 float yCoeff = (power - _min_dB) / (_max_dB - _min_dB);
897 y = _analysis_height - _analysis_height*yCoeff;
900 cairo_move_to (cr, x, y);
904 } else if (rint (x) > prevX || i == _impulse_fft->bins() - 1) {
905 avgY = avgY / (float)avgNum;
906 if (avgY > (height * 10.0)) {
907 avgY = height * 10.0;
909 if (avgY < (-height * 10.0)) {
910 avgY = -height * 10.0;
912 cairo_line_to (cr, prevX, avgY);