⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnu_javax_sound_midi_dssi_dssisynthesizer.c

📁 gcc的组建
💻 C
📖 第 1 页 / 共 2 页
字号:
/* gnu_javax_sound_midi_dssi_DSSISynthesizer.c - DSSI Synth   Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. *//* The original get_port_default() and set_control() routines were * copied from the DSSI source distribution and are covered by the * following copyright and license... * * Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton. *  * Permission to use, copy, modify, distribute, and sell this software * for any purpose is hereby granted without fee, provided that the * above copyright notice and this permission notice are included in * all copies or substantial portions of the software. */#include <config.h>#include <gnu_javax_sound_midi_dssi_DSSISynthesizer.h> #include <math.h>#include "dssi_data.h"/* Define this for debug output.  */#undef DEBUG_DSSI_PROVIDERstatic void set_control (dssi_data *data, snd_seq_event_t *event);/** * The jack callback routine. * * This function is called by the jack audio system in its own thread * whenever it needs new audio data. * */static intprocess (jack_nframes_t nframes, void *arg){      dssi_data *data = (dssi_data *) arg;  int index;  jack_default_audio_sample_t *buffer;  /* Look through the event buffer to see if any control values     need changing.  */  for ( index = data->midiEventReadIndex; 	index != data->midiEventWriteIndex;	index = (index + 1) % EVENT_BUFFER_SIZE)    {      if (data->midiEventBuffer[index].type == SND_SEQ_EVENT_CONTROLLER)	set_control (data, & data->midiEventBuffer[index]);    }  if (data->desc->run_synth)    {      /* Call the synth audio processing routine.  */      data->desc->run_synth	(data->plugin_handle,	 nframes,	 &data->midiEventBuffer[data->midiEventReadIndex],	 data->midiEventWriteIndex - data->midiEventReadIndex);    }  else     if (data->desc->run_multiple_synths)      {	snd_seq_event_t *events = 	  &data->midiEventBuffer[data->midiEventReadIndex];	unsigned long event_count = 	  data->midiEventWriteIndex - data->midiEventReadIndex;	/* Call the synth audio processing routine.  */	data->desc->run_multiple_synths	  (1,	   & (data->plugin_handle),	   nframes,	   &events,	   &event_count);      }  /* 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);  memcpy (buffer, data->left_buffer, nframes * sizeof(LADSPA_Data));  return 0;   }/** * Calculate a reasonable default value for a specific control port. * This is mostly copied from the DSSI example code.  Copyright info * is found at the top of this file. * */static LADSPA_Data get_port_default (const LADSPA_Descriptor *plugin, 		  int port, jack_nframes_t sample_rate){  LADSPA_PortRangeHint hint = plugin->PortRangeHints[port];  float lower = hint.LowerBound *    (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f);  float upper = hint.UpperBound *    (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f);    if (!LADSPA_IS_HINT_HAS_DEFAULT(hint.HintDescriptor))     {      if (!LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) ||	  !LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) 	{	  /* No hint, its not bounded, wild guess */	  return 0.0f;	}          if (lower <= 0.0f && upper >= 0.0f) 	{	  /* It spans 0.0, 0.0 is often a good guess */	  return 0.0f;	}          /* No clues, return minimum */      return lower;    }    /* Try all the easy ones */    if (LADSPA_IS_HINT_DEFAULT_0(hint.HintDescriptor))    return 0.0f;  else if (LADSPA_IS_HINT_DEFAULT_1(hint.HintDescriptor))     return 1.0f;  else if (LADSPA_IS_HINT_DEFAULT_100(hint.HintDescriptor))     return 100.0f;  else if (LADSPA_IS_HINT_DEFAULT_440(hint.HintDescriptor))     return 440.0f;     /* All the others require some bounds */    if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)      && (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint.HintDescriptor)))    return lower;  if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor))    {      if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint.HintDescriptor))	return upper;      if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) 	{	  if (LADSPA_IS_HINT_DEFAULT_LOW(hint.HintDescriptor)) 	    return lower * 0.75f + upper * 0.25f;	  else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint.HintDescriptor)) 	    return lower * 0.5f + upper * 0.5f;	  else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint.HintDescriptor)) 	    return lower * 0.25f + upper * 0.75f;	}    }    /* fallback */  return 0.0f;}/** * Set a control value by mapping the MIDI event to a suitable value * for this control. * This is mostly copied from the DSSI example code.  Copyright info * is found at the top of this file. * */static voidset_control(dssi_data *data, snd_seq_event_t *event){  unsigned control = event->data.control.param;  unsigned port = data->control_port_map[control];  const LADSPA_Descriptor *p = data->desc->LADSPA_Plugin;  LADSPA_PortRangeHintDescriptor d = p->PortRangeHints[port].HintDescriptor;  LADSPA_Data lb = p->PortRangeHints[port].LowerBound *    (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?     data->sample_rate : 1.0f);    LADSPA_Data ub = p->PortRangeHints[port].UpperBound *    (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?     data->sample_rate : 1.0f);    float value = (float)event->data.control.value;    if (!LADSPA_IS_HINT_BOUNDED_BELOW(d))     {      if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) 	{	  /* unbounded: might as well leave the value alone. */	}       else 	{	  /* bounded above only. just shift the range. */	  value = ub - 127.0f + value;	}    }   else     {      if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) 	{	  /* bounded below only. just shift the range. */	  value = lb + value;	}       else 	{	  /* bounded both ends.  more interesting. */	  if (LADSPA_IS_HINT_LOGARITHMIC(d)) 	    {	      const float llb = logf(lb);	      const float lub = logf(ub);	      	      value = expf(llb + ((lub - llb) * value / 127.0f));	    } 	  else 	    {	      value = lb + ((ub - lb) * value / 127.0f);	    }	}    }  #ifdef DEBUG_DSSI_PROVIDER  printf("MIDI controller %d=%d -> control in %u=%f\n", 	 event->data.control.param,	 event->data.control.value, 	 data->control_value_map[control], value);#endif    data->control_values[data->control_value_map[control]] = value;}/** * Open a new synthesizer.  This currently involves instantiating a * new synth, creating a new jack client connection, and activating * both. * */JNIEXPORT void JNICALLJava_gnu_javax_sound_midi_dssi_DSSISynthesizer_open_1   (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle){  unsigned int port_count, j, cindex;  const char **ports;  int controller = 0;  dssi_data *data = (dssi_data *) (long) handle;  if ((data->jack_client = jack_client_new (data->desc->LADSPA_Plugin->Label)) == 0)    {      /*	JCL_ThrowException (env, "javax/sound/midi/MidiUnavailableException",   */      JCL_ThrowException (env, "java/io/IOException", 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -