[linux-audio-dev] MIDI Clock and ALSA seq

Takashi Iwai tiwai at suse.de
Fri Feb 14 14:08:00 UTC 2003


At Fri, 14 Feb 2003 14:02:45 +0000,
Steve Harris wrote:
> 
> Hi all,
> 
> I'm trying to hack up a quick app that sends MIDI clock pulses in sync
> with a ringbuffer playback.
> 
> I've got it reading MIDI (thanks to Matthias' great exmaple code), but I
> cant figure out how to send MIDI clock pulses explicitly. The ALSA seq
> interface lets me set it up to go automatically, but I want to send a
> clock pulse every 1/24th of the buffer, so the sync is correct.

in theory, it will run like below.

but anyway you need a precise timer source to generate midi clocks
accurately, either the higher kernel HZ or an RTC timer (both need
patches to kernel) in general...


- allocate and set up the queue.

	snd_seq_t *seq;
	// allocation of seq handler
	...

	// allocation of queue
	int queue = snd_seq_alloc_queue(seq);

	snd_seq_queue_tempo_t *tempo;
	snd_seq_queue_tempo_alloca(&tempo);
	snd_seq_queue_tempo_set_tempo(tempo, MY_TEMPO_IN_USEC);
	snd_seq_queue_tempo_set_ppq(tempo, MY_PPQ);
	snd_seq_set_queue_tempo(seq, queue, tempo);

- put the event

	tick_interval = MY_PPQ / 24;

	tick = tick_interval;
	snd_seq_event_t ev;

	snd_seq_ev_clear(&ev);
	ev.dest.client = DESTINATION_CLIENT;
	ev.dest.port = DESTINATION_PORT;
	ev.source.port = MY_PORT;
	ev.type = SND_SEQ_EVENT_TICK;

	snd_seq_ev_schedule_tick(&ev, queue, 0, tick);
	snd_seq_event_output(seq, &ev);
	tick += tick_interval; // next schedule

- start the queue

	snd_seq_start_queue(seq, queue, NULL);

- put the next events in loop



Takashi



More information about the Linux-audio-dev mailing list