2 Copyright (C) 2008 Paul Davis
3 Author: Sampo Savolainen
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 "ardour/audio_buffer.h"
42 #include "ardour/data_type.h"
43 #include "ardour/chan_mapping.h"
44 #include "ardour/plugin_insert.h"
45 #include "ardour/session.h"
47 #include "plugin_eq_gui.h"
49 #include "ardour_ui.h"
50 #include "gui_thread.h"
54 using namespace ARDOUR;
56 PluginEqGui::PluginEqGui(boost::shared_ptr<ARDOUR::PluginInsert> pluginInsert)
61 , _signal_buffer_size(0)
63 , _signal_input_fft(0)
64 , _signal_output_fft(0)
65 , _plugin_insert(pluginInsert)
67 _signal_analysis_running = false;
68 _samplerate = ARDOUR_UI::instance()->the_session()->sample_rate();
70 _log_coeff = (1.0 - 2.0 * (1000.0/(_samplerate/2.0))) / powf(1000.0/(_samplerate/2.0), 2.0);
71 _log_max = log10f(1 + _log_coeff);
73 // Setup analysis drawing area
74 _analysis_scale_surface = 0;
76 _analysis_area = new Gtk::DrawingArea();
77 _analysis_width = 256.0;
78 _analysis_height = 256.0;
79 _analysis_area->set_size_request(_analysis_width, _analysis_height);
81 _analysis_area->add_events(Gdk::POINTER_MOTION_MASK | Gdk::LEAVE_NOTIFY_MASK | Gdk::BUTTON_PRESS_MASK);
83 _analysis_area->signal_expose_event().connect( sigc::mem_fun (*this, &PluginEqGui::expose_analysis_area));
84 _analysis_area->signal_size_allocate().connect( sigc::mem_fun (*this, &PluginEqGui::resize_analysis_area));
85 _analysis_area->signal_motion_notify_event().connect( sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseover));
86 _analysis_area->signal_leave_notify_event().connect( sigc::mem_fun (*this, &PluginEqGui::analysis_area_mouseexit));
87 _analysis_area->signal_button_press_event().connect( sigc::mem_fun (*this, &PluginEqGui::analysis_area_mousedown));
90 dBScaleModel = Gtk::ListStore::create(dBColumns);
92 dBScaleCombo = new Gtk::ComboBox (dBScaleModel, false);
93 dBScaleCombo->set_title (_("dB scale"));
95 #define ADD_DB_ROW(MIN,MAX,STEP,NAME) \
97 Gtk::TreeModel::Row row = *(dBScaleModel->append()); \
98 row[dBColumns.dBMin] = (MIN); \
99 row[dBColumns.dBMax] = (MAX); \
100 row[dBColumns.dBStep] = (STEP); \
101 row[dBColumns.name] = NAME; \
104 ADD_DB_ROW( -6, +6, 1, "-6dB .. +6dB");
105 ADD_DB_ROW(-12, +12, 3, "-12dB .. +12dB");
106 ADD_DB_ROW(-24, +24, 5, "-24dB .. +24dB");
107 ADD_DB_ROW(-36, +36, 6, "-36dB .. +36dB");
108 ADD_DB_ROW(-64, +64,12, "-64dB .. +64dB");
112 dBScaleCombo -> pack_start(dBColumns.name);
113 dBScaleCombo -> set_active(1);
115 dBScaleCombo -> signal_changed().connect( sigc::mem_fun(*this, &PluginEqGui::change_dB_scale) );
117 Gtk::Label *dBComboLabel = new Gtk::Label (_("dB scale"));
119 Gtk::HBox *dBSelectBin = new Gtk::HBox(false, 5);
120 dBSelectBin->add( *manage(dBComboLabel));
121 dBSelectBin->add( *manage(dBScaleCombo));
124 _signal_button = new Gtk::CheckButton (_("Plot live signal"));
125 _signal_button->set_active(true);
128 _phase_button = new Gtk::CheckButton (_("Show phase"));
129 _phase_button->set_active(true);
130 _phase_button->signal_toggled().connect( sigc::mem_fun(*this, &PluginEqGui::redraw_scales));
132 // Freq/dB info for mouse over
133 _pointer_info = new Gtk::Label ("", 1, 0.5);
134 _pointer_info->set_size_request(_analysis_width / 4, -1);
135 _pointer_info->set_name("PluginAnalysisInfoLabel");
138 attach (*manage(_analysis_area), 0, 4, 0, 1);
139 attach (*manage(dBSelectBin), 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
140 attach (*manage(_signal_button), 1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
141 attach (*manage(_phase_button), 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
142 attach (*manage(_pointer_info), 3, 4, 1, 2, Gtk::FILL, Gtk::SHRINK);
145 PluginEqGui::~PluginEqGui()
149 if (_analysis_scale_surface) {
150 cairo_surface_destroy (_analysis_scale_surface);
155 delete _signal_input_fft;
156 _signal_input_fft = 0;
157 delete _signal_output_fft;
158 _signal_output_fft = 0;
160 // all gui objects are *manage'd by the inherited Table object
164 PluginEqGui::start_listening ()
167 _plugin = _plugin_insert->get_impulse_analysis_plugin();
171 set_buffer_size(4096, 16384);
172 _plugin->set_block_size (_buffer_size);
173 // Connect the realtime signal collection callback
174 _plugin_insert->AnalysisDataGathered.connect (analysis_connection, invalidator (*this), boost::bind (&PluginEqGui::signal_collect_callback, this, _1, _2), gui_context());
178 PluginEqGui::stop_listening ()
180 analysis_connection.disconnect ();
181 _plugin->deactivate ();
185 PluginEqGui::on_hide()
188 Gtk::Table::on_hide();
192 PluginEqGui::stop_updating()
194 if (_update_connection.connected()) {
195 _update_connection.disconnect();
200 PluginEqGui::start_updating()
202 if (!_update_connection.connected() && is_visible()) {
203 _update_connection = Glib::signal_timeout().connect( sigc::mem_fun(this, &PluginEqGui::timeout_callback), 250);
208 PluginEqGui::on_show()
210 Gtk::Table::on_show();
214 Gtk::Widget *toplevel = get_toplevel();
216 if (!_window_unmap_connection.connected()) {
217 _window_unmap_connection = toplevel->signal_unmap().connect( sigc::mem_fun(this, &PluginEqGui::stop_updating));
220 if (!_window_map_connection.connected()) {
221 _window_map_connection = toplevel->signal_map().connect( sigc::mem_fun(this, &PluginEqGui::start_updating));
227 PluginEqGui::change_dB_scale()
229 Gtk::TreeModel::iterator iter = dBScaleCombo -> get_active();
231 Gtk::TreeModel::Row row;
233 if(iter && (row = *iter)) {
234 _min_dB = row[dBColumns.dBMin];
235 _max_dB = row[dBColumns.dBMax];
236 _step_dB = row[dBColumns.dBStep];
244 PluginEqGui::redraw_scales()
247 if (_analysis_scale_surface) {
248 cairo_surface_destroy (_analysis_scale_surface);
249 _analysis_scale_surface = 0;
252 _analysis_area->queue_draw();
254 // TODO: Add graph legend!
258 PluginEqGui::set_buffer_size(uint32_t size, uint32_t signal_size)
260 if (_buffer_size == size && _signal_buffer_size == signal_size) {
264 GTKArdour::FFT *tmp1 = _impulse_fft;
265 GTKArdour::FFT *tmp2 = _signal_input_fft;
266 GTKArdour::FFT *tmp3 = _signal_output_fft;
269 _impulse_fft = new GTKArdour::FFT(size);
270 _signal_input_fft = new GTKArdour::FFT(signal_size);
271 _signal_output_fft = new GTKArdour::FFT(signal_size);
273 // Don't care about lost memory, we're screwed anyhow
275 _signal_input_fft = tmp2;
276 _signal_output_fft = tmp3;
285 _signal_buffer_size = signal_size;
287 // allocate separate in+out buffers, VST cannot process in-place
288 ARDOUR::ChanCount acount (_plugin->get_info()->n_inputs + _plugin->get_info()->n_outputs);
289 ARDOUR::ChanCount ccount = ARDOUR::ChanCount::max (_plugin->get_info()->n_inputs, _plugin->get_info()->n_outputs);
291 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
292 _bufferset.ensure_buffers (*i, acount.get (*i), _buffer_size);
293 _collect_bufferset.ensure_buffers (*i, ccount.get (*i), _buffer_size);
296 _bufferset.set_count (acount);
297 _collect_bufferset.set_count (ccount);
301 PluginEqGui::resize_analysis_area (Gtk::Allocation& size)
303 _analysis_width = (float)size.get_width();
304 _analysis_height = (float)size.get_height();
306 if (_analysis_scale_surface) {
307 cairo_surface_destroy (_analysis_scale_surface);
308 _analysis_scale_surface = 0;
311 _pointer_info->set_size_request(_analysis_width / 4, -1);
315 PluginEqGui::timeout_callback()
317 if (!_signal_analysis_running) {
318 _signal_analysis_running = true;
319 _plugin_insert -> collect_signal_for_analysis(_signal_buffer_size);
321 run_impulse_analysis();
327 PluginEqGui::signal_collect_callback(ARDOUR::BufferSet *in, ARDOUR::BufferSet *out)
329 ENSURE_GUI_THREAD (*this, &PluginEqGui::signal_collect_callback, in, out);
331 _signal_input_fft ->reset();
332 _signal_output_fft->reset();
334 for (uint32_t i = 0; i < _plugin_insert->input_streams().n_audio(); ++i) {
335 _signal_input_fft ->analyze(in ->get_audio(i).data(), GTKArdour::FFT::HANN);
338 for (uint32_t i = 0; i < _plugin_insert->output_streams().n_audio(); ++i) {
339 _signal_output_fft->analyze(out->get_audio(i).data(), GTKArdour::FFT::HANN);
342 _signal_input_fft ->calculate();
343 _signal_output_fft->calculate();
345 _signal_analysis_running = false;
347 // This signals calls expose_analysis_area()
348 _analysis_area->queue_draw();
352 PluginEqGui::run_impulse_analysis()
354 /* Allocate some thread-local buffers so that Plugin::connect_and_run can use them */
355 ARDOUR_UI::instance()->get_process_buffers ();
357 uint32_t inputs = _plugin->get_info()->n_inputs.n_audio();
358 uint32_t outputs = _plugin->get_info()->n_outputs.n_audio();
360 // Create the impulse, can't use silence() because consecutive calls won't work
361 for (uint32_t i = 0; i < inputs; ++i) {
362 ARDOUR::AudioBuffer& buf = _bufferset.get_audio(i);
363 ARDOUR::Sample* d = buf.data();
364 memset(d, 0, sizeof(ARDOUR::Sample)*_buffer_size);
368 ARDOUR::ChanMapping in_map(_plugin->get_info()->n_inputs);
369 ARDOUR::ChanMapping out_map(_plugin->get_info()->n_outputs);
370 // map output buffers after input buffers (no inplace for VST)
371 out_map.offset_to (DataType::AUDIO, inputs);
373 _plugin->connect_and_run(_bufferset, 0, _buffer_size, 1.0, in_map, out_map, _buffer_size, 0);
374 samplecnt_t f = _plugin->signal_latency ();
375 // Adding user_latency() could be interesting
377 // Gather all output, taking latency into account.
378 _impulse_fft->reset();
380 // Silence collect buffers to copy data to, can't use silence() because consecutive calls won't work
381 for (uint32_t i = 0; i < outputs; ++i) {
382 ARDOUR::AudioBuffer &buf = _collect_bufferset.get_audio(i);
383 ARDOUR::Sample *d = buf.data();
384 memset(d, 0, sizeof(ARDOUR::Sample)*_buffer_size);
388 //std::cerr << "0: no latency, copying full buffer, trivial.." << std::endl;
389 for (uint32_t i = 0; i < outputs; ++i) {
390 memcpy(_collect_bufferset.get_audio(i).data(),
391 _bufferset.get_audio(inputs + i).data(), _buffer_size * sizeof(float));
395 //std::cerr << (++C) << ": latency is " << f << " samples, doing split processing.." << std::endl;
396 samplecnt_t target_offset = 0;
397 samplecnt_t samples_left = _buffer_size; // refaktoroi
399 if (f >= _buffer_size) {
400 //std::cerr << (++C) << ": f (=" << f << ") is larger than buffer_size, still trying to reach the actual output" << std::endl;
401 // there is no data in this buffer regarding to the input!
404 // this buffer contains either the first, last or a whole bu the output of the impulse
405 // first part: offset is 0, so we copy to the start of _collect_bufferset
406 // we start at output offset "f"
407 // .. and copy "buffer size" - "f" - "offset" samples
409 samplecnt_t length = _buffer_size - f - target_offset;
411 //std::cerr << (++C) << ": copying " << length << " samples to _collect_bufferset.get_audio(i)+" << target_offset << " from bufferset at offset " << f << std::endl;
412 for (uint32_t i = 0; i < outputs; ++i) {
413 memcpy(_collect_bufferset.get_audio(i).data(target_offset),
414 _bufferset.get_audio(inputs + i).data() + f,
415 length * sizeof(float));
418 target_offset += length;
419 samples_left -= length;
422 if (samples_left > 0) {
423 // Silence the buffers
424 for (uint32_t i = 0; i < inputs; ++i) {
425 ARDOUR::AudioBuffer &buf = _bufferset.get_audio(i);
426 ARDOUR::Sample *d = buf.data();
427 memset(d, 0, sizeof(ARDOUR::Sample)*_buffer_size);
430 _plugin->connect_and_run (_bufferset, target_offset, target_offset + _buffer_size, 1.0, in_map, out_map, _buffer_size, 0);
432 } while ( samples_left > 0);
437 for (uint32_t i = 0; i < outputs; ++i) {
438 _impulse_fft->analyze(_collect_bufferset.get_audio(i).data());
441 // normalize the output
442 _impulse_fft->calculate();
444 // This signals calls expose_analysis_area()
445 _analysis_area->queue_draw();
447 ARDOUR_UI::instance()->drop_process_buffers ();
451 PluginEqGui::update_pointer_info(float x, float y)
453 const int freq = std::max(1, (int) roundf((powf(10, x / _analysis_width * _log_max) - 1) * _samplerate / 2.0 / _log_coeff));
454 const float dB = _max_dB - y / _analysis_height * ( _max_dB - _min_dB );
455 std::stringstream ss;
458 ss << std::setprecision (1) << freq / 1000.0 << "kHz";
459 } else if (freq >= 1000) {
460 ss << std::setprecision (2) << freq / 1000.0 << "kHz";
462 ss << std::setprecision (0) << freq << "Hz";
464 ss << " " << std::setw(5) << std::setprecision (1) << std::showpos << dB;
465 ss << std::setw(0) << "dB";
466 _pointer_info->set_text(ss.str());
470 PluginEqGui::analysis_area_mouseover(GdkEventMotion *event)
472 update_pointer_info(event->x, event->y);
477 PluginEqGui::analysis_area_mouseexit(GdkEventCrossing *)
479 _pointer_info->set_text("");
484 PluginEqGui::analysis_area_mousedown(GdkEventButton *event)
486 update_pointer_info(event->x, event->y);
492 PluginEqGui::expose_analysis_area(GdkEventExpose *)
494 redraw_analysis_area();
499 PluginEqGui::draw_analysis_scales(cairo_t *ref_cr)
501 // TODO: check whether we need rounding
502 _analysis_scale_surface = cairo_surface_create_similar (cairo_get_target(ref_cr),
507 cairo_t *cr = cairo_create (_analysis_scale_surface);
509 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
510 cairo_rectangle(cr, 0.0, 0.0, _analysis_width, _analysis_height);
514 draw_scales_power(_analysis_area, cr);
515 if (_phase_button->get_active()) {
516 draw_scales_phase(_analysis_area, cr);
523 PluginEqGui::redraw_analysis_area()
527 cr = gdk_cairo_create(GDK_DRAWABLE(_analysis_area->get_window()->gobj()));
529 if (_analysis_scale_surface == 0) {
530 draw_analysis_scales(cr);
535 cairo_set_source_surface(cr, _analysis_scale_surface, 0.0, 0.0);
538 if (_phase_button->get_active()) {
539 plot_impulse_phase(_analysis_area, cr);
541 plot_impulse_amplitude(_analysis_area, cr);
543 if (_signal_button->get_active()) {
544 plot_signal_amplitude_difference(_analysis_area, cr);
550 #define PHASE_PROPORTION 0.5
553 PluginEqGui::draw_scales_phase(Gtk::Widget */*w*/, cairo_t *cr)
556 cairo_font_extents_t extents;
557 cairo_font_extents(cr, &extents);
560 cairo_text_extents_t t_ext;
562 for (uint32_t i = 0; i < 3; i++) {
564 y = _analysis_height/2.0 - (float)i*(_analysis_height/8.0)*PHASE_PROPORTION;
566 cairo_set_source_rgb(cr, .8, .9, 0.2);
568 snprintf(buf,256, "0\u00b0");
570 snprintf(buf,256, "%d\u00b0", (i * 45));
572 cairo_text_extents(cr, buf, &t_ext);
573 cairo_move_to(cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
574 cairo_show_text(cr, buf);
580 cairo_set_source_rgba(cr, .8, .9, 0.2, 0.6/(float)i);
581 cairo_move_to(cr, 0.0, y);
582 cairo_line_to(cr, _analysis_width, y);
585 y = _analysis_height/2.0 + (float)i*(_analysis_height/8.0)*PHASE_PROPORTION;
588 snprintf(buf,256, "-%d\u00b0", (i * 45));
589 cairo_set_source_rgb(cr, .8, .9, 0.2);
590 cairo_text_extents(cr, buf, &t_ext);
591 cairo_move_to(cr, _analysis_width - t_ext.width - t_ext.x_bearing - 2.0, y - extents.descent);
592 cairo_show_text(cr, buf);
595 cairo_set_source_rgba(cr, .8, .9, 0.2, 0.6/(float)i);
596 cairo_move_to(cr, 0.0, y);
597 cairo_line_to(cr, _analysis_width, y);
599 cairo_set_line_width (cr, 0.25 + 1.0/(float)(i+1));
605 PluginEqGui::plot_impulse_phase(Gtk::Widget *w, cairo_t *cr)
613 // float width = w->get_width();
614 float height = w->get_height();
616 cairo_set_source_rgba(cr, 0.95, 0.3, 0.2, 1.0);
617 for (uint32_t i = 0; i < _impulse_fft->bins()-1; i++) {
618 // x coordinate of bin i
619 x = log10f(1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
620 x *= _analysis_width;
622 y = _analysis_height/2.0 - (_impulse_fft->phase_at_bin(i)/M_PI)*(_analysis_height/2.0)*PHASE_PROPORTION;
625 cairo_move_to(cr, x, y);
629 } else if (rint(x) > prevX || i == _impulse_fft->bins()-1 ) {
630 avgY = avgY/(float)avgNum;
631 if (avgY > (height * 10.0) ) avgY = height * 10.0;
632 if (avgY < (-height * 10.0) ) avgY = -height * 10.0;
633 cairo_line_to(cr, prevX, avgY);
634 //cairo_line_to(cr, prevX, avgY/(float)avgNum);
646 cairo_set_line_width (cr, 2.0);
651 PluginEqGui::draw_scales_power(Gtk::Widget */*w*/, cairo_t *cr)
653 if (_impulse_fft == 0) {
657 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 };
658 float divisor = _samplerate / 2.0 / _impulse_fft->bins();
661 cairo_set_line_width (cr, 1.5);
662 cairo_set_font_size(cr, 9);
664 cairo_font_extents_t extents;
665 cairo_font_extents(cr, &extents);
666 // float fontXOffset = extents.descent + 1.0;
670 for (uint32_t i = 0; scales[i] != -1.0; ++i) {
671 float bin = scales[i] / divisor;
673 x = log10f(1.0 + bin / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
674 x *= _analysis_width;
676 if (scales[i] < 1000.0) {
677 snprintf(buf, 256, "%0.0f", scales[i]);
679 snprintf(buf, 256, "%0.0fk", scales[i]/1000.0);
682 cairo_set_source_rgb(cr, 0.4, 0.4, 0.4);
684 //cairo_move_to(cr, x + fontXOffset, 3.0);
685 cairo_move_to(cr, x - extents.height, 3.0);
687 cairo_rotate(cr, M_PI / 2.0);
688 cairo_show_text(cr, buf);
689 cairo_rotate(cr, -M_PI / 2.0);
692 cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
693 cairo_move_to(cr, x, _analysis_height);
694 cairo_line_to(cr, x, 0.0);
700 //double dashes[] = { 1.0, 3.0, 4.5, 3.0 };
701 double dashes[] = { 3.0, 5.0 };
703 for (float dB = 0.0; dB < _max_dB; dB += _step_dB ) {
704 snprintf(buf, 256, "+%0.0f", dB );
706 y = ( _max_dB - dB) / ( _max_dB - _min_dB );
707 //std::cerr << " y = " << y << std::endl;
708 y *= _analysis_height;
711 cairo_set_source_rgb(cr, 0.4, 0.4, 0.4);
712 cairo_move_to(cr, 1.0, y + extents.height + 1.0);
713 cairo_show_text(cr, buf);
717 cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
718 cairo_move_to(cr, 0, y);
719 cairo_line_to(cr, _analysis_width, y);
723 cairo_set_dash(cr, dashes, 2, 0.0);
729 for (float dB = - _step_dB; dB > _min_dB; dB -= _step_dB ) {
730 snprintf(buf, 256, "%0.0f", dB );
732 y = ( _max_dB - dB) / ( _max_dB - _min_dB );
733 y *= _analysis_height;
735 cairo_set_source_rgb(cr, 0.4, 0.4, 0.4);
736 cairo_move_to(cr, 1.0, y - extents.descent - 1.0);
737 cairo_show_text(cr, buf);
740 cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
741 cairo_move_to(cr, 0, y);
742 cairo_line_to(cr, _analysis_width, y);
746 cairo_set_dash(cr, 0, 0, 0.0);
753 return 10.0 * log10f(a);
757 PluginEqGui::plot_impulse_amplitude(Gtk::Widget *w, cairo_t *cr)
764 // float width = w->get_width();
765 float height = w->get_height();
767 cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
768 cairo_set_line_width (cr, 2.5);
770 for (uint32_t i = 0; i < _impulse_fft->bins()-1; i++) {
771 // x coordinate of bin i
772 x = log10f(1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
773 x *= _analysis_width;
775 float yCoeff = ( power_to_dB(_impulse_fft->power_at_bin(i)) - _min_dB) / (_max_dB - _min_dB);
777 y = _analysis_height - _analysis_height*yCoeff;
780 cairo_move_to(cr, x, y);
784 } else if (rint(x) > prevX || i == _impulse_fft->bins()-1 ) {
785 avgY = avgY/(float)avgNum;
786 if (avgY > (height * 10.0) ) avgY = height * 10.0;
787 if (avgY < (-height * 10.0) ) avgY = -height * 10.0;
788 cairo_line_to(cr, prevX, avgY);
789 //cairo_line_to(cr, prevX, avgY/(float)avgNum);
805 PluginEqGui::plot_signal_amplitude_difference(Gtk::Widget *w, cairo_t *cr)
813 // float width = w->get_width();
814 float height = w->get_height();
816 cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
817 cairo_set_line_width (cr, 1.5);
819 for (uint32_t i = 0; i < _signal_input_fft->bins()-1; i++) {
820 // x coordinate of bin i
821 x = log10f(1.0 + (float)i / (float)_signal_input_fft->bins() * _log_coeff) / _log_max;
822 x *= _analysis_width;
824 float power_out = _signal_output_fft->power_at_bin (i) + 1e-30;
825 float power_in = _signal_input_fft ->power_at_bin (i) + 1e-30;
826 float power = power_to_dB (power_out / power_in);
828 assert (!ISINF(power));
829 assert (!ISNAN(power));
831 float yCoeff = ( power - _min_dB) / (_max_dB - _min_dB);
833 y = _analysis_height - _analysis_height*yCoeff;
836 cairo_move_to(cr, x, y);
840 } else if (rint(x) > prevX || i == _impulse_fft->bins()-1 ) {
841 avgY = avgY/(float)avgNum;
842 if (avgY > (height * 10.0) ) avgY = height * 10.0;
843 if (avgY < (-height * 10.0) ) avgY = -height * 10.0;
844 cairo_line_to(cr, prevX, avgY);