*/
+#include <algorithm>
#include <math.h>
+#include <iomanip>
#include <iostream>
+#include <sstream>
#ifdef COMPILER_MSVC
#include <float.h>
#include "ardour_ui.h"
#include "gui_thread.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
using namespace ARDOUR;
: _min_dB(-12.0)
, _max_dB(+12.0)
, _step_dB(3.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)
{
_signal_analysis_running = false;
- _samplerate = ARDOUR_UI::instance()->the_session()->frame_rate();
+ _samplerate = ARDOUR_UI::instance()->the_session()->sample_rate();
_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);
_analysis_height = 256.0;
_analysis_area->set_size_request(_analysis_width, _analysis_height);
+ _analysis_area->add_events(Gdk::POINTER_MOTION_MASK | Gdk::LEAVE_NOTIFY_MASK | Gdk::BUTTON_PRESS_MASK);
+
_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));
// dB selection
dBScaleModel = Gtk::ListStore::create(dBColumns);
- /* this grotty-looking cast allows compilation against gtkmm 2.24.0, which
- added a new ComboBox constructor.
- */
- dBScaleCombo = new Gtk::ComboBox ((Glib::RefPtr<Gtk::TreeModel> &) dBScaleModel);
+ dBScaleCombo = new Gtk::ComboBox (dBScaleModel, false);
dBScaleCombo->set_title (_("dB scale"));
#define ADD_DB_ROW(MIN,MAX,STEP,NAME) \
dBSelectBin->add( *manage(dBComboLabel));
dBSelectBin->add( *manage(dBScaleCombo));
+ // Phase checkbutton
+ _signal_button = new Gtk::CheckButton (_("Plot live signal"));
+ _signal_button->set_active(true);
+
// Phase checkbutton
_phase_button = new Gtk::CheckButton (_("Show phase"));
_phase_button->set_active(true);
_phase_button->signal_toggled().connect( sigc::mem_fun(*this, &PluginEqGui::redraw_scales));
+ // Freq/dB info for mouse over
+ _pointer_info = new Gtk::Label ("", 1, 0.5);
+ _pointer_info->set_size_request(_analysis_width / 4, -1);
+ _pointer_info->set_name("PluginAnalysisInfoLabel");
+
// populate table
- attach( *manage(_analysis_area), 1, 3, 1, 2);
- attach( *manage(dBSelectBin), 1, 2, 2, 3, Gtk::SHRINK, Gtk::SHRINK);
- attach( *manage(_phase_button), 2, 3, 2, 3, Gtk::SHRINK, Gtk::SHRINK);
+ attach (*manage(_analysis_area), 0, 4, 0, 1);
+ attach (*manage(dBSelectBin), 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
+ attach (*manage(_signal_button), 1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
+ attach (*manage(_phase_button), 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
+ attach (*manage(_pointer_info), 3, 4, 1, 2, Gtk::FILL, Gtk::SHRINK);
}
PluginEqGui::~PluginEqGui()
// all gui objects are *manage'd by the inherited Table object
}
+static inline float
+power_to_dB(float a)
+{
+ return 10.0 * log10f(a);
+}
+
void
PluginEqGui::start_listening ()
{
_plugin->activate();
set_buffer_size(4096, 16384);
+ _plugin->set_block_size (_buffer_size);
// Connect the realtime signal collection callback
_plugin_insert->AnalysisDataGathered.connect (analysis_connection, invalidator (*this), boost::bind (&PluginEqGui::signal_collect_callback, this, _1, _2), gui_context());
}
return;
}
- GTKArdour::FFT *tmp1 = _impulse_fft;
- GTKArdour::FFT *tmp2 = _signal_input_fft;
- GTKArdour::FFT *tmp3 = _signal_output_fft;
+ GTKArdour::FFT *tmp1 = _impulse_fft;
+ GTKArdour::FFT *tmp2 = _signal_input_fft;
+ GTKArdour::FFT *tmp3 = _signal_output_fft;
try {
_impulse_fft = new GTKArdour::FFT(size);
_buffer_size = size;
_signal_buffer_size = signal_size;
- ARDOUR::ChanCount count = ARDOUR::ChanCount::max (_plugin->get_info()->n_inputs, _plugin->get_info()->n_outputs);
+ // allocate separate in+out buffers, VST cannot process in-place
+ 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);
for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
- _bufferset.ensure_buffers (*i, count.get (*i), _buffer_size);
- _collect_bufferset.ensure_buffers (*i, count.get (*i), _buffer_size);
+ _bufferset.ensure_buffers (*i, acount.get (*i), _buffer_size);
+ _collect_bufferset.ensure_buffers (*i, ccount.get (*i), _buffer_size);
}
- _bufferset.set_count (count);
- _collect_bufferset.set_count (count);
+ _bufferset.set_count (acount);
+ _collect_bufferset.set_count (ccount);
}
void
cairo_surface_destroy (_analysis_scale_surface);
_analysis_scale_surface = 0;
}
+
+ _pointer_info->set_size_request(_analysis_width / 4, -1);
}
bool
void
PluginEqGui::signal_collect_callback(ARDOUR::BufferSet *in, ARDOUR::BufferSet *out)
{
- ENSURE_GUI_THREAD (*this, &PluginEqGui::signal_collect_callback, in, out)
+ ENSURE_GUI_THREAD (*this, &PluginEqGui::signal_collect_callback, in, out);
_signal_input_fft ->reset();
_signal_output_fft->reset();
{
/* Allocate some thread-local buffers so that Plugin::connect_and_run can use them */
ARDOUR_UI::instance()->get_process_buffers ();
-
+
uint32_t inputs = _plugin->get_info()->n_inputs.n_audio();
uint32_t outputs = _plugin->get_info()->n_outputs.n_audio();
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)
+ out_map.offset_to (DataType::AUDIO, inputs);
- _plugin->set_block_size (_buffer_size);
- _plugin->connect_and_run(_bufferset, in_map, out_map, _buffer_size, 0);
- framecnt_t f = _plugin->signal_latency ();
+ _plugin->connect_and_run(_bufferset, 0, _buffer_size, 1.0, in_map, out_map, _buffer_size, 0);
+ samplecnt_t f = _plugin->signal_latency ();
// Adding user_latency() could be interesting
// Gather all output, taking latency into account.
//std::cerr << "0: no latency, copying full buffer, trivial.." << std::endl;
for (uint32_t i = 0; i < outputs; ++i) {
memcpy(_collect_bufferset.get_audio(i).data(),
- _bufferset.get_audio(i).data(), _buffer_size * sizeof(float));
+ _bufferset.get_audio(inputs + i).data(), _buffer_size * sizeof(float));
}
} else {
//int C = 0;
- //std::cerr << (++C) << ": latency is " << f << " frames, doing split processing.." << std::endl;
- framecnt_t target_offset = 0;
- framecnt_t frames_left = _buffer_size; // refaktoroi
+ //std::cerr << (++C) << ": latency is " << f << " samples, doing split processing.." << std::endl;
+ samplecnt_t target_offset = 0;
+ samplecnt_t samples_left = _buffer_size; // refaktoroi
do {
if (f >= _buffer_size) {
//std::cerr << (++C) << ": f (=" << f << ") is larger than buffer_size, still trying to reach the actual output" << std::endl;
// this buffer contains either the first, last or a whole bu the output of the impulse
// first part: offset is 0, so we copy to the start of _collect_bufferset
// we start at output offset "f"
- // .. and copy "buffer size" - "f" - "offset" frames
+ // .. and copy "buffer size" - "f" - "offset" samples
- framecnt_t length = _buffer_size - f - target_offset;
+ samplecnt_t length = _buffer_size - f - target_offset;
- //std::cerr << (++C) << ": copying " << length << " frames to _collect_bufferset.get_audio(i)+" << target_offset << " from bufferset at offset " << f << std::endl;
+ //std::cerr << (++C) << ": copying " << length << " samples to _collect_bufferset.get_audio(i)+" << target_offset << " from bufferset at offset " << f << std::endl;
for (uint32_t i = 0; i < outputs; ++i) {
memcpy(_collect_bufferset.get_audio(i).data(target_offset),
- _bufferset.get_audio(i).data() + f,
- length * sizeof(float));
+ _bufferset.get_audio(inputs + i).data() + f,
+ length * sizeof(float));
}
target_offset += length;
- frames_left -= length;
+ samples_left -= length;
f = 0;
}
- if (frames_left > 0) {
+ if (samples_left > 0) {
// Silence the buffers
for (uint32_t i = 0; i < inputs; ++i) {
ARDOUR::AudioBuffer &buf = _bufferset.get_audio(i);
memset(d, 0, sizeof(ARDOUR::Sample)*_buffer_size);
}
- in_map = ARDOUR::ChanMapping(_plugin->get_info()->n_inputs);
- out_map = ARDOUR::ChanMapping(_plugin->get_info()->n_outputs);
- _plugin->connect_and_run(_bufferset, in_map, out_map, _buffer_size, 0);
+ _plugin->connect_and_run (_bufferset, target_offset, target_offset + _buffer_size, 1.0, in_map, out_map, _buffer_size, 0);
}
- } while ( frames_left > 0);
+ } while ( samples_left > 0);
}
ARDOUR_UI::instance()->drop_process_buffers ();
}
+void
+PluginEqGui::update_pointer_info(float x)
+{
+ /* 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 */
+ const int freq = std::max (1, (int) roundf((float)i / (float)_impulse_fft->bins() * _samplerate / 2.f));
+
+ _pointer_in_area_freq = round (_analysis_width * log10f(1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max);
+
+ std::stringstream ss;
+ ss << std::fixed;
+ if (freq >= 10000) {
+ ss << std::setprecision (1) << freq / 1000.0 << "kHz";
+ } else if (freq >= 1000) {
+ ss << std::setprecision (2) << freq / 1000.0 << "kHz";
+ } else {
+ ss << std::setprecision (0) << freq << "Hz";
+ }
+ ss << " " << std::setw(6) << std::setprecision (1) << std::showpos << dB;
+ ss << std::setw(0) << "dB";
+
+ if (_phase_button->get_active()) {
+ float phase = 180. * _impulse_fft->phase_at_bin (i) / M_PI;
+ ss << " " << std::setw(6) << std::setprecision (1) << std::showpos << phase;
+ ss << std::setw(0) << "\u00B0";
+ }
+ _pointer_info->set_text(ss.str());
+}
+
+bool
+PluginEqGui::analysis_area_mouseover(GdkEventMotion *event)
+{
+ update_pointer_info(event->x);
+ _pointer_in_area_xpos = event->x;
+ _analysis_area->queue_draw();
+ return true;
+}
+
+bool
+PluginEqGui::analysis_area_mouseexit(GdkEventCrossing *)
+{
+ _pointer_info->set_text("");
+ _pointer_in_area_xpos = -1;
+ _analysis_area->queue_draw();
+ return true;
+}
+
bool
PluginEqGui::expose_analysis_area(GdkEventExpose *)
{
PluginEqGui::draw_analysis_scales(cairo_t *ref_cr)
{
// TODO: check whether we need rounding
- _analysis_scale_surface = cairo_surface_create_similar(cairo_get_target(ref_cr),
- CAIRO_CONTENT_COLOR,
- _analysis_width,
- _analysis_height);
+ _analysis_scale_surface = cairo_surface_create_similar (cairo_get_target(ref_cr),
+ CAIRO_CONTENT_COLOR,
+ _analysis_width,
+ _analysis_height);
cairo_t *cr = cairo_create (_analysis_scale_surface);
- 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);
+ 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);
draw_scales_power(_analysis_area, cr);
draw_scales_phase(_analysis_area, cr);
}
- cairo_destroy(cr);
-
+ cairo_destroy(cr);
}
void
{
cairo_t *cr;
- cr = gdk_cairo_create(GDK_DRAWABLE(_analysis_area->get_window()->gobj()));
+ cr = gdk_cairo_create(GDK_DRAWABLE(_analysis_area->get_window()->gobj()));
if (_analysis_scale_surface == 0) {
draw_analysis_scales(cr);
}
-
cairo_copy_page(cr);
cairo_set_source_surface(cr, _analysis_scale_surface, 0.0, 0.0);
cairo_paint(cr);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+
if (_phase_button->get_active()) {
plot_impulse_phase(_analysis_area, cr);
}
+
plot_impulse_amplitude(_analysis_area, cr);
- // TODO: make this optional
- plot_signal_amplitude_difference(_analysis_area, cr);
+ if (_pointer_in_area_xpos >= 0) {
+ update_pointer_info (_pointer_in_area_xpos);
+ }
- cairo_destroy(cr);
+ if (_signal_button->get_active()) {
+ plot_signal_amplitude_difference(_analysis_area, cr);
+ }
+ 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);
+ cairo_move_to (cr, _pointer_in_area_freq - .5, -.5);
+ cairo_line_to (cr, _pointer_in_area_freq - .5, _analysis_height - .5);
+ cairo_stroke(cr);
+ }
+ cairo_destroy(cr);
}
#define PHASE_PROPORTION 0.5
y = _analysis_height/2.0 - (float)i*(_analysis_height/8.0)*PHASE_PROPORTION;
- cairo_set_source_rgb(cr, .8, .9, 0.2);
+ cairo_set_source_rgb(cr, .8, .9, 0.2);
if (i == 0) {
snprintf(buf,256, "0\u00b0");
} else {
continue;
- cairo_set_source_rgba(cr, .8, .9, 0.2, 0.6/(float)i);
+ cairo_set_source_rgba(cr, .8, .9, 0.2, 0.6/(float)i);
cairo_move_to(cr, 0.0, y);
cairo_line_to(cr, _analysis_width, y);
// label
snprintf(buf,256, "-%d\u00b0", (i * 45));
- cairo_set_source_rgb(cr, .8, .9, 0.2);
+ 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);
// line
- cairo_set_source_rgba(cr, .8, .9, 0.2, 0.6/(float)i);
+ cairo_set_source_rgba(cr, .8, .9, 0.2, 0.6/(float)i);
cairo_move_to(cr, 0.0, y);
cairo_line_to(cr, _analysis_width, y);
// float width = w->get_width();
float height = w->get_height();
- cairo_set_source_rgba(cr, 0.95, 0.3, 0.2, 1.0);
+ cairo_set_source_rgba(cr, 0.95, 0.3, 0.2, 1.0);
for (uint32_t i = 0; i < _impulse_fft->bins()-1; i++) {
// x coordinate of bin i
x = log10f(1.0 + (float)i / (float)_impulse_fft->bins() * _log_coeff) / _log_max;
}
-inline float
-power_to_dB(float a)
-{
- return 10.0 * log10f(a);
-}
-
void
PluginEqGui::plot_impulse_amplitude(Gtk::Widget *w, cairo_t *cr)
{
// float width = w->get_width();
float height = w->get_height();
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+ cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_set_line_width (cr, 2.5);
for (uint32_t i = 0; i < _impulse_fft->bins()-1; i++) {
// float width = w->get_width();
float height = w->get_height();
- cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
- cairo_set_line_width (cr, 2.5);
+ cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
+ cairo_set_line_width (cr, 1.5);
for (uint32_t i = 0; i < _signal_input_fft->bins()-1; i++) {
// x coordinate of bin i
x = log10f(1.0 + (float)i / (float)_signal_input_fft->bins() * _log_coeff) / _log_max;
x *= _analysis_width;
- float power_out = power_to_dB(_signal_output_fft->power_at_bin(i));
- float power_in = power_to_dB(_signal_input_fft ->power_at_bin(i));
- float power = power_out - power_in;
-
- // for SaBer
- /*
- double p = 10.0 * log10( 1.0 + (double)_signal_output_fft->power_at_bin(i) - (double)
- - _signal_input_fft ->power_at_bin(i));
- //p *= 1000000.0;
- float power = (float)p;
+ float power_out = _signal_output_fft->power_at_bin (i) + 1e-30;
+ float power_in = _signal_input_fft ->power_at_bin (i) + 1e-30;
+ float power = power_to_dB (power_out / power_in);
- if ( (i % 1000) == 0) {
- std::cerr << i << ": " << power << std::endl;
- }
- */
-
- if (ISINF(power)) {
- if (power < 0) {
- power = _min_dB - 1.0;
- } else {
- power = _max_dB - 1.0;
- }
- } else if (ISNAN(power)) {
- power = _min_dB - 1.0;
- }
+ assert (!ISINF(power));
+ assert (!ISNAN(power));
float yCoeff = ( power - _min_dB) / (_max_dB - _min_dB);
}
cairo_stroke(cr);
-
-
}