summaryrefslogtreecommitdiff
path: root/libs/ardour/audioengine.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-09-13 11:55:56 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-09-13 11:55:56 -0400
commit4861eca97483128e5febb575b94688581abb0154 (patch)
tree9893912806d7267a0086a94d4065d32663fe157b /libs/ardour/audioengine.cc
parentc985a64d5851634a77bc013a7f66ef8d9ccefcae (diff)
parent83a826095deaddb90b8236a757c384aa6f120e71 (diff)
Merge branch 'master' into windows
Diffstat (limited to 'libs/ardour/audioengine.cc')
-rw-r--r--libs/ardour/audioengine.cc56
1 files changed, 46 insertions, 10 deletions
diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc
index ded8bf39b5..63bed97ecc 100644
--- a/libs/ardour/audioengine.cc
+++ b/libs/ardour/audioengine.cc
@@ -78,6 +78,7 @@ AudioEngine::AudioEngine ()
, _latency_output_port (0)
, _latency_flush_frames (0)
, _latency_signal_latency (0)
+ , _started_for_latency (false)
{
g_atomic_int_set (&m_meter_exit, 0);
discover_backends ();
@@ -200,6 +201,13 @@ AudioEngine::process_callback (pframes_t nframes)
bool return_after_remove_check = false;
if (_measuring_latency && _mtdm) {
+ /* run a normal cycle from the perspective of the PortManager
+ so that we get silence on all registered ports.
+
+ we overwrite the silence on the two ports used for latency
+ measurement.
+ */
+
PortManager::cycle_start (nframes);
PortManager::silence (nframes);
@@ -415,8 +423,6 @@ AudioEngine::remove_session ()
if (_running) {
- stop_metering_thread ();
-
if (_session) {
session_remove_pending = true;
session_removal_countdown = 0;
@@ -564,8 +570,7 @@ AudioEngine::set_backend (const std::string& name, const std::string& arg1, cons
throw failed_constructor ();
}
- _backend = b->second->backend_factory (*this);
- _impl = b->second->portengine_factory (*this);
+ _backend = b->second->factory (*this);
} catch (exception& e) {
error << string_compose (_("Could not create backend for %1: %2"), name, e.what()) << endmsg;
@@ -607,7 +612,9 @@ AudioEngine::start ()
start_metering_thread ();
- Running(); /* EMIT SIGNAL */
+ if (!_started_for_latency) {
+ Running(); /* EMIT SIGNAL */
+ }
return 0;
}
@@ -630,6 +637,7 @@ AudioEngine::stop ()
_measuring_latency = false;
_latency_output_port = 0;
_latency_input_port = 0;
+ _started_for_latency = false;
stop_metering_thread ();
Port::PortDrop ();
@@ -693,7 +701,7 @@ AudioEngine::connected() const
return false;
}
- return _backend->connected();
+ return _backend->available();
}
void
@@ -980,6 +988,13 @@ AudioEngine::halted_callback (const char* why)
bool
AudioEngine::setup_required () const
{
+ /* If there is only a single backend and it claims to be configured
+ * already there is no setup to be done.
+ *
+ * Primarily for a case where there is only a JACK backend and
+ * JACK is already running.
+ */
+
if (_backends.size() == 1 && _backends.begin()->second->already_configured()) {
return false;
}
@@ -993,9 +1008,28 @@ AudioEngine::mtdm()
return _mtdm;
}
+int
+AudioEngine::prepare_for_latency_measurement ()
+{
+ if (!running()) {
+ _started_for_latency = true;
+
+ if (start()) {
+ _started_for_latency = false;
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
void
AudioEngine::start_latency_detection ()
{
+ if (prepare_for_latency_measurement ()) {
+ return;
+ }
+
PortEngine& pe (port_engine());
delete _mtdm;
@@ -1027,23 +1061,25 @@ AudioEngine::start_latency_detection ()
lr = pe.get_latency_range (_latency_output_port, true);
_latency_signal_latency += lr.max;
- cerr << "latency signal pathway = " << _latency_signal_latency << endl;
-
/* all created and connected, lets go */
_mtdm = new MTDM (sample_rate());
_measuring_latency = true;
_latency_flush_frames = samples_per_cycle();
-
}
void
AudioEngine::stop_latency_detection ()
{
+ _measuring_latency = false;
+
port_engine().unregister_port (_latency_output_port);
port_engine().unregister_port (_latency_input_port);
- _measuring_latency = false;
+
+ if (_started_for_latency) {
+ stop ();
+ }
}
void