* enabled moving averages again... plays much nicer in a realtime setup
authorHans Baier <hansfbaier@googlemail.com>
Thu, 7 Aug 2008 04:03:17 +0000 (04:03 +0000)
committerHans Baier <hansfbaier@googlemail.com>
Thu, 7 Aug 2008 04:03:17 +0000 (04:03 +0000)
* disabled excessive tracing

git-svn-id: svn://localhost/ardour2/branches/3.0@3668 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/slave.h
libs/ardour/midi_clock_slave.cc

index 4831fd0c9869f84dd6b7af851aacbf3ea97ed1e3..9ec064445a7f8eb0766f897bef52efcbb2c89c04 100644 (file)
@@ -135,6 +135,11 @@ class MIDIClock_Slave : public Slave, public sigc::trackable {
        nframes_t   first_midi_clock_frame;
        nframes_t   first_midi_clock_time;
 
+       static const int32_t accumulator_size = 128;
+       float   accumulator[accumulator_size];
+       int32_t accumulator_index;
+       bool    have_first_accumulated_speed;
+
        void reset ();
        void start (MIDI::Parser& parser);
        void stop (MIDI::Parser& parser);
index db33902fd3bf44318e13e524081c53330a66dc59..f570b5406a1f667e9982653d261237b320a07bdf 100644 (file)
@@ -97,10 +97,11 @@ MIDIClock_Slave::update_midi_clock (Parser& parser)
        midi_clock_frame += (long) (one_ppqn_in_frames)
                            + session.worst_output_latency();
 
+       /*
        std::cerr << "got MIDI Clock message at time " << now  
                  << " midi_clock_frame: " << midi_clock_frame 
                  << " one_ppqn_in_frames: " << one_ppqn_in_frames << std::endl;
-       
+       */
        if (first_midi_clock_frame == 0) {
                first_midi_clock_frame = midi_clock_frame;
                first_midi_clock_time = now;
@@ -204,9 +205,29 @@ MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
                speed_now = (float) ((last.position - first_midi_clock_frame) / (double) (now - first_midi_clock_time));
        }
 
-       cerr << "speed_and_position: speed_now: " << speed_now ;
+       //cerr << "speed_and_position: speed_now: " << speed_now ;
        
-       midi_clock_speed = speed_now;
+       accumulator[accumulator_index++] = speed_now;
+
+       if (accumulator_index >= accumulator_size) {
+               have_first_accumulated_speed = true;
+               accumulator_index = 0;
+       }
+
+       if (have_first_accumulated_speed) {
+               float total = 0;
+
+               for (int32_t i = 0; i < accumulator_size; ++i) {
+                       total += accumulator[i];
+               }
+
+               midi_clock_speed = total / accumulator_size;
+
+       } else {
+
+               midi_clock_speed = speed_now;
+
+       }
 
        if (midi_clock_speed == 0.0f) {
 
@@ -229,7 +250,7 @@ MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
 
        speed = midi_clock_speed;
        
-       cerr << " final speed: " << speed << " position: " << pos << endl;
+       //cerr << " final speed: " << speed << " position: " << pos << endl;
        return true;
 }