~aio-launchpad/seq24/seq24

« back to all changes in this revision

Viewing changes to src/perform.cpp

  • Committer: Sebastien Alaiwan
  • Date: 2012-01-05 07:08:37 UTC
  • Revision ID: ace17@free.fr-20120105070837-25h5y6tls37tp696
Use integer division to compute delta_tick. This way, the division does not loose precision (because the remainder is re-injected into the next division) and the sum of all delta_tick (i.e clock_tick) does not drift (relative to the system clock.).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1294
1294
        /* tick and tick fraction */
1295
1295
        double current_tick   = 0.0;
1296
1296
        double total_tick   = 0.0;
1297
 
        double clock_tick = 0.0;
 
1297
        long clock_tick = 0;
 
1298
        long delta_tick_frac = 0;
1298
1299
 
1299
1300
        long stats_total_tick = 0;
1300
1301
 
1389
1390
            int bpm  = m_master_bus.get_bpm();
1390
1391
 
1391
1392
            /* get delta ticks, delta_ticks_f is in 1000th of a tick */
1392
 
            double delta_tick = (double) (bpm * ppqn * (delta_us/60000000.0f));
 
1393
            long long delta_tick_num = bpm * ppqn * delta_us + delta_tick_frac;
 
1394
            long long delta_tick_denom = 60000000;
 
1395
            long delta_tick = (long)(delta_tick_num / delta_tick_denom);
 
1396
            delta_tick_frac = (long)(delta_tick_num % delta_tick_denom);
1393
1397
 
1394
1398
            if (m_usemidiclock) {
1395
1399
                delta_tick = m_midiclocktick;
1564
1568
             * as soon as jack gets a good lock on playback */
1565
1569
 
1566
1570
            if (init_clock) {
1567
 
                m_master_bus.init_clock( (long)clock_tick );
 
1571
                m_master_bus.init_clock( clock_tick );
1568
1572
                init_clock = false;
1569
1573
            }
1570
1574
 
1588
1592
                //printf( "play[%d]\n", current_tick );
1589
1593
 
1590
1594
                /* midi clock */
1591
 
                m_master_bus.clock( (long) clock_tick );
 
1595
                m_master_bus.clock( clock_tick );
1592
1596
 
1593
1597
 
1594
1598
                if ( global_stats ){