#include "audio_mixer.h"
#include "ui_delay_analyzer.h"
+#include "shared/post_to_main_thread.h"
#include <bmusb/bmusb.h>
grab_timeout->start(milliseconds(2000));
clip1.clear();
clip2.clear();
+ ui->delay_estimate_label->clear();
ui->peak_display_1->reset_base();
ui->peak_display_2->reset_base();
ui->peak_display_1->audio_clip_updated();
clip2.clear();
ui->peak_display_2->audio_clip_updated();
}
+ ui->delay_estimate_label->clear();
}
void DelayAnalyzer::channel_selected(QComboBox *channel_combo)
clip2.clear();
ui->peak_display_2->audio_clip_updated();
}
+ ui->delay_estimate_label->clear();
}
DeviceSpec DelayAnalyzer::get_selected_device(QComboBox *card_combo)
grab_timeout->stop();
});
grabbing = false;
+
+ // The delay estimation is cheap, but it's not free, and we're on the main mixer thread,
+ // so fire it off onto a background thread.
+ std::thread(&DelayAnalyzer::estimate_delay, this).detach();
+ }
+}
+
+void DelayAnalyzer::estimate_delay()
+{
+ AudioClip::BestCorrelation corr = clip1.find_best_correlation(&clip2);
+ char buf[256];
+ if (isnan(corr.correlation) || fabs(corr.correlation) < 0.1) { // Very loose bound, basically to guard against digital silence.
+ snprintf(buf, sizeof(buf), "Could not estimate delay.\n");
+ } else if (corr.correlation < 0.0) {
+ snprintf(buf, sizeof(buf), "Best estimate: Channel is %.1f ms delayed compared to reference <em>and inverted</em> (correlation = %.3f)\n",
+ corr.delay_ms, corr.correlation);
+ } else {
+ snprintf(buf, sizeof(buf), "Best estimate: Channel is %.1f ms delayed compared to reference (correlation = %.3f)\n",
+ corr.delay_ms, corr.correlation);
}
+ post_to_main_thread([this, buf] {
+ ui->delay_estimate_label->setText(buf);
+ });
}
void DelayAnalyzer::grab_timed_out()