13
0

Temporal: extend timepos_t API to provide samples() method, using thread-local sample rate

This commit is contained in:
Paul Davis 2020-08-05 16:04:57 -06:00
parent 4c6d6b14e5
commit 791e76290d
2 changed files with 5 additions and 0 deletions

View File

@ -32,6 +32,10 @@ extern superclock_t superclock_ticks_per_second;
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 (int samples, int sr) { return int_div_round (samples * superclock_ticks_per_second, superclock_t (sr)); }
/* this needs to be updated per-thread at a suitable time */
extern thread_local uint32_t _thread_sample_rate;
}
#endif /* __ardour_superclock_h__ */

View File

@ -56,6 +56,7 @@ class timepos_t : public int62_t {
Temporal::TimeDomain time_domain () const { if (flagged()) return Temporal::BeatTime; return Temporal::AudioTime; }
superclock_t superclocks() const { if (is_superclock()) return v; return _superclocks (); }
int64_t samples() const { return superclock_to_samples (superclocks(), _thread_sample_rate); }
int64_t ticks() const { if (is_beats()) return val(); return _ticks (); }
Beats beats() const { if (is_beats()) return Beats::ticks (val()); return _beats (); }