summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/audioengine.h2
-rw-r--r--libs/ardour/audioengine.cc53
-rw-r--r--libs/ardour/session.cc17
3 files changed, 65 insertions, 7 deletions
diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h
index 21206da8fc..5762e709b3 100644
--- a/libs/ardour/ardour/audioengine.h
+++ b/libs/ardour/ardour/audioengine.h
@@ -188,6 +188,7 @@ public:
/* latency measurement */
MTDM* mtdm();
+ int prepare_for_latency_measurement ();
void start_latency_detection ();
void stop_latency_detection ();
void set_latency_input_port (const std::string&);
@@ -225,6 +226,7 @@ public:
std::string _latency_input_name;
std::string _latency_output_name;
framecnt_t _latency_signal_latency;
+ bool _started_for_latency;
void meter_thread ();
void start_metering_thread ();
diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc
index ba5b5ad525..819a166866 100644
--- a/libs/ardour/audioengine.cc
+++ b/libs/ardour/audioengine.cc
@@ -80,6 +80,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 ();
@@ -202,6 +203,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);
@@ -609,7 +617,9 @@ AudioEngine::start ()
start_metering_thread ();
- Running(); /* EMIT SIGNAL */
+ if (!_started_for_latency) {
+ Running(); /* EMIT SIGNAL */
+ }
return 0;
}
@@ -632,6 +642,7 @@ AudioEngine::stop ()
_measuring_latency = false;
_latency_output_port = 0;
_latency_input_port = 0;
+ _started_for_latency = false;
stop_metering_thread ();
Port::PortDrop ();
@@ -982,6 +993,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;
}
@@ -995,9 +1013,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;
@@ -1026,26 +1063,32 @@ AudioEngine::start_latency_detection ()
_latency_signal_latency = 0;
lr = pe.get_latency_range (_latency_input_port, false);
_latency_signal_latency = lr.max;
+ cerr << "Input port lm = " << lr.max;
lr = pe.get_latency_range (_latency_output_port, true);
_latency_signal_latency += lr.max;
+ cerr << " output port lm = " << lr.max << endl;
- 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 ()
{
+ cerr << "Stop LD\n";
+
+ _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
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 443738f777..94882c13b3 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -289,13 +289,26 @@ Session::Session (AudioEngine &eng,
/* we need the audioengine to be up and usable to make much more
* progress with construction, so lets get that started if it isn't already.
*/
-
- if (_engine.current_backend() == 0 || _engine.setup_required()) {
+
+ if (_engine.current_backend() == 0) {
+ /* backend is unknown ... */
+ boost::optional<int> r = AudioEngineSetupRequired (sr);
+ if (r.get_value_or (-1) != 0) {
+ destroy ();
+ throw failed_constructor();
+ }
+ } else if (_engine.setup_required()) {
+ /* backend is known, but setup is needed */
boost::optional<int> r = AudioEngineSetupRequired (sr);
if (r.get_value_or (-1) != 0) {
destroy ();
throw failed_constructor();
}
+ } else if (!_engine.running()) {
+ if (_engine.start()) {
+ destroy ();
+ throw failed_constructor ();
+ }
}
/* at this point the engine should be connected (i.e. interacting