All of lore.kernel.org
 help / color / mirror / Atom feed
* Sequencer timestamps for soft synth app
@ 2009-06-03  8:55 Glyn Adgie
  2009-06-03 15:02 ` Clemens Ladisch
  0 siblings, 1 reply; 2+ messages in thread
From: Glyn Adgie @ 2009-06-03  8:55 UTC (permalink / raw)
  To: alsa-devel

I have written a soft synth, which uses ALSA to get MIDI events, and 
Jack to do audio output. MIDI events are fetched and processed at the 
start of the Jack audio callback, then the Jack output buffers are 
filled by the synth engine. The problem I have is that, if the Jack 
buffer size is too large, the time resolution for MIDI events is too 
coarse, and this has a severe effect on rhythms.

I currently get around this by setting  up Jack for a buffer size of 64 
frames, and a sample rate of 48 kHz, giving a timing resolution of 1.33 
msec, which appears to be adequate. However, I might not always be able 
to get the desired buffer size. If the Jack buffer is some multiple of 
64 frames, the synth renders multiple 64 frame chunks until the buffer 
is filled. This takes care of audio quality. However, MIDI timing 
resolution suffers.

I am looking at using the event's timestamp, to decide when to process 
an event. For example, I might have a Jack buffer of 256 frames, so I 
want to work out whether to process an event right away, or after one 64 
frame chunk, and so on. It would appear that, in order to make this 
work, I need an initial timestamp, which I get at the start of the audio 
callback. I then compare each event's timestamp, to determine where it 
should be processed.

I cannot find an ALSA function for getting a timestamp. Perhaps I am 
missing something, or trying to do the job in the wrong way.

Regards

Glyn

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Sequencer timestamps for soft synth app
  2009-06-03  8:55 Sequencer timestamps for soft synth app Glyn Adgie
@ 2009-06-03 15:02 ` Clemens Ladisch
  0 siblings, 0 replies; 2+ messages in thread
From: Clemens Ladisch @ 2009-06-03 15:02 UTC (permalink / raw)
  To: Glyn Adgie; +Cc: alsa-devel

Glyn Adgie wrote:
> I cannot find an ALSA function for getting a timestamp.

If you have a running queue, you can get timestamped events delivered to
your port by enabling it with snd_seq_port_info_set_timestamping() and
snd_seq_port_info_set_timestamp_queue().  (The events don't actually
need to come through that queue.)  See the source code of arecordmidi.


HTH
Clemens

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-03 15:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-03  8:55 Sequencer timestamps for soft synth app Glyn Adgie
2009-06-03 15:02 ` Clemens Ladisch

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.