All of lore.kernel.org
 help / color / mirror / Atom feed
From: nescivi <nescivi@gmail.com>
To: alsa-devel@alsa-project.org
Subject: problem with scheduling alsa events
Date: Tue, 25 Nov 2008 10:09:58 -0500	[thread overview]
Message-ID: <200811251009.58254.nescivi@gmail.com> (raw)

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;
}

                 reply	other threads:[~2008-11-25 15:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200811251009.58254.nescivi@gmail.com \
    --to=nescivi@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.