diff --git a/libs/ardour/ardour/audio_unit.h b/libs/ardour/ardour/audio_unit.h index 24f427b124..c5c5ed4a95 100644 --- a/libs/ardour/ardour/audio_unit.h +++ b/libs/ardour/ardour/audio_unit.h @@ -171,7 +171,7 @@ class LIBARDOUR_API AUPlugin : public ARDOUR::Plugin int32_t output_channels; std::vector > io_configs; framecnt_t _last_nframes; - mutable framecnt_t _current_latency; + mutable volatile guint _current_latency; bool _requires_fixed_size_buffers; AudioBufferList* buffers; bool _has_midi_input; diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index 3e6bdfb691..85a387e933 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -431,7 +431,7 @@ AUPlugin::AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptrLatency() * _session.frame_rate(); + guint lat = g_atomic_int_get (&_current_latency);; + if (lat == UINT_MAX) { + lat = unit->Latency() * _session.frame_rate(); + g_atomic_int_set (&_current_latency, lat); } - return _current_latency; + return lat; } void @@ -3474,9 +3476,9 @@ AUPlugin::parameter_change_listener (void* /*arg*/, void* src, const AudioUnitEv { if (event->mEventType == kAudioUnitEvent_PropertyChange) { if (event->mArgument.mProperty.mPropertyID == kAudioUnitProperty_Latency) { - DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Latency Change Event %1 <> %1\n", new_value, unit->Latency())); - // TODO atomically set //_current_latency = -1; - _current_latency = unit->Latency() * _session.frame_rate(); // TODO: check: new_value + DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Latency Change Event %1 <> %2\n", new_value, unit->Latency())); + guint lat = unit->Latency() * _session.frame_rate(); + g_atomic_int_set (&_current_latency, lat); } return; }