problem with scheduling alsa events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hiho,

In the Midi output code of this opensource project I am working on, there is a 
problem with the timing when alsa events are scheduled in the future.
The events take much longer to arrive (sometimes almost minutes later!).

Below is the code snippet.

Can anyone see what is wrong in here?
Let me know if you need more code...

This is with libasound2 1.0.16-2 (Debian unstable).

sincerely,
Marije


int SC_AlsaMidiClient::sendEvent(int outputIndex, int uid, snd_seq_event_t* 
evt, float late)
{
        snd_seq_real_time time;
        
        if ((outputIndex < 0) || (outputIndex >= mNumOutPorts)) return 
errIndexOutOfRange;

        snd_seq_ev_set_source(evt, mOutPorts[outputIndex]);
        if (uid == 0) {
                // send to all subscribed ports
                snd_seq_ev_set_subs(evt);
        } else {
                // send to specific port
                int cid, pid;
                SC_AlsaParseUID(uid, cid, pid);
                snd_seq_ev_set_dest(evt, cid, pid);
        }

// late is the latency value in seconds in floats
        if (late > 0.f) {
// old time calculation:
//              time.tv_sec = (unsigned)(late * 1.0e-6f);
//              time.tv_nsec = (unsigned)(late * 1.0e3f);
// new time calculation. The old one was not correct
                time.tv_sec = (unsigned)(late); // seconds
                time.tv_nsec = (unsigned)(late * 1.0e9f) % 1000000000; // 
nanoseconds
// should these be (long) instead???
        } else {
                time.tv_sec = time.tv_nsec = 0;
        }

        post("MIDI (ALSA): sending event, time %i, %i, late %f\n", 
time.tv_sec, 
time.tv_nsec, late);

        snd_seq_ev_schedule_real(evt, mQueue, 1, &time);
        snd_seq_event_output_direct(mHandle, evt);

        return errNone;
}
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel


[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux