From da95a0a0ee2506daca05870d34b8786567edff5b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 14 Mar 2022 13:16:55 -0600 Subject: [PATCH] replace sample rate callback used for superclock<=>sample conversion Now using a globally-scoped static variable which is updated by the AudioEngine whenever an SR change occurs. Defaults to 48kHz and can be used even before there is a backend. --- libs/ardour/ardour/audioengine.h | 3 --- libs/ardour/audioengine.cc | 1 + libs/ardour/globals.cc | 2 -- libs/ardour/test/automation_list_property_test.cc | 5 ----- libs/ardour/test/test_util.cc | 2 -- libs/temporal/superclock.cc | 6 +++--- libs/temporal/temporal/superclock.h | 6 +++--- 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h index d696238e5a..0f34efe2c2 100644 --- a/libs/ardour/ardour/audioengine.h +++ b/libs/ardour/ardour/audioengine.h @@ -199,9 +199,6 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr static AudioEngine* instance() { return _instance; } static void destroy(); - /* this method is intended only to be used as a "fast" callback from libtemporal */ - static int static_sample_rate () { return _instance->sample_rate(); } - void died (); /* The backend will cause these at the appropriate time(s) */ diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 5d10357583..c36316ee0a 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -198,6 +198,7 @@ AudioEngine::sample_rate_change (pframes_t nframes) } SampleRateChanged (nframes); /* EMIT SIGNAL */ + Temporal::set_sample_rate (nframes); #ifdef SILENCE_AFTER_SECONDS _silence_countdown = nframes * SILENCE_AFTER_SECONDS; diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 11e75a2804..df472cc9af 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -529,8 +529,6 @@ ARDOUR::init (bool try_optimization, const char* localedir, bool with_gui) return true; } - Temporal::set_sample_rate_callback (AudioEngine::static_sample_rate); - running_from_gui = with_gui; #ifndef NDEBUG diff --git a/libs/ardour/test/automation_list_property_test.cc b/libs/ardour/test/automation_list_property_test.cc index 27d003297f..ae082b3b3f 100644 --- a/libs/ardour/test/automation_list_property_test.cc +++ b/libs/ardour/test/automation_list_property_test.cc @@ -43,19 +43,14 @@ write_automation_list_xml (XMLNode* node, std::string filename) CPPUNIT_ASSERT (write_ref (node, output_file)); } -static int -static_sample_rate () { return 48000; } - void AutomationListPropertyTest::setUp () { - Temporal::set_sample_rate_callback (static_sample_rate); } void AutomationListPropertyTest::tearDown () { - Temporal::set_sample_rate_callback (0); } void diff --git a/libs/ardour/test/test_util.cc b/libs/ardour/test/test_util.cc index 91754ceb4a..8b4fba6baf 100644 --- a/libs/ardour/test/test_util.cc +++ b/libs/ardour/test/test_util.cc @@ -107,7 +107,6 @@ create_and_start_dummy_backend () CPPUNIT_ASSERT (engine->set_backend ("None (Dummy)", "Unit-Test", "")); CPPUNIT_ASSERT (engine->start () == 0); - Temporal::set_sample_rate_callback (AudioEngine::static_sample_rate); } void @@ -116,7 +115,6 @@ stop_and_destroy_backend () AudioEngine::instance()->remove_session (); AudioEngine::instance()->stop (); AudioEngine::destroy (); - Temporal::set_sample_rate_callback (0); } /** @param dir Session directory. diff --git a/libs/temporal/superclock.cc b/libs/temporal/superclock.cc index 8b7062042d..613b971da3 100644 --- a/libs/temporal/superclock.cc +++ b/libs/temporal/superclock.cc @@ -22,10 +22,10 @@ Temporal::superclock_t Temporal::superclock_ticks_per_second = 508032000; // 2^10 * 3^4 * 5^3 * 7^2 #endif -int (*Temporal::sample_rate_callback)() = 0; +int Temporal::most_recent_engine_sample_rate = 48000; /* have to pick something as a default */ void -Temporal::set_sample_rate_callback (int (*func)()) +Temporal::set_sample_rate (int sr) { - sample_rate_callback = func; + most_recent_engine_sample_rate = sr; } diff --git a/libs/temporal/temporal/superclock.h b/libs/temporal/temporal/superclock.h index 4eb2c02bf3..f03ac2ca6f 100644 --- a/libs/temporal/temporal/superclock.h +++ b/libs/temporal/temporal/superclock.h @@ -38,12 +38,12 @@ typedef int64_t superclock_t; static inline superclock_t superclock_to_samples (superclock_t s, int sr) { return int_div_round (s * sr, superclock_ticks_per_second); } static inline superclock_t samples_to_superclock (int64_t samples, int sr) { return int_div_round (samples * superclock_ticks_per_second, superclock_t (sr)); } -extern int (*sample_rate_callback)(); +extern int most_recent_engine_sample_rate; -LIBTEMPORAL_API void set_sample_rate_callback (int (*function)()); +LIBTEMPORAL_API void set_sample_rate (int sr); } -#define TEMPORAL_SAMPLE_RATE (sample_rate_callback ()) +#define TEMPORAL_SAMPLE_RATE (most_recent_engine_sample_rate) #endif /* __ardour_superclock_h__ */