diff -Naur /home/rgareus/tmp/bea/Makefile beatrix/Makefile
--- /home/rgareus/tmp/bea/Makefile	2004-11-25 23:42:33.000000000 +0100
+++ beatrix/Makefile	2007-04-19 22:45:03.000000000 +0200
@@ -45,7 +45,7 @@
 CFLAGS=	-O $(DEFINES)
 #CFLAGS=	-g -DOFFLINE $(DEFINES)
 
-LIBS=	-lm -lpthread
+LIBS=	-lm -lpthread -ljack
 
 beatrix:	$(OBJS)
 	cc -o $(@) $(OBJS) $(LIBS)
diff -Naur /home/rgareus/tmp/bea/main.c beatrix/main.c
--- /home/rgareus/tmp/bea/main.c	2004-10-08 01:47:55.000000000 +0200
+++ beatrix/main.c	2007-04-19 23:07:14.000000000 +0200
@@ -55,7 +55,7 @@
 static int  audio_channels_requested = 2;
 static int  audio_splrate;
 static int  audio_splrate_requested = 22050;
-static int  audio_fragsize;
+int  audio_fragsize = 512;
 static int  audio_fragsize_requested = 0x00040009; /* 4 bufs, 2^9=512 bytes */
 static int  audio_profile;
 static int  audio_profile_requested = APF_CPUINTENS;
@@ -80,9 +80,14 @@
  *    2,048   92.88        4,096          8,192
  */
 
-#define BUFFER_SIZE_SAMPLES  128 // 256 // 2048
-#define BUFFER_SIZE_BYTES    256 // 512 // 4096
-#define STEREO_BUFR_BYTES    512 // 1028 // 8192
+//#define BUFFER_SIZE_SAMPLES  128 // 256 // 2048
+//#define BUFFER_SIZE_BYTES    256 // 512 // 4096
+//#define STEREO_BUFR_BYTES    512 // 1028 // 8192
+ 
+// JACK CLIENT - use jack-bufsize <= BUFFER_SIZE_SAMPLES 
+#define BUFFER_SIZE_SAMPLES  2048
+#define BUFFER_SIZE_BYTES    4096
+#define STEREO_BUFR_BYTES    8192
 
 struct _drawbarPreset {
   char * key;
@@ -120,6 +125,100 @@
   }
 }
 
