summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-10-05 17:17:44 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-10-05 17:17:44 +0000
commitb96d96f3f97b3fdbc541ff83d29b339a4a85f92d (patch)
treef2c2f37ee3d396402e2ffc0801d06cb93267c9f6 /libs
parentd31649b4b4d2ef9a4d638abffdf39f09ee5058fc (diff)
provide jdelay-based hardware/port insert latency measurement
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@5729 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/SConscript1
-rw-r--r--libs/ardour/ardour/insert.h13
-rw-r--r--libs/ardour/insert.cc83
3 files changed, 91 insertions, 6 deletions
diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript
index 6dfc62ecbc..1d96fd0777 100644
--- a/libs/ardour/SConscript
+++ b/libs/ardour/SConscript
@@ -65,6 +65,7 @@ ladspa_plugin.cc
location.cc
mix.cc
mtc_slave.cc
+mtdm.cc
named_selection.cc
onset_detector.cc
panner.cc
diff --git a/libs/ardour/ardour/insert.h b/libs/ardour/ardour/insert.h
index c401a2062e..7baebe401c 100644
--- a/libs/ardour/ardour/insert.h
+++ b/libs/ardour/ardour/insert.h
@@ -30,6 +30,7 @@
#include <ardour/types.h>
class XMLNode;
+class MTDM;
namespace MIDI {
class Port;
@@ -81,8 +82,18 @@ class PortInsert : public Insert
int32_t configure_io (int32_t magic, int32_t in, int32_t out);
uint32_t bit_slot() const { return bitslot; }
+ void start_latency_detection ();
+ void stop_latency_detection ();
+
+ MTDM* mtdm () const { return _mtdm; }
+ void set_measured_latency (nframes_t);
+
private:
- uint32_t bitslot;
+ uint32_t bitslot;
+ MTDM* _mtdm;
+ bool _latency_detect;
+ nframes_t _latency_flush_frames;
+ nframes_t _measured_latency;
};
class PluginInsert : public Insert
diff --git a/libs/ardour/insert.cc b/libs/ardour/insert.cc
index 3214182c4f..721c61f593 100644
--- a/libs/ardour/insert.cc
+++ b/libs/ardour/insert.cc
@@ -26,6 +26,7 @@
#include <pbd/stacktrace.h>
#include <ardour/insert.h>
+#include <ardour/mtdm.h>
#include <ardour/plugin.h>
#include <ardour/port.h>
#include <ardour/route.h>
@@ -905,12 +906,19 @@ PortInsert::PortInsert (const PortInsert& other)
void
PortInsert::init ()
{
+ _mtdm = 0;
+ _latency_detect = false;
+ _latency_flush_frames = false;
+ _measured_latency = 0;
}
PortInsert::PortInsert (Session& s, const XMLNode& node)
: Insert (s, "will change", PreFader)
{
+ init ();
+
bitslot = 0xffffffff;
+
if (set_state (node)) {
throw failed_constructor();
}
@@ -920,33 +928,94 @@ PortInsert::PortInsert (Session& s, const XMLNode& node)
PortInsert::~PortInsert ()
{
+ delete _mtdm;
GoingAway ();
}
void
+PortInsert::start_latency_detection ()
+{
+ if (_mtdm != 0) {
+ delete _mtdm;
+ }
+
+ _mtdm = new MTDM;
+ _latency_flush_frames = false;
+ _latency_detect = true;
+ _measured_latency = 0;
+}
+
+void
+PortInsert::stop_latency_detection ()
+{
+ _latency_flush_frames = latency() + _session.engine().frames_per_cycle();
+ _latency_detect = false;
+}
+
+void
+PortInsert::set_measured_latency (nframes_t n)
+{
+ _measured_latency = n;
+}
+
+void
PortInsert::run (vector<Sample *>& bufs, uint32_t nbufs, nframes_t nframes)
{
if (n_outputs() == 0) {
return;
}
+ vector<Port*>::iterator o;
+
+ if (_latency_detect) {
+
+ if (n_inputs() != 0) {
+ Sample* in = get_input_buffer (0, nframes);
+ Sample* out = get_output_buffer (0, nframes);
+
+ _mtdm->process (nframes, in, out);
+
+ for (o = _outputs.begin(); o != _outputs.end(); ++o) {
+ (*o)->mark_silence (false);
+ }
+ }
+
+ return;
+
+ } else if (_latency_flush_frames) {
+
+ /* wait for the entire input buffer to drain before picking up input again so that we can't
+ hear the remnants of whatever MTDM pumped into the pipeline.
+ */
+
+ silence (nframes);
+
+ if (_latency_flush_frames > nframes) {
+ _latency_flush_frames -= nframes;
+ } else {
+ _latency_flush_frames = 0;
+ }
+
+ return;
+ }
+
if (!active()) {
/* deliver silence */
silence (nframes);
return;
}
- uint32_t n;
- vector<Port*>::iterator o;
- vector<Port*>::iterator i;
-
/* deliver output */
+ uint32_t n;
+
for (o = _outputs.begin(), n = 0; o != _outputs.end(); ++o, ++n) {
memcpy (get_output_buffer (n, nframes), bufs[min(nbufs,n)], sizeof (Sample) * nframes);
(*o)->mark_silence (false);
}
+ vector<Port*>::iterator i;
+
/* collect input */
for (i = _inputs.begin(), n = 0; i != _inputs.end(); ++i, ++n) {
@@ -1027,7 +1096,11 @@ PortInsert::latency()
need to take that into account too.
*/
- return _session.engine().frames_per_cycle() + input_latency();
+ if (_measured_latency == 0) {
+ return _session.engine().frames_per_cycle() + input_latency();
+ } else {
+ return _measured_latency;
+ }
}
int32_t