Csound Csound-dev Csound-tekno Search About

[Cs-dev] Tuning Jack server and external Midi callback

Date2011-06-09 12:59
FromDurga
Subject[Cs-dev] Tuning Jack server and external Midi callback
AttachmentsNone  None  
Dear Csound community I tinkered a dirty implementation of the csoundSetExternalMidiRead Callback: int midi_in_read(CSOUND * csound, void *userData, unsigned char *buf, int nBytes) { int i; int bytes = 0; ProjData * pFP = (ProjData *) userData; if(userData) { if(pFP->buf_fill > 0) { for(i=0; i < pFP->buf_fill; i++) { buf[i] = pFP->cs_midi_buf[i]; bytes++; } } } return bytes; } pFP->cs_midi_buf is filled by the Jack process callback which is called each Jack cycle. pFP->buf_fill is the amount of bytes written by the Jack process callback. I use a Jack buffer size of 1024 frames / period ksmps = 256 csound software buffer size (-b) = -4 So the Csound software buffer is also 1024 and synced with kr. I get a satisfying real time response to my keyboard strokes but unfortunately Csound outputs around 30: new alloc for instr 1: WARNING: MIDI note overlaps with key 71 on same channel messages. If I reduce the Jack buffer size to 64 (of course I also have to adjust ksmps to =< 64) I can reduce these messegas to around 3 each time I I press a key on my keyboard. I dont understand this behavior. From the Csound Book CD chapter 2 “Real-time Synthesis in Csound with MIDI Control” I've learned “Csound looks to see if there are any new MIDI messages once per k-period.”. So for a -b -4 value I expect 4 “WARNING: MIDI note overlaps with key 71 on same channel” messages. Since I am pretty new to C programming I might have forgotten something fundamental. Do I have to lock the pFP->cs_midi_buf array while Jack is writing / Csound is reading? Any hints are appreciated, please tell me if you need more information about my code or setup. Thank you! Durga

View this message in context: Tuning Jack server and external Midi callback
Sent from the Csound - Dev mailing list archive at Nabble.com.