+#define HAVE_JACK
+
+#ifdef HAVE_JACK
+#include <jack/jack.h>
+
+jack_client_t *j_client = NULL;
+jack_port_t **j_output_port; 
+jack_default_audio_sample_t **j_output_bufferptrs; // 
+
+
+/* when jack shuts down... */
+void jack_shutdown_callback(void *arg) {
+  fprintf(stderr,"jack server shut down.\n");
+}
+
+int jack_srate_callback(jack_nframes_t nframes, void *arg) {
+  audio_splrate= (int) nframes;
+  return(0); 
+}
+
+int jack_bufsiz_callback(jack_nframes_t nframes, void *arg) {
+  audio_fragsize= (int) nframes;
+  return(0); 
+}
+
+int jack_audio_callback (jack_nframes_t nframes, void *arg) {
+  jack_default_audio_sample_t **out = j_output_bufferptrs; 
+  int i,s;
+  jack_nframes_t my_tot_latency = 0;
+
+  for (i=0;i<audio_channels;i++) {
+  	jack_nframes_t my_latency = jack_port_get_total_latency(j_client,j_output_port[i]);
+  	if (my_latency > my_tot_latency) my_tot_latency = my_latency;
+  	//printf("DEBUG: c=%i pl=%i tl=%i\n",i,jack_port_get_latency(j_output_port[i]) ,jack_port_get_total_latency(j_client,j_output_port[i]));
+  	out[i] = jack_port_get_buffer (j_output_port[i], nframes);
+  	//memset(out[i],0, sizeof (jack_default_audio_sample_t) * nframes);
+  }
+
+  unsigned char * obuf;
+  oscGenerateFragment (bufA, nframes);
+  obuf = preamp (bufA, bufB, nframes);
+  obuf = reverb (obuf, bufB, nframes);
+  whirlProc (obuf, bufC, nframes);
+
+  for (s=0;s<nframes;s++)
+    for (i=0;i<audio_channels;i++) 
+    //out[i][s]= ((((signed short*)bufB)[s]))/65536.0;
+      out[i][s]= ((((signed short*)bufC)[audio_channels*s+i]))/unitAmplification;
+
+  return(nframes);
+}
+
+int open_jack(void) {
+  int i;
+  i = 0;
+  do {
+    char jackid[16];
+    snprintf(jackid,16,"beatrix-%i",i);
+    j_client = jack_client_new (jackid);
+  } while (j_client == 0 && i++<16);
+
+  if (!j_client) {
+    fprintf(stderr, "could not connect to jack.\n");
+    return(1);
+  }	
+  audio_channels=audio_channels_requested;
+  audio_format = audio_format_requested;
+
+  jack_on_shutdown (j_client, jack_shutdown_callback, NULL);
+  jack_set_process_callback(j_client,jack_audio_callback,NULL);
+  jack_set_sample_rate_callback (j_client, jack_srate_callback, NULL);
+  jack_set_buffer_size_callback (j_client, jack_bufsiz_callback, NULL);
+
+  j_output_port= calloc(audio_channels,sizeof(jack_port_t*));
+  j_output_bufferptrs = calloc(audio_channels,sizeof(jack_default_audio_sample_t*));
+
+  for (i=0;i<audio_channels;i++) {
+    char channelid[16];
+    snprintf(channelid,16,"output-%i",i);
+    j_output_port[i] = jack_port_register (j_client, channelid, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+    if (!j_output_port[i]) {
+      fprintf(stderr, "no more jack ports available.\n");
+      jack_client_close (j_client);
+      return(1);
+    }
+  }
+  jack_srate_callback(jack_get_sample_rate(j_client),NULL); // init j_srate
+  jack_bufsiz_callback(jack_get_buffer_size(j_client),NULL); // init j_bufsiz & alloc
+
+  jack_activate(j_client);
+  return(0);
+}
+#endif
+
 /*
  * This routine initializes the audio driver according to the current
  * configuration parameters.
@@ -127,6 +226,13 @@
 static void initAudio () {
   /* Open the audio hardware. */
 
+#ifdef HAVE_JACK
+  if (open_jack()) {
+    perror ("could not connect to JACK.");
+    exit(1);
+  }
+#else /* NO JACK - OSS */
+
   if ((audio_fd = open (audioDevice, O_WRONLY, 0)) == -1) {
     perror (audioDevice);
     exit (1);
@@ -209,13 +315,15 @@
   fprintf (stderr, "AUDIO FRAGMENT SIZE : %d\n", audio_fragsize);
 #endif /* COMMENT */
 
+#endif /* NO JACK = OSS */
 }
 
 /*
  * Ask each module to initialize itself.
  */
 static void initAll () {
-  fragTimeMs = (1000 * BUFFER_SIZE_SAMPLES) / SampleRateI;
+  //fragTimeMs = (1000 * BUFFER_SIZE_SAMPLES) / SampleRateI;
+  fragTimeMs = (1000 * audio_splrate) / SampleRateI;
 
   fprintf (stderr, "Scanner : ");
   fflush (stderr);
@@ -592,7 +700,9 @@
 #endif /* STATIC_CHORD */
 
     while (TRUE) {
-
+#ifdef HAVE_JACK
+      sleep (1); // jack callback is doing this:
+#else
       oscGenerateFragment (bufA, BUFFER_SIZE_SAMPLES);
 
       obuf = preamp (bufA, bufB, BUFFER_SIZE_SAMPLES);
@@ -627,6 +737,7 @@
 	perror ("write audio_fd bufC");
 	exit (1);
       }
+#endif
     }
   }
 
@@ -634,3 +745,5 @@
 
   return 0;
 }
+
+/* vi:set ts=8 sts=2 sw=2: */
diff -Naur /home/rgareus/tmp/bea/midi.c beatrix/midi.c
--- /home/rgareus/tmp/bea/midi.c	2004-10-01 01:06:40.000000000 +0200
+++ beatrix/midi.c	2007-04-19 22:49:10.000000000 +0200
@@ -176,7 +176,7 @@
 static unsigned char byte3;
 
 static int midi_fd;	     /* File descriptor for the MIDI device */
-static char * midiDevice = "/dev/midi00"; /* Default path to MIDI device */
+static char * midiDevice = "/dev/sound/midi1"; /* Default path to MIDI device */
 static char midiDeviceBuffer[PATH_MAX + 1]; /* Actual path to MIDI device */
 
 static unsigned char rcvChA = 0; /* MIDI receive channel */
