midi_clock_slave: fix wrong calculation of loop error

since transport_frame refers to cycle start, the should be position has
to account for position of the midi clock event.
This commit is contained in:
Hans Baier 2013-12-18 09:55:15 +07:00
parent bc5d23d5fa
commit caac41a9cb
3 changed files with 23 additions and 11 deletions

View file

@ -189,6 +189,7 @@ class ISlaveSessionProxy {
virtual framepos_t audible_frame () const { return 0; } virtual framepos_t audible_frame () const { return 0; }
virtual framepos_t transport_frame () const { return 0; } virtual framepos_t transport_frame () const { return 0; }
virtual pframes_t frames_since_cycle_start () const { return 0; } virtual pframes_t frames_since_cycle_start () const { return 0; }
virtual pframes_t sample_time_at_cycle_start() const { return 0; }
virtual framepos_t frame_time () const { return 0; } virtual framepos_t frame_time () const { return 0; }
virtual void request_locate (framepos_t /*frame*/, bool with_roll = false) { virtual void request_locate (framepos_t /*frame*/, bool with_roll = false) {
@ -211,6 +212,7 @@ class SlaveSessionProxy : public ISlaveSessionProxy {
framepos_t audible_frame () const; framepos_t audible_frame () const;
framepos_t transport_frame () const; framepos_t transport_frame () const;
pframes_t frames_since_cycle_start () const; pframes_t frames_since_cycle_start () const;
pframes_t sample_time_at_cycle_start() const;
framepos_t frame_time () const; framepos_t frame_time () const;
void request_locate (framepos_t frame, bool with_roll = false); void request_locate (framepos_t frame, bool with_roll = false);

View file

@ -123,6 +123,8 @@ MIDIClock_Slave::update_midi_clock (Parser& /*parser*/, framepos_t timestamp)
return; return;
} }
pframes_t cycle_offset = timestamp - session->sample_time_at_cycle_start();
calculate_one_ppqn_in_frames_at(should_be_position); calculate_one_ppqn_in_frames_at(should_be_position);
framepos_t elapsed_since_start = timestamp - first_timestamp; framepos_t elapsed_since_start = timestamp - first_timestamp;
@ -131,7 +133,6 @@ MIDIClock_Slave::update_midi_clock (Parser& /*parser*/, framepos_t timestamp)
if (_starting || last_timestamp == 0) { if (_starting || last_timestamp == 0) {
midi_clock_count = 0; midi_clock_count = 0;
first_timestamp = timestamp; first_timestamp = timestamp;
elapsed_since_start = should_be_position; elapsed_since_start = should_be_position;
@ -156,7 +157,7 @@ MIDIClock_Slave::update_midi_clock (Parser& /*parser*/, framepos_t timestamp)
// we use session->transport_frame() instead of t1 here // we use session->transport_frame() instead of t1 here
// because t1 is used to calculate the transport speed, // because t1 is used to calculate the transport speed,
// so the loop will compensate for accumulating rounding errors // so the loop will compensate for accumulating rounding errors
error = (double(should_be_position) - double(session->transport_frame())); error = (double(should_be_position) - (double(session->transport_frame()) + double(cycle_offset)));
e = error / double(session->frame_rate()); e = error / double(session->frame_rate());
current_delta = error; current_delta = error;
@ -167,7 +168,7 @@ MIDIClock_Slave::update_midi_clock (Parser& /*parser*/, framepos_t timestamp)
} }
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("clock #%1 @ %2 should-be %3 transport %4 error %5 appspeed %6 " DEBUG_TRACE (DEBUG::MidiClock, string_compose ("clock #%1 @ %2 should-be %3 transport %4 error %5 appspeed %6 "
"read-delta %7 should-be delta %8 t1-t0 %9 t0 %10 t1 %11 framerate %12\n", "read-delta %7 should-be delta %8 t1-t0 %9 t0 %10 t1 %11 framerate %12 engine %13\n",
midi_clock_count, // # midi_clock_count, // #
elapsed_since_start, // @ elapsed_since_start, // @
should_be_position, // should-be should_be_position, // should-be
@ -179,7 +180,9 @@ MIDIClock_Slave::update_midi_clock (Parser& /*parser*/, framepos_t timestamp)
(t1 - t0) * session->frame_rate(), // t1-t0 (t1 - t0) * session->frame_rate(), // t1-t0
t0 * session->frame_rate(), // t0 t0 * session->frame_rate(), // t0
t1 * session->frame_rate(), // t1 t1 * session->frame_rate(), // t1
session->frame_rate() // framerate session->frame_rate(), // framerate
session->frame_time()
)); ));
last_timestamp = timestamp; last_timestamp = timestamp;

View file

@ -59,6 +59,13 @@ SlaveSessionProxy::frames_since_cycle_start() const
return session.engine().samples_since_cycle_start(); return session.engine().samples_since_cycle_start();
} }
pframes_t
SlaveSessionProxy::sample_time_at_cycle_start() const
{
return session.engine().sample_time_at_cycle_start();
}
framepos_t framepos_t
SlaveSessionProxy::frame_time() const SlaveSessionProxy::frame_time() const
{ {