[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-audio-dev
Subject:    [LAD] problem with scheduling alsa events
From:       nescivi <nescivi () gmail ! com>
Date:       2008-11-24 19:13:07
Message-ID: 200811241413.08068.nescivi () gmail ! com
[Download RAW message or body]

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@lists.linuxaudio.org
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic