Re: [linux-audio-dev] Realtime problems with midi/osc sequencer

From: Christian <krampenschiesser@email-addr-hidden>
Date: Sat Mar 10 2007 - 23:13:12 EET

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I'd suggest using clock_nanosleep() and clock_gettime() with
> clockid=CLOCK_MONOTONIC.
> This is the "more right" approach than select/gettimeofday().
>
>
> Dmitry.

Yeah clock_nanosleep did it!
I got a stable absolute bpm exact midi clock.
I'll test the osc messages tomorrow( I've to rewrite some stuff of my
first sequencer ).
Whooo, thanks alot.
Christian

p.s.:
The Code:
[CODE]
void Timer::runThread()
{
        std::list<Seq>::iterator iter;
        timespec timeOut;
        int shortTickCount=0;
        int longTickCount=0;
        int midiTickCount=0;
        
        struct sched_param rtparam;
        memset (&rtparam, 0, sizeof (rtparam));
        rtparam.sched_priority = 99;
        pthread_setschedparam (thread, SCHED_FIFO, &rtparam);
        
        while( !bRunning )
                usleep ( 100 );
        
        clock_gettime( CLOCK_MONOTONIC, &timeOut );
        
        for( iter=seqs.begin(); iter!=seqs.end(); iter++ )
        {
                lo_send_timestamped( iter->address, LO_TT_IMMEDIATE, "/timer/tick",
"iii", iTact, iShortTick, iLongTick );
        }
        
        while( !bQuit )
        {
                if( shortTickCount == 3 )
                {
                        iShortTick++;
                        shortTickCount=0;
                        if( iShortTick == 256 )
                        {
                                iShortTick=0;
                                iLongTick=0;
                                iTact++;
                        }
                        for( iter=seqs.begin(); iter!=seqs.end(); iter++ )
                        {
                                lo_send_timestamped( iter->address, LO_TT_IMMEDIATE, "/timer/tick",
"iii", iTact, iShortTick, iLongTick );
                        }
                }
                
                if( longTickCount == 4 )
                {
                        longTickCount=0;
                        iLongTick++;
                }
                
                if( midiTickCount == 8 )
                {
                        midiTickCount=0;
                          midiOut->sendMessage( &midiMsg );
                }
                
                shortTickCount++;
                longTickCount++;
                midiTickCount++;
                
                timeOut.tv_nsec+=iTick*1000;
                if( timeOut.tv_nsec >1000000000 )
                {
                        timeOut.tv_sec++;
                        timeOut.tv_nsec=timeOut.tv_nsec-1000000000;
                }
                
                clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &timeOut, NULL );
        }
        pthread_exit( 0 );
}
[/CODE]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF8x9oVC26eJ+o0+0RAr5gAJ9/a/UMEIKzlA3ZKXhPhEidXs4FGgCgopIC
am0HTYe66SLHV0o9e/hE4oM=
=1owC
-----END PGP SIGNATURE-----
Received on Sun Mar 11 00:15:04 2007

This archive was generated by hypermail 2.1.8 : Sun Mar 11 2007 - 00:15:04 EET