classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: dssi/alsa JNI cleanup


From: Anthony Green
Subject: [cp-patches] Patch: dssi/alsa JNI cleanup
Date: Tue, 04 Oct 2005 05:22:33 -0700

I'm checking in the following cleanup patch to my DSSI and ALSA JNI
code.  

It removes debug output, reformats some code and adds comments.

AG


2005-10-04  Anthony Green  <address@hidden>

        * native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c 
        (process): Add comments.  Remove unused gettimeofday call.
        (Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_open_1): Remove
        debug output.  Add comments.
        (Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOn_1,
        Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOff_1): Add
        comments.  Remove bogus __attribute__((unused)).
        * native/jni/midi-dssi/dssi_data.h (JLONG_TO_PTR, PTR_TO_JLONG): 
        Document helper macros.
        (dssi_data): Document.
        * 
native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c:
        Formatting fixes.
        * native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c
        (Java_gnu_javax_sound_midi_alsa_AlsaPortDevice_run_1receiver_1thread_1):
        Remove debugging output.


Index: native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c,v
retrieving revision 1.1
diff -u -r1.1 gnu_javax_sound_midi_alsa_AlsaPortDevice.c
--- native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c     3 Oct 
2005 01:53:12 -0000       1.1
+++ native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c     4 Oct 
2005 12:15:47 -0000
@@ -59,7 +59,6 @@
   snd_seq_port_subscribe_alloca (&subs);
 
   rc = snd_seq_open (&seq, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK);
-  puts (snd_strerror(rc));
 
   snd_seq_port_info_set_capability (pinfo, SND_SEQ_PORT_CAP_WRITE);
   snd_seq_port_info_set_type (pinfo, SND_SEQ_PORT_TYPE_MIDI_GENERIC);
Index: native/jni/midi-dssi/dssi_data.h
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/midi-dssi/dssi_data.h,v
retrieving revision 1.1
diff -u -r1.1 dssi_data.h
--- native/jni/midi-dssi/dssi_data.h    3 Oct 2005 01:53:12 -0000       1.1
+++ native/jni/midi-dssi/dssi_data.h    4 Oct 2005 12:15:47 -0000
@@ -50,24 +50,55 @@
 #include "target_native_misc.h"
 #include "../classpath/jcl.h"
 
+/* Specify the size of the circular buffer.  It only needs to be big
+   enough to hold the events that happen between jack callbacks (~
+   1/40th of a second).  */
 #define EVENT_BUFFER_SIZE 1024
 
+/* Helper macros for going between pointers and jlongs.  */
 #define JLONG_TO_PTR(T,P) ((T *)(long)P)
 #define PTR_TO_JLONG(P) ((jlong)(long)P)
 
+
+/* Every DSSI Synthesizer has one of these associated with it.  The
+   Java class sees it as a "long" handle.  */
+
 typedef struct
 {
+  /* This is a handle to the dlopen'ed .so file containing the DSSI
+     synthesizer.  */
   void *dlhandle;
+
+  /* The function to call to get the DSS_Descriptor.  */
   DSSI_Descriptor_Function fn;
+
+  /* The descriptor for this synthesizer.  See the dssi.h system
+     header.  */
   const DSSI_Descriptor *desc;
+
+  /* We currently open a jack client connection for every
+     synthesizer.  */
   jack_client_t *jack_client;
+
+  /* We currently only handle stereo jack connections.  Output from
+     mono synthesizers is sent to both left and right ports.  */
   jack_port_t *jack_left_output_port;
   jack_port_t *jack_right_output_port;
+
+  /* We use a circular buffer to hold MIDI events before processing
+     them in the jack audio processing callback function.  */
   snd_seq_event_t midiEventBuffer[EVENT_BUFFER_SIZE];
   int midiEventReadIndex; 
   int midiEventWriteIndex;
+
+  /* This is a handle the synthesizers underlying LADSPA structure.
+     See the ladspa.h system header for details.  */
   LADSPA_Handle plugin_handle;
+
+  /* These are buffers we pass to the DSSI Synthesizer for
+     filling.  */
   float *left_buffer;
   float *right_buffer;
+
 } dssi_data;
 
Index: native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c,v
retrieving revision 1.1
diff -u -r1.1 gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c
--- native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c     
3 Oct 2005 01:53:12 -0000       1.1
+++ native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c     
4 Oct 2005 12:15:47 -0000
@@ -41,7 +41,8 @@
 #include "dssi_data.h"
 
 void
-Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_dlclose_1 (JNIEnv *env, 
jclass clazz __attribute__((unused)), jlong sohandle)
+Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_dlclose_1 
+  (JNIEnv *env, jclass clazz __attribute__((unused)), jlong sohandle)
 {
   dssi_data *data = (dssi_data *) (long) sohandle;
   dlclose (data->dlhandle);
@@ -49,7 +50,8 @@
 }
 
 jlong
-Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_dlopen_1 (JNIEnv *env, 
jclass clazz __attribute__((unused)), jstring name)
+Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_dlopen_1 
+  (JNIEnv *env, jclass clazz __attribute__((unused)), jstring name)
 {
   const char *filename;
   void *handle;
@@ -58,9 +60,7 @@
   
   filename = JCL_jstring_to_cstring (env, name);
   if (filename == NULL)
-    {
-      return (0);
-    }
+    return (0);
   
   handle = dlopen(filename, RTLD_NOW);
   
@@ -87,7 +87,9 @@
 }
 
 jlong
-Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIHandle_1 (JNIEnv 
*env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong 
handle, jlong index)
+Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIHandle_1 
+  (JNIEnv *env __attribute__((unused)), 
+   jclass clazz __attribute__((unused)), jlong handle, jlong index)
 { 
   dssi_data *data = JLONG_TO_PTR(dssi_data,handle);
   data->desc = (data->fn)(index);
@@ -95,7 +97,8 @@
 }
 
 jstring
-Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIName_1 (JNIEnv 
*env, jclass clazz __attribute__((unused)), jlong handle)
+Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIName_1 
+  (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle)
 {
   DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle);
   const char *str = desc->LADSPA_Plugin->Name;
@@ -104,7 +107,8 @@
 } 
 
 jstring
-Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSICopyright_1 
(JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle)
+Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSICopyright_1 
+  (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle)
 {
   DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle);
   const char *str = desc->LADSPA_Plugin->Copyright;
@@ -113,7 +117,8 @@
 } 
 
 jstring
-Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIVendor_1 (JNIEnv 
*env, jclass clazz __attribute__((unused)), jlong handle)
+Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIVendor_1 
+  (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle)
 {
   DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle);
   const char *str = desc->LADSPA_Plugin->Maker;
@@ -122,7 +127,8 @@
 }
 
 jstring
-Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSILabel_1 (JNIEnv 
*env, jclass clazz __attribute__((unused)), jlong handle)
+Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSILabel_1 
+  (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle)
 {
   DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle);
   const char *str = desc->LADSPA_Plugin->Label;
Index: native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c,v
retrieving revision 1.1
diff -u -r1.1 gnu_javax_sound_midi_dssi_DSSISynthesizer.c
--- native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c    3 Oct 
2005 01:53:12 -0000       1.1
+++ native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c    4 Oct 
2005 12:15:47 -0000
@@ -40,6 +40,13 @@
 
 #include "dssi_data.h"
 
