[LAD] problem with scheduling alsa events

From: nescivi <nescivi@email-addr-hidden>
Date: Mon Nov 24 2008 - 21:13:07 EET

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...

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;
}
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Tue Nov 25 00:15:06 2008

This archive was generated by hypermail 2.1.8 : Tue Nov 25 2008 - 00:15:06 EET