Fix MIDI Clock generator (rounding issues)

This broke in f67029bd0 and notably bcc1aeeb86.

next_tick needs to accommodate for sub-sample accuracy when
PPQN are not integer samples. e.g. 110 bpm @ 48kHz

PS. Instead of `double` we could use superclock next_tick, and
`one_ppqn_in_superclocks` respectively. This would provide us
with 62 bit significand (instead of 52 bit using double).

Yet for the case of MIDI clock, this will have no real world
effect.
This commit is contained in:
Robin Gareus 2024-12-29 15:56:42 +01:00
parent c98a36be0f
commit 6e2d34df2d
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
2 changed files with 3 additions and 2 deletions

View file

@ -47,7 +47,7 @@ private:
ARDOUR::Session& _session;
std::shared_ptr<MidiPort> _midi_port;
bool _rolling;
samplepos_t _next_tick;
double _next_tick;
uint32_t _beat_pos;
uint32_t _clock_cnt;
samplepos_t _transport_pos;

View file

@ -219,7 +219,8 @@ double
MidiClockTicker::one_ppqn_in_samples (samplepos_t transport_position) const
{
TempoPoint const & tempo (TempoMap::use()->metric_at (timepos_t (transport_position)).tempo());
const double samples_per_quarter_note = superclock_to_samples (tempo.superclocks_per_note_type_at (timepos_t (transport_position)), _session.nominal_sample_rate());
/* un-rounded superclock_to_samples (tempo.superclocks_per_note_type_at (timepos_t (transport_position)), _session.nominal_sample_rate()) */
const double samples_per_quarter_note = tempo.superclocks_per_note_type_at (timepos_t (transport_position)) * _session.nominal_sample_rate() / (double)superclock_ticks_per_second ();
return samples_per_quarter_note / 24.0;
}