temporal: provide ::decrement_by_domain() methods for time{pos,cnt}_t
audio time nominally uses superclocks as its canonical unit. However many things at a higher level only understand samples. If we increment or decrement a superclock value by 1, the vast majority of the time we will still get the same sample value after conversion. Thus to correctly alter an audio time by an amount that will manifest as 1 sample's difference, we have to use samples_to_superclock(1)
This commit is contained in:
parent
617a517a60
commit
c4d737dd87
@ -168,16 +168,31 @@ class LIBTEMPORAL_API timepos_t : public int62_t {
|
|||||||
|
|
||||||
timepos_t & shift_earlier (Temporal::BBT_Offset const &);
|
timepos_t & shift_earlier (Temporal::BBT_Offset const &);
|
||||||
|
|
||||||
|
/* audio time nominally uses superclocks as its canonical unit. However
|
||||||
|
* many things at a higher level only understand samples. If we
|
||||||
|
* increment or decrement a superclock value by 1, the vast majority of
|
||||||
|
* the time we will still get the same sample value after
|
||||||
|
* conversion. Thus to correctly alter an audio time by an amount
|
||||||
|
* that will manifest as 1 sample's difference, we have to use
|
||||||
|
* samples_to_superclock(1)
|
||||||
|
*/
|
||||||
|
|
||||||
/* given the absence of operator- and thus also operator--, return a
|
/* given the absence of operator- and thus also operator--, return a
|
||||||
* timepos_t that is the previous (earlier) possible position given
|
* timepos_t that is the previous (earlier) possible position given
|
||||||
* this one
|
* this one
|
||||||
*/
|
*/
|
||||||
timepos_t decrement () const { return timepos_t (flagged(), val() > 0 ? val() - 1 : 0); /* cannot go negative */ }
|
timepos_t decrement () const { return timepos_t (flagged(), val() > 0 ? val() - 1 : 0); /* cannot go negative */ }
|
||||||
|
timepos_t decrement_by_domain () const { return timepos_t (flagged(),
|
||||||
|
is_beats() ?
|
||||||
|
(val() > 0 ? val() - 1 : 0) : /* reduce by 1 tick */
|
||||||
|
(val() > samples_to_superclock (1, TEMPORAL_SAMPLE_RATE) ? val() - samples_to_superclock (1, TEMPORAL_SAMPLE_RATE) : 0)); }
|
||||||
|
|
||||||
/* purely for reasons of symmetry with ::decrement(), return a
|
/* purely for reasons of symmetry with ::decrement(), return a
|
||||||
* timepos_t that is the next (later) possible position given this one
|
* timepos_t that is the next (later) possible position given this one
|
||||||
*/
|
*/
|
||||||
timepos_t increment () const { return timepos_t (flagged(), val() + 1); }
|
timepos_t increment () const { return timepos_t (flagged(), val() + 1); }
|
||||||
|
timepos_t increment_by_domain () const { return timepos_t (flagged(), (is_beats() ? (val() + 1) : (val() + samples_to_superclock (1, TEMPORAL_SAMPLE_RATE)))); }
|
||||||
|
|
||||||
|
|
||||||
timepos_t & operator+=(timecnt_t const & d);
|
timepos_t & operator+=(timecnt_t const & d);
|
||||||
timepos_t & operator+=(timepos_t const & d);
|
timepos_t & operator+=(timepos_t const & d);
|
||||||
@ -369,8 +384,19 @@ class LIBTEMPORAL_API timecnt_t {
|
|||||||
timecnt_t & operator-= (timecnt_t const & t);
|
timecnt_t & operator-= (timecnt_t const & t);
|
||||||
timecnt_t & operator+= (timecnt_t const & t);
|
timecnt_t & operator+= (timecnt_t const & t);
|
||||||
|
|
||||||
|
/* audio time nominally uses superclocks as its canonical unit. However
|
||||||
|
* many things at a higher level only understand samples. If we
|
||||||
|
* increment or decrement a superclock value by 1, the vast majority of
|
||||||
|
* the time we will still get the same sample value after
|
||||||
|
* conversion. Thus to correctly alter an audio time by an amount
|
||||||
|
* that will manifest as 1 sample's difference, we have to use
|
||||||
|
* samples_to_superclock(1)
|
||||||
|
*/
|
||||||
|
|
||||||
timecnt_t decrement () const { return timecnt_t (_distance - 1, _position); }
|
timecnt_t decrement () const { return timecnt_t (_distance - 1, _position); }
|
||||||
|
timecnt_t decrement_by_domain () const { return timecnt_t (_distance.flagged() ? _distance - 1 : _distance - samples_to_superclock (1, TEMPORAL_SAMPLE_RATE), _position); }
|
||||||
timecnt_t increment () const { return timecnt_t (_distance + 1, _position); }
|
timecnt_t increment () const { return timecnt_t (_distance + 1, _position); }
|
||||||
|
timecnt_t increment_by_domain () const { return timecnt_t (_distance.flagged() ? _distance + 1 : _distance + samples_to_superclock (1, TEMPORAL_SAMPLE_RATE), _position); }
|
||||||
|
|
||||||
//timecnt_t operator- (timepos_t const & t) const;
|
//timecnt_t operator- (timepos_t const & t) const;
|
||||||
//timecnt_t operator+ (timepos_t const & t) const;
|
//timecnt_t operator+ (timepos_t const & t) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user