/[classpath]/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c
ViewVC logotype

Diff of /classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by green, Mon Oct 3 01:53:12 2005 UTC revision 1.2 by green, Tue Oct 4 12:24:08 2005 UTC
# Line 40  exception statement from your version. * Line 40  exception statement from your version. *
40    
41  #include "dssi_data.h"  #include "dssi_data.h"
42    
43    /**
44     * The jack callback routine.
45     *
46     * This function is called by the jack audio system in its own thread
47     * whenever it needs new audio data.
48     *
49     */
50  static int  static int
51  process (jack_nframes_t nframes, void *arg)  process (jack_nframes_t nframes, void *arg)
52  {      {    
# Line 48  process (jack_nframes_t nframes, void *a Line 55  process (jack_nframes_t nframes, void *a
55    int index;    int index;
56    jack_default_audio_sample_t *buffer;    jack_default_audio_sample_t *buffer;
57    
   gettimeofday(&tv, NULL);  
   
58    /* Look through the event buffer to see if anything needs doing.  */    /* Look through the event buffer to see if anything needs doing.  */
59    for ( index = data->midiEventReadIndex;    for ( index = data->midiEventReadIndex;
60          index != data->midiEventWriteIndex;          index != data->midiEventWriteIndex;
61          index = (index + 1) % EVENT_BUFFER_SIZE);          index = (index + 1) % EVENT_BUFFER_SIZE);
62    
63      /* Call the synth audio processing routine.  */
64    data->desc->run_synth(data->plugin_handle,    data->desc->run_synth(data->plugin_handle,
65                          nframes,                          nframes,
66                          &data->midiEventBuffer[data->midiEventReadIndex],                          &data->midiEventBuffer[data->midiEventReadIndex],
67                          data->midiEventWriteIndex - data->midiEventReadIndex);                          data->midiEventWriteIndex - data->midiEventReadIndex);
68    
69      /* Update the read index on our circular buffer.  */
70    data->midiEventReadIndex = data->midiEventWriteIndex;    data->midiEventReadIndex = data->midiEventWriteIndex;
71    
72      /* Copy output from the synth to jack.  
73    
74         FIXME: This is hack that only gets one channel from the synth and
75         send that to both jack ports (until we handle stero synths
76         properly).
77    
78         FIXME: Can we avoid this copying?  */
79    buffer = jack_port_get_buffer(data->jack_left_output_port, nframes);    buffer = jack_port_get_buffer(data->jack_left_output_port, nframes);
80    memcpy (buffer, data->left_buffer, nframes * sizeof(LADSPA_Data));    memcpy (buffer, data->left_buffer, nframes * sizeof(LADSPA_Data));
81    buffer = jack_port_get_buffer(data->jack_right_output_port, nframes);    buffer = jack_port_get_buffer(data->jack_right_output_port, nframes);
# Line 73  process (jack_nframes_t nframes, void *a Line 87  process (jack_nframes_t nframes, void *a
87  /* FIXME: Temporary hack.  */  /* FIXME: Temporary hack.  */
88  float mctrl = 0.9f;  float mctrl = 0.9f;
89    
90    /**
91     * Open a new synthesizer.  This currently involves instantiating a
92     * new synth, creating a new jack client connection, and activating
93     * both.
94     *
95     */
96  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
97  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
98      (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle)
99  {  {
100    unsigned int port_count, j;    unsigned int port_count, j;
101    dssi_data *data = (dssi_data *) (long) handle;    dssi_data *data = (dssi_data *) (long) handle;
# Line 89  Java_gnu_javax_sound_midi_dssi_DSSISynth Line 110  Java_gnu_javax_sound_midi_dssi_DSSISynth
110    data->plugin_handle = (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin,    data->plugin_handle = (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin,
111                                                                   jack_get_sample_rate (data->jack_client));                                                                   jack_get_sample_rate (data->jack_client));
112        
   printf ("open() plugin_handle = 0x%x\n", data->plugin_handle);  
   
113    if (jack_set_process_callback (data->jack_client, process, data) != 0)    if (jack_set_process_callback (data->jack_client, process, data) != 0)
114      {      {
115        JCL_ThrowException (env, "java/io/IOException",        JCL_ThrowException (env, "java/io/IOException",
# Line 122  Java_gnu_javax_sound_midi_dssi_DSSISynth Line 141  Java_gnu_javax_sound_midi_dssi_DSSISynth
141      {        {  
142        LADSPA_PortDescriptor pod =        LADSPA_PortDescriptor pod =
143          data->desc->LADSPA_Plugin->PortDescriptors[j];          data->desc->LADSPA_Plugin->PortDescriptors[j];
         
144        if (LADSPA_IS_PORT_AUDIO(pod) && LADSPA_IS_PORT_OUTPUT(pod))        if (LADSPA_IS_PORT_AUDIO(pod) && LADSPA_IS_PORT_OUTPUT(pod))
145          {          {
146            data->left_buffer = (float *) calloc(jack_get_buffer_size(data->jack_client), sizeof(float));            data->left_buffer =
147            (data->desc->LADSPA_Plugin->connect_port)(data->plugin_handle, j, data->left_buffer);              (float *) calloc(jack_get_buffer_size(data->jack_client),
148                                 sizeof(float));
149              (data->desc->LADSPA_Plugin->connect_port)(data->plugin_handle, j,
150                                                        data->left_buffer);
151          }          }
152        else        else
153          if (LADSPA_IS_PORT_CONTROL(pod) && LADSPA_IS_PORT_INPUT(pod))          if (LADSPA_IS_PORT_CONTROL(pod) && LADSPA_IS_PORT_INPUT(pod))
# Line 143  Java_gnu_javax_sound_midi_dssi_DSSISynth Line 164  Java_gnu_javax_sound_midi_dssi_DSSISynth
164                          "can't activate jack client");                          "can't activate jack client");
165  }  }
166    
167    /**
168     * This is called when we receive a new MIDI NOTE ON message.  Simply
169     * stick an appropriate event in the event buffer.  This will get
170     * processed in the jack callback function.
171     */
172  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
173  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
174      (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)),
175       jlong handle, jint channel, jint note, jint velocity)
176  {  {
177    dssi_data *data = (dssi_data *) (long) handle;    dssi_data *data = (dssi_data *) (long) handle;
178    
# Line 155  Java_gnu_javax_sound_midi_dssi_DSSISynth Line 183  Java_gnu_javax_sound_midi_dssi_DSSISynth
183    ev->data.control.channel = channel;    ev->data.control.channel = channel;
184    ev->data.note.note = note;    ev->data.note.note = note;
185    ev->data.note.velocity = velocity;    ev->data.note.velocity = velocity;
186      
187    data->midiEventWriteIndex = (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;    data->midiEventWriteIndex =
188        (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;
189  }  }
190    
191    /**
192     * This is called when we receive a new MIDI NOTE OFF message.  Simply
193     * stick an appropriate event in the event buffer.  This will get
194     * processed in the jack callback function.
195     */
196  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
197  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
198      (JNIEnv *env __attribute__((unused)),
199       jclass clazz __attribute__((unused)),
200       jlong handle, jint channel, jint note, jint velocity)
201  {  {
202    dssi_data *data = (dssi_data *) (long) handle;    dssi_data *data = (dssi_data *) (long) handle;
203    
# Line 171  Java_gnu_javax_sound_midi_dssi_DSSISynth Line 208  Java_gnu_javax_sound_midi_dssi_DSSISynth
208    ev->data.control.channel = channel;    ev->data.control.channel = channel;
209    ev->data.note.note = note;    ev->data.note.note = note;
210    ev->data.note.velocity = velocity;    ev->data.note.velocity = velocity;
211      
212    data->midiEventWriteIndex = (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;    data->midiEventWriteIndex =
213        (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;
214  }  }
215    
216  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
217  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
218      (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)),
219       jlong handle __attribute__((unused)), jint channel __attribute__((unused)),
220       jint note __attribute__((unused)), jint velocity __attribute__((unused)))
221  {  {
222  }  }
223    
224  JNIEXPORT jint JNICALL  JNIEXPORT jint JNICALL
225  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
226      (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)),
227       jlong handle __attribute__((unused)), jint channel __attribute__((unused)),
228       jint note __attribute__((unused)))
229  {  {
230    return 0;    return 0;
231  }  }
232    
233  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
234  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
235      (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)),
236       jlong handle __attribute__((unused)))
237  {  {
238  }  }
239    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26