superclock_ticks_per_second: use an (inline) accessor, change value

We do not want a value as large as the previous one, which limits the time
range that can be represented in 62 bits unnecessarily. The new value is
9 times smaller than the previous value, and loses only 384000 as a significant
factor.

This commit also switches to using an (inline) accessor for superclock_ticks_per_second,
making it possible in debug/testing phases to spot early/illegal uses of the value.
This commit is contained in:
Paul Davis 2022-03-17 14:14:41 -06:00
parent 641589c56a
commit a803dd0df8
7 changed files with 40 additions and 30 deletions

View file

@ -19,7 +19,9 @@
#ifndef __ardour_superclock_h__
#define __ardour_superclock_h__
#include <cstdlib>
#include <stdint.h>
#include <csignal>
#include "pbd/integer_division.h"
@ -30,17 +32,26 @@ namespace Temporal {
typedef int64_t superclock_t;
#ifndef COMPILER_MSVC
extern superclock_t superclock_ticks_per_second;
extern superclock_t _superclock_ticks_per_second;
#else
static superclock_t superclock_ticks_per_second = 508032000; // 2^10 * 3^4 * 5^3 * 7^2
static superclock_t _superclock_ticks_per_second = 56448000; /* 2^10 * 3^2 * 5^3 * 7^2 */
#endif
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 bool scts_set;
#ifdef DEBUG_EARLY_SCTS_USE
static inline superclock_t superclock_ticks_per_second() { if (!scts_set) { raise (SIGUSR2); } return _superclock_ticks_per_second; }
#else
static inline superclock_t superclock_ticks_per_second() { return _superclock_ticks_per_second; }
#endif
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 most_recent_engine_sample_rate;
LIBTEMPORAL_API void set_sample_rate (int sr);
LIBTEMPORAL_API void set_superclock_ticks_per_second (superclock_t sc);
}