[alsa-devel] Sequencer timestamps for soft synth app

Glyn Adgie glyn at castro-design.co.uk
Wed Jun 3 10:55:37 CEST 2009


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



More information about the Alsa-devel mailing list