+/**
+ * The jack callback routine.
+ *
+ * This function is called by the jack audio system in its own thread
+ * whenever it needs new audio data.
+ *
+ */
 static int
 process (jack_nframes_t nframes, void *arg)
 {    
@@ -48,20 +55,27 @@
   int index;
   jack_default_audio_sample_t *buffer;
 
-  gettimeofday(&tv, NULL);
-
   /* Look through the event buffer to see if anything needs doing.  */
   for ( index = data->midiEventReadIndex; 
        index != data->midiEventWriteIndex;
        index = (index + 1) % EVENT_BUFFER_SIZE);
 
+  /* Call the synth audio processing routine.  */
   data->desc->run_synth(data->plugin_handle,
                        nframes,
                        &data->midiEventBuffer[data->midiEventReadIndex],
                        data->midiEventWriteIndex - data->midiEventReadIndex);
 
+  /* Update the read index on our circular buffer.  */
   data->midiEventReadIndex = data->midiEventWriteIndex;
 
+  /* Copy output from the synth to jack.  
+
+     FIXME: This is hack that only gets one channel from the synth and
+     send that to both jack ports (until we handle stero synths
+     properly).
+
+     FIXME: Can we avoid this copying?  */
   buffer = jack_port_get_buffer(data->jack_left_output_port, nframes);
   memcpy (buffer, data->left_buffer, nframes * sizeof(LADSPA_Data));
   buffer = jack_port_get_buffer(data->jack_right_output_port, nframes);
@@ -73,8 +87,15 @@
 /* FIXME: Temporary hack.  */
 float mctrl = 0.9f;
 
+/**
+ * Open a new synthesizer.  This currently involves instantiating a
+ * new synth, creating a new jack client connection, and activating
+ * both.
+ *
+ */
 JNIEXPORT void JNICALL
-Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_open_1 (JNIEnv *env, jclass 
clazz __attribute__((unused)), jlong handle)
+Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_open_1 
+  (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle)
 {
   unsigned int port_count, j;
   dssi_data *data = (dssi_data *) (long) handle;
@@ -89,8 +110,6 @@
   data->plugin_handle = 
(data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, 
                                                                 
jack_get_sample_rate (data->jack_client));
   
-  printf ("open() plugin_handle = 0x%x\n", data->plugin_handle);
-
   if (jack_set_process_callback (data->jack_client, process, data) != 0)
     {
       JCL_ThrowException (env, "java/io/IOException", 
@@ -122,11 +141,13 @@
     {  
       LADSPA_PortDescriptor pod =
        data->desc->LADSPA_Plugin->PortDescriptors[j];
-      
       if (LADSPA_IS_PORT_AUDIO(pod) && LADSPA_IS_PORT_OUTPUT(pod))
        {
-         data->left_buffer = (float *) 
calloc(jack_get_buffer_size(data->jack_client), sizeof(float));
-         (data->desc->LADSPA_Plugin->connect_port)(data->plugin_handle, j, 
data->left_buffer);
+         data->left_buffer = 
+           (float *) calloc(jack_get_buffer_size(data->jack_client), 
+                            sizeof(float));
+         (data->desc->LADSPA_Plugin->connect_port)(data->plugin_handle, j, 
+                                                   data->left_buffer);
        }
       else 
        if (LADSPA_IS_PORT_CONTROL(pod) && LADSPA_IS_PORT_INPUT(pod))
@@ -143,8 +164,15 @@
                        "can't activate jack client"); 
 }
 
+/**
+ * This is called when we receive a new MIDI NOTE ON message.  Simply
+ * stick an appropriate event in the event buffer.  This will get
+ * processed in the jack callback function.
+ */
 JNIEXPORT void JNICALL 
-Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOn_1 (JNIEnv *env 
__attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle 
__attribute__((unused)), jint channel __attribute__((unused)), jint note 
__attribute__((unused)), jint velocity __attribute__((unused)))
+Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOn_1 
+  (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), 
+   jlong handle, jint channel, jint note, jint velocity)
 {
   dssi_data *data = (dssi_data *) (long) handle;
 
@@ -155,12 +183,21 @@
   ev->data.control.channel = channel;
   ev->data.note.note = note;
   ev->data.note.velocity = velocity;
-  
-  data->midiEventWriteIndex = (data->midiEventWriteIndex + 1) % 
EVENT_BUFFER_SIZE;
+
+  data->midiEventWriteIndex = 
+    (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;
 }
 
+/**
+ * This is called when we receive a new MIDI NOTE OFF message.  Simply
+ * stick an appropriate event in the event buffer.  This will get
+ * processed in the jack callback function.
+ */
 JNIEXPORT void JNICALL 
-Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOff_1 (JNIEnv *env 
__attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle 
__attribute__((unused)), jint channel __attribute__((unused)), jint note 
__attribute__((unused)), jint velocity __attribute__((unused)))
+Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOff_1 
+  (JNIEnv *env __attribute__((unused)), 
+   jclass clazz __attribute__((unused)), 
+   jlong handle, jint channel, jint note, jint velocity)
 {
   dssi_data *data = (dssi_data *) (long) handle;
 
@@ -171,23 +208,32 @@
   ev->data.control.channel = channel;
   ev->data.note.note = note;
   ev->data.note.velocity = velocity;
-  
-  data->midiEventWriteIndex = (data->midiEventWriteIndex + 1) % 
EVENT_BUFFER_SIZE;
+
+  data->midiEventWriteIndex = 
+    (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;
 }
 
 JNIEXPORT void JNICALL 
-Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_setPolyPressure_1 (JNIEnv *env 
__attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle 
__attribute__((unused)), jint channel __attribute__((unused)), jint note 
__attribute__((unused)), jint velocity __attribute__((unused)))
+Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_setPolyPressure_1 
+  (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), 
+   jlong handle __attribute__((unused)), jint channel __attribute__((unused)), 
+   jint note __attribute__((unused)), jint velocity __attribute__((unused)))
 {
 }
 
 JNIEXPORT jint JNICALL 
-Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getPolyPressure_1 (JNIEnv *env 
__attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle 
__attribute__((unused)), jint channel __attribute__((unused)), jint note 
__attribute__((unused)))
+Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getPolyPressure_1 
+  (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), 
+   jlong handle __attribute__((unused)), jint channel __attribute__((unused)), 
+   jint note __attribute__((unused)))
 {
   return 0;
 }
 
 JNIEXPORT void JNICALL 
-Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_close_1 (JNIEnv *env 
__attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle 
__attribute__((unused)))
+Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_close_1 
+  (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), 
+   jlong handle __attribute__((unused)))
 {
 }
 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]