diff -Naur /home/rgareus/tmp/bea/tonegen.c beatrix/tonegen.c
--- /home/rgareus/tmp/bea/tonegen.c	2004-11-25 23:40:21.000000000 +0100
+++ beatrix/tonegen.c	2007-04-19 23:09:22.000000000 +0200
@@ -228,8 +228,9 @@
 #define isOsc(O) ((0 <= (O)) && ((O) < 128))
 
 #ifndef BUFFER_SIZE_SAMPLES
-#define BUFFER_SIZE_SAMPLES 128
+#define BUFFER_SIZE_SAMPLES 512
 #endif
+extern int  audio_fragsize;
 
 /*
  * List element definition for the distribution network specification.
@@ -2486,7 +2487,7 @@
 static void setEnvAtkClkLength (int * p, double u) {
   if (p != NULL) {
     if ((0.0 <= u) && (u <= 1.0)) {
-      *p = (int) (((double) BUFFER_SIZE_SAMPLES) * u);
+      *p = (int) (((double) audio_fragsize) * u);
     }
   }
 }
@@ -3200,8 +3201,8 @@
  * This routine initialises the envelope shape tables.
  */
 static void initEnvelopes () {
-  int bss = BUFFER_SIZE_SAMPLES;
-  int bs2 = BUFFER_SIZE_SAMPLES / 2;
+  int bss = audio_fragsize;
+  int bs2 = audio_fragsize / 2;
   int pattern = 2;
   int b;
   int i;			/* 0 -- 127 */
@@ -3209,7 +3210,7 @@
   int burst;			/* Samples in noist burst */
   int bound;
   int start;			/* Sample where burst starts */
-  double T = (double) (BUFFER_SIZE_SAMPLES - 1); /* 127.0 */
+  double T = (double) (audio_fragsize - 1); /* 127.0 */
 
   for (b = 0; b < 9; b++) {
 
@@ -3293,24 +3294,24 @@
     /* cos(0)=1.0, cos(PI/2)=0, cos(PI)=-1.0 */
 
     if (envAttackModel == ENV_COSINE) {	/* Sigmoid decay */
-      for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
-	int d = BUFFER_SIZE_SAMPLES - (i + 1);
+      for (i = 0; i < audio_fragsize; i++) {
+	int d = audio_fragsize - (i + 1);
 	double a = (M_PI * (double) d) / T;	/* PI < a <= 0 */
 	attackEnv [b][i] = 0.5 + (0.5 * cos (a));
       }
     }
 
     if (envReleaseModel == ENV_COSINE) {
-      for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
+      for (i = 0; i < audio_fragsize; i++) {
 	double a = (M_PI * (double) i) / T;	/* 0 < b <= PI */
 	releaseEnv[b][i] = 0.5 - (0.5 * cos (a));
       }
     }
 
     if (envAttackModel == ENV_LINEAR) {	/* Linear decay */
-      int k = BUFFER_SIZE_SAMPLES;			/* TEST SPECIAL */
+      int k = audio_fragsize;			/* TEST SPECIAL */
 
-      for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
+      for (i = 0; i < audio_fragsize; i++) {
 	if (i < k) {
 	  attackEnv[b][i]  = ((float) i) / (float) k;
 	} else {
@@ -3320,9 +3321,9 @@
     }
 
     if (envReleaseModel == ENV_LINEAR) {
-      int k = BUFFER_SIZE_SAMPLES;			/* TEST SPECIAL */
+      int k = audio_fragsize;			/* TEST SPECIAL */
 
-      for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
+      for (i = 0; i < audio_fragsize; i++) {
 	if (i < k) {
 	  releaseEnv[b][i] = ((float) i) / (float) k;
 	} else {
@@ -3809,7 +3810,7 @@
 
 #ifdef KEYCOMPRESSION
 
-  keyCompDelta = (keyComp - keyCompLevel) / (float) BUFFER_SIZE_SAMPLES;
+  keyCompDelta = (keyComp - keyCompLevel) / (float) audio_fragsize;
 
 #endif /* KEYCOMPRESSION */
 
@@ -3926,11 +3927,11 @@
       /* Target gain is zero */
       coreWriter->nsgain = coreWriter->npgain = coreWriter->nvgain = 0.0;
 
-      if (osp->lengthSamples < (osp->pos + BUFFER_SIZE_SAMPLES)) {
+      if (osp->lengthSamples < (osp->pos + audio_fragsize)) {
 	/* Need another instruction because of wrap */
 	CoreIns * prev = coreWriter;
 	coreWriter->cnt = osp->lengthSamples - osp->pos;
-	osp->pos = BUFFER_SIZE_SAMPLES - coreWriter->cnt;
+	osp->pos = audio_fragsize - coreWriter->cnt;
 	coreWriter += 1;
 	coreWriter->opr = prev->opr;
 	coreWriter->src = osp->wave;
@@ -3948,8 +3949,8 @@
 	coreWriter->cnt = osp->pos;
       }
       else {
-	coreWriter->cnt = BUFFER_SIZE_SAMPLES;
-	osp->pos += BUFFER_SIZE_SAMPLES;
+	coreWriter->cnt = audio_fragsize;
+	osp->pos += audio_fragsize;
       }
 
       coreWriter += 1;
@@ -4054,11 +4055,11 @@
       coreWriter->off = 0;
 
 
-      if (osp->lengthSamples < (osp->pos + BUFFER_SIZE_SAMPLES)) {
+      if (osp->lengthSamples < (osp->pos + audio_fragsize)) {
 	/* Instruction wraps source buffer */
 	CoreIns * prev = coreWriter; /* Refer to the first instruction */
 	coreWriter->cnt = osp->lengthSamples - osp->pos; /* Set len count */
-	osp->pos = BUFFER_SIZE_SAMPLES - coreWriter->cnt; /* Updat src pos */
+	osp->pos = audio_fragsize - coreWriter->cnt; /* Updat src pos */
 	
 	coreWriter += 1;	/* Advance to next instruction */
 
@@ -4080,8 +4081,8 @@
 	coreWriter->cnt = osp->pos; /* Up to next read position */
       }
       else {
-	coreWriter->cnt = BUFFER_SIZE_SAMPLES;
-	osp->pos += BUFFER_SIZE_SAMPLES;
+	coreWriter->cnt = audio_fragsize;
+	osp->pos += audio_fragsize;
       }
 
       coreWriter += 1;	/* Advance to next instruction */
@@ -4137,7 +4138,7 @@
     float * yv = vibBuffer;
     float * yp = prcBuffer;
 
-    for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
+    for (i = 0; i < audio_fragsize; i++) {
       *ys++ = 0.0;
       *yv++ = 0.0;
       *yp++ = 0.0;
@@ -4218,7 +4219,7 @@
 
     (void) vibratoProc ((unsigned char *) vibBuffer,
 			(unsigned char *) vibYBuffr,
-			BUFFER_SIZE_SAMPLES);
+			audio_fragsize);
 
   }
 
@@ -4237,10 +4238,10 @@
 
     if (oldRouting & RT_PERC) {	/* If percussion is on */
 #ifdef HIPASS_PERCUSSION
-      float * tp = &(prcBuffer[BUFFER_SIZE_SAMPLES - 1]);
+      float * tp = &(prcBuffer[audio_fragsize - 1]);
       float temp = *tp;
       pp = tp - 1;
-      for (i = 1; i < BUFFER_SIZE_SAMPLES; i++) {
+      for (i = 1; i < audio_fragsize; i++) {
 	*tp = *pp - *tp;
 	tp--;
 	pp--;
@@ -4251,7 +4252,7 @@
 #endif /* HIPASS_PERCUSSION */
       outputGain = swellPedalGain * percDrawbarGain;
       if (oldRouting & RT_VIB) { /* If vibrato is on */
-	for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) { /* Perc and vibrato */
+	for (i = 0; i < audio_fragsize; i++) { /* Perc and vibrato */
 	  *yptr++ = (short) 
 	    (outputGain * keyCompLevel *
 	     ((*xp++) + (*vp++) + ((*pp++) * percEnvGain)));
@@ -4259,7 +4260,7 @@
 	  KEYCOMPCHASE();
 	}
       } else {			/* Percussion only */
-	for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
+	for (i = 0; i < audio_fragsize; i++) {
 	  *yptr++ = (short) 
 	    (outputGain * keyCompLevel * ((*xp++) + ((*pp++) * percEnvGain)));
 	  percEnvGain *= percEnvGainDecay;
@@ -4269,13 +4270,13 @@
 
     } else if (oldRouting & RT_VIB) { /* No percussion and vibrato */
 
-      for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
+      for (i = 0; i < audio_fragsize; i++) {
 	*yptr++ = (short)
 	  (swellPedalGain * keyCompLevel * ((*xp++) + (*vp++)));
 	KEYCOMPCHASE();
       }
     } else {			/* No percussion and no vibrato */
-      for (i = 0; i < BUFFER_SIZE_SAMPLES; i++) {
+      for (i = 0; i < audio_fragsize; i++) {
 	*yptr++ = (short)
 	  (swellPedalGain * keyCompLevel * (*xp++));
 	KEYCOMPCHASE();
