Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Henning Thielemann <schlepptop@henning-thielemann.de>
To: alsa-devel@alsa-project.org
Cc: Clemens Ladisch <clemens@ladisch.de>
Subject: Re: sending a sequencer event to a delayed queue
Date: Sun, 11 Mar 2012 16:41:31 +0100	[thread overview]
Message-ID: <4F5CC7AB.3030300@henning-thielemann.de> (raw)
In-Reply-To: <4F5BBECF.8020506@ladisch.de>

[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]

Clemens Ladisch schrieb:
> Henning Thielemann wrote:
>> Unfortunately the ALSA doc does not say, what happens if I send an event
>> to a queue that is not running.
> 
> Exactly the same as with a running queue: the event stays in the client's
> output buffer if its scheduled time has not yet been reached.
> 
>> I expected that the event is being delivered once the queue is started.
>> But it seems that instead the event is dropped.
> 
> Perhaps it was delivered too early?

I have attached a C program that demonstrates the effect: I start the
"player" queue with one second delay and immediately send a message with
a timestamp 0 that is meant to be the local time of the "player" queue.
I expected that this event is delivered when the player queue starts,
that is, one second after program start. But actually it is played
immediately. If I choose a time larger than 0, say 1ns or 1s, then the
event is not delivered at all.

I use output_direct, but the effect is the same if I use output and drain.

[-- Attachment #2: send-note-delayed.c --]
[-- Type: text/x-c++src, Size: 2168 bytes --]

#include <alsa/asoundlib.h>
#include <time.h>

void connect (snd_seq_t *seq, int port, const char* dest_name) {
  snd_seq_addr_t addr;
  snd_seq_parse_address(seq, &addr, dest_name);
  snd_seq_connect_to(seq, port, addr.client, addr.port);
  printf("connect to %s: %d:%d\n", dest_name, addr.client, addr.port);
}

int main () {
  snd_seq_t *seq;
  snd_seq_event_t ev;
  snd_seq_ev_clear(&ev);

  snd_seq_open(&seq, "default", SND_SEQ_OPEN_OUTPUT, 0);
  int port = snd_seq_create_simple_port(seq, "out",
                 SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
                 SND_SEQ_PORT_TYPE_MIDI_GENERIC);

  connect (seq, port, "aseqdump");
  connect (seq, port, "TiMidity");

  int control = snd_seq_alloc_queue(seq);
  int player = snd_seq_alloc_queue(seq);

  /* start controller queue */
  snd_seq_control_queue(seq, control, SND_SEQ_EVENT_START, 0, NULL);
  snd_seq_drain_output(seq);

  /* start player queue after one second using controller queue for timing */
  const int absolute = 0;
  snd_seq_real_time_t rtime;
  rtime.tv_sec = 1;
  rtime.tv_nsec = 0;
  snd_seq_ev_schedule_real(&ev, control, absolute, &rtime);
  snd_seq_control_queue(seq, player, SND_SEQ_EVENT_START, 0, &ev);
  snd_seq_drain_output(seq);

  snd_seq_ev_set_source(&ev, port);
  snd_seq_ev_set_subs(&ev);

  /* send note-on to player queue with local time 0 */
  /* this is played too early,
     if you increase the time, then the note is not played at all. */
  rtime.tv_sec = 0;
  rtime.tv_nsec = 0;
  snd_seq_ev_schedule_real(&ev, player, absolute, &rtime);
  snd_seq_ev_set_noteon(&ev, 0, 60, 64);
  snd_seq_event_output_direct(seq, &ev);

  /* send note-off to player queue with local time 1 */
  /* this event is dropped */
  rtime.tv_sec = 1;
  rtime.tv_nsec = 0;
  snd_seq_ev_schedule_real(&ev, player, absolute, &rtime);
  snd_seq_ev_set_noteoff(&ev, 0, 60, 64);
  snd_seq_event_output_direct(seq, &ev);

  snd_seq_sync_output_queue(seq);

  /* make sure that we do not destroy pending messages */
  sleep(3);

  snd_seq_free_queue(seq, control);
  snd_seq_free_queue(seq, player);
  snd_seq_delete_simple_port(seq, port);
  snd_seq_close(seq);

  return 0;
}

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2012-03-11 15:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-10 18:20 sending a sequencer event to a delayed queue Henning Thielemann
2012-03-10 20:51 ` Clemens Ladisch
2012-03-11 15:41   ` Henning Thielemann [this message]
2012-03-11 20:40     ` Clemens Ladisch
2012-03-11 21:08       ` Henning Thielemann
2012-03-11 22:14         ` Henning Thielemann
2012-03-12  8:21         ` Clemens Ladisch
2012-03-14 20:01           ` Henning Thielemann
2012-03-14 20:22             ` Henning Thielemann
2012-03-14 21:36               ` Clemens Ladisch
2012-03-13 22:33       ` Henning Thielemann
2012-03-14  8:22         ` Clemens Ladisch
2012-03-14 17:37       ` Henning Thielemann

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=4F5CC7AB.3030300@henning-thielemann.de \
    --to=schlepptop@henning-thielemann.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox