[08fda7]: extra / fluidsynth-1.0.5-dssi_patch Maximize Restore History

Download this file

fluidsynth-1.0.5-dssi_patch    371 lines (331 with data), 12.9 kB

diff -ur fluidsynth-1.0.5/include/fluidsynth/synth.h fluidsynth-1.0.5-patched/include/fluidsynth/synth.h
--- fluidsynth-1.0.5/include/fluidsynth/synth.h	2004-08-18 07:33:21.000000000 -0700
+++ fluidsynth-1.0.5-patched/include/fluidsynth/synth.h	2005-04-26 10:21:52.000000000 -0700
@@ -141,6 +141,10 @@
 			   unsigned int* bank_num, 
 			   unsigned int* preset_num);
 
+  /** Immediately stop all notes on a channel. */
+FLUIDSYNTH_API
+int fluid_synth_all_sounds_off(fluid_synth_t* synth, int chan);
+
   /** Send a bank select and a program change to every channel to
    *  reinitialize the preset of the channel. This function is useful
    *  mainly after a SoundFont has been loaded, unloaded or
@@ -368,6 +372,12 @@
   /** Get the master gain */
 FLUIDSYNTH_API float fluid_synth_get_gain(fluid_synth_t* synth);
 
+  /** Set the polyphony limit */
+FLUIDSYNTH_API int fluid_synth_set_polyphony(fluid_synth_t* synth, int polyphony);
+
+  /** Get the polyphony limit */
+FLUIDSYNTH_API int fluid_synth_get_polyphony(fluid_synth_t* synth);
+
   /** Get the internal buffer size. The internal buffer size if not the
       same thing as the buffer size specified in the
       settings. Internally, the synth *always* uses a specific buffer
diff -ur fluidsynth-1.0.5/src/fluid_cmd.c fluidsynth-1.0.5-patched/src/fluid_cmd.c
--- fluidsynth-1.0.5/src/fluid_cmd.c	2004-08-18 07:34:02.000000000 -0700
+++ fluidsynth-1.0.5-patched/src/fluid_cmd.c	2005-04-26 08:30:17.000000000 -0700
@@ -102,6 +102,8 @@
     "chorus [0|1|on|off]        Turn the chorus on or off" },
   { "gain", "general", (fluid_cmd_func_t) fluid_handle_gain, NULL,
     "gain value                 Set the master gain (0 < gain < 5)" },
+  { "polyphony", "general", (fluid_cmd_func_t) fluid_handle_polyphony, NULL,
+    "polyphony value            Set the polyphony limit" },
   { "tuning", "tuning", (fluid_cmd_func_t) fluid_handle_tuning, NULL,
     "tuning name bank prog      Create a tuning with name, bank number, \n"
     "                           and program number (0 <= bank,prog <= 127)" },
@@ -912,6 +914,32 @@
   return 0;
 }
 
+int
+fluid_handle_polyphony(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out)
+{
+  int polyphony;
+
+  if (ac < 1) {
+    fluid_ostream_printf(out, "polyphony: too few arguments.\n");
+    return -1;
+  }
+
+  polyphony = atoi(av[0]);
+
+  if ((polyphony < 1) || (polyphony > synth->nvoice)) {
+    fluid_ostream_printf(out, "polyphony: value should be between '1' and '%d'.\n",
+                         synth->nvoice);
+    if (polyphony > synth->nvoice) {
+      fluid_ostream_printf(out, "(start fluidsynth with '-o synth.polyphony=<number>' to raise limit)\n");
+    }
+    return -1;
+  };
+
+  fluid_synth_set_polyphony(synth, polyphony);
+
+  return 0;
+}
+
 /* Purpose:
  * Response to 'interp' command. */
 int
diff -ur fluidsynth-1.0.5/src/fluid_cmd.h fluidsynth-1.0.5-patched/src/fluid_cmd.h
--- fluidsynth-1.0.5/src/fluid_cmd.h	2003-03-11 08:57:14.000000000 -0800
+++ fluidsynth-1.0.5-patched/src/fluid_cmd.h	2005-04-26 07:37:37.000000000 -0700
@@ -59,6 +59,7 @@
 int fluid_handle_chorus(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
 int fluid_handle_reverb(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
 int fluid_handle_gain(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
+int fluid_handle_polyphony(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
 int fluid_handle_interp(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
 int fluid_handle_interpc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
 int fluid_handle_tuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
diff -ur fluidsynth-1.0.5/src/fluid_synth.c fluidsynth-1.0.5-patched/src/fluid_synth.c
--- fluidsynth-1.0.5/src/fluid_synth.c	2004-08-18 07:38:31.000000000 -0700
+++ fluidsynth-1.0.5-patched/src/fluid_synth.c	2005-04-26 10:27:19.000000000 -0700
@@ -371,6 +371,10 @@
   fluid_settings_register_num(settings, "synth.gain", 
 			      0.2f, 0.0f, 10.0f, 0, 
 			      (fluid_num_update_t) fluid_synth_update_gain, synth);
+  fluid_settings_register_int(settings, "synth.polyphony", 
+			      synth->polyphony, 16, 4096, 0,
+			      (fluid_int_update_t) fluid_synth_update_polyphony,
+                              synth);
 
   /* do some basic sanity checking on the settings */
 
@@ -776,13 +780,13 @@
 /*   fluid_mutex_lock(synth->busy); /\* Don't interfere with the audio thread *\/ */
 /*   fluid_mutex_unlock(synth->busy); */
   
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (_ON(voice) && (voice->chan == chan) && (voice->key == key)) {
       if (synth->verbose) {
 	int used_voices = 0;
 	int k;
-	for (k = 0; k < synth->nvoice; k++) {
+	for (k = 0; k < synth->polyphony; k++) {
 	  if (!_AVAILABLE(synth->voice[k])) {
 	    used_voices++;
 	  }
@@ -813,7 +817,7 @@
 /*   fluid_mutex_lock(synth->busy); /\* Don't interfere with the audio thread *\/ */
 /*   fluid_mutex_unlock(synth->busy); */
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if ((voice->chan == chan) && _SUSTAINED(voice)) {
 /*        printf("turned off sustained note: chan=%d, key=%d, vel=%d\n", voice->chan, voice->key, voice->vel); */
@@ -888,7 +892,7 @@
   int i;
   fluid_voice_t* voice;
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (_PLAYING(voice) && (voice->chan == chan)) {
       fluid_voice_noteoff(voice);
@@ -900,7 +904,7 @@
 /*
  * fluid_synth_all_sounds_off
  *
- * put all notes on this channel into released state.
+ * immediately stop all notes on this channel.
  */
 int
 fluid_synth_all_sounds_off(fluid_synth_t* synth, int chan)
@@ -908,7 +912,7 @@
   int i;
   fluid_voice_t* voice;
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (_PLAYING(voice) && (voice->chan == chan)) {
       fluid_voice_off(voice);
@@ -929,7 +933,7 @@
   int i;
   fluid_voice_t* voice;
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (_PLAYING(voice)) {
       fluid_voice_off(voice);
@@ -961,7 +965,7 @@
 /*   fluid_mutex_lock(synth->busy); /\* Don't interfere with the audio thread *\/ */
 /*   fluid_mutex_unlock(synth->busy); */
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (voice->chan == chan) {
       fluid_voice_modulate(voice, is_cc, ctrl);
@@ -986,7 +990,7 @@
 /*   fluid_mutex_lock(synth->busy); /\* Don't interfere with the audio thread *\/ */
 /*   fluid_mutex_unlock(synth->busy); */
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (voice->chan == chan) {
       fluid_voice_modulate_all(voice);
@@ -1374,7 +1378,7 @@
   fluid_clip(gain, 0.0f, 10.0f);
   synth->gain = gain;
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     fluid_voice_t* voice = synth->voice[i];    
     if (_PLAYING(voice)) {
       fluid_voice_set_gain(voice, gain);
@@ -1391,6 +1395,47 @@
 }
 
 /*
+ * fluid_synth_update_polyphony
+ */
+int fluid_synth_update_polyphony(fluid_synth_t* synth, char* name, int value)
+{
+  fluid_synth_set_polyphony(synth, value);
+  return 0;
+}
+
+/*
+ * fluid_synth_set_polyphony
+ */
+int fluid_synth_set_polyphony(fluid_synth_t* synth, int polyphony)
+{
+  int i;
+
+  if (polyphony < 1 || polyphony > synth->nvoice) {
+    return FLUID_FAILED;
+  }
+
+  /* turn off any voices above the new limit */
+  for (i = polyphony; i < synth->nvoice; i++) {
+    fluid_voice_t* voice = synth->voice[i];    
+    if (_PLAYING(voice)) {
+      fluid_voice_off(voice);
+    }
+  }
+
+  synth->polyphony = polyphony;
+
+  return FLUID_OK;
+}
+
+/*
+ * fluid_synth_get_polyphony
+ */
+int fluid_synth_get_polyphony(fluid_synth_t* synth)
+{
+  return synth->polyphony;
+}
+
+/*
  * fluid_synth_get_internal_buffer_size
  */
 int fluid_synth_get_internal_bufsize(fluid_synth_t* synth)
@@ -1537,20 +1582,24 @@
 
   /* First, take what's still available in the buffer */
   count = 0;
-  available = FLUID_BUFSIZE - synth->cur;
+  num = synth->cur;
+  if (synth->cur < FLUID_BUFSIZE) {
+    available = FLUID_BUFSIZE - synth->cur;
 
-  num = (available > len)? len : available;
-  bytes = num * sizeof(float);
+    num = (available > len)? len : available;
+    bytes = num * sizeof(float);
 
-  for (i = 0; i < synth->audio_channels; i++) {
-    FLUID_MEMCPY(left[i], left_in[i] + synth->cur, bytes);
-    FLUID_MEMCPY(right[i], right_in[i] + synth->cur, bytes);
-  }
-  for (i = 0; i < synth->effects_channels; i++) {
-    FLUID_MEMCPY(fx_left[i], fx_left_in[i] + synth->cur, bytes);
-    FLUID_MEMCPY(fx_right[i], fx_right_in[i] + synth->cur, bytes);
+    for (i = 0; i < synth->audio_channels; i++) {
+      FLUID_MEMCPY(left[i], left_in[i] + synth->cur, bytes);
+      FLUID_MEMCPY(right[i], right_in[i] + synth->cur, bytes);
+    }
+    for (i = 0; i < synth->effects_channels; i++) {
+      FLUID_MEMCPY(fx_left[i], fx_left_in[i] + synth->cur, bytes);
+      FLUID_MEMCPY(fx_right[i], fx_right_in[i] + synth->cur, bytes);
+    }
+    count += num;
+    num += synth->cur; /* if we're now done, num becomes the new synth->cur below */
   }
-  count += num;
 
   /* Then, run one_block() and copy till we have 'len' samples  */
   while (count < len) {
@@ -1756,7 +1805,7 @@
   fluid_profile(FLUID_PROF_ONE_BLOCK_CLEAR, prof_ref);
 
   /* call all playing synthesis processes */
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     
     if (_PLAYING(voice)) {
@@ -1869,7 +1918,7 @@
 /*   fluid_mutex_lock(synth->busy); /\* Don't interfere with the audio thread *\/ */
 /*   fluid_mutex_unlock(synth->busy); */
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     
     voice = synth->voice[i];
     
@@ -1951,7 +2000,7 @@
 /*   fluid_mutex_unlock(synth->busy); */
 
   /* check if there's an available synthesis process */
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     if (_AVAILABLE(synth->voice[i])) {
       voice = synth->voice[i];
       break;
@@ -1970,7 +2019,7 @@
 
   if (synth->verbose) {
     k = 0;
-    for (i = 0; i < synth->nvoice; i++) {
+    for (i = 0; i < synth->polyphony; i++) {
       if (!_AVAILABLE(synth->voice[i])) {
 	k++;
       }
@@ -2039,7 +2088,7 @@
   
     /* Kill all notes on the same channel with the same exclusive class */
   
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     fluid_voice_t* existing_voice = synth->voice[i];
     
     /* Existing voice does not play? Leave it alone. */
@@ -2385,7 +2434,7 @@
 {
   int i;
   int count = 0;
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     fluid_voice_t* voice = synth->voice[i];
     if (count >= bufsize) {
       return;
@@ -2481,7 +2530,7 @@
 /*   fluid_mutex_lock(synth->busy); /\* Don't interfere with the audio thread *\/ */
 /*   fluid_mutex_unlock(synth->busy); */
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (_PLAYING(voice) 
 	&& (voice->chan == chan) 
@@ -2804,7 +2853,7 @@
 
   fluid_channel_set_gen(synth->channel[chan], param, value, 0);
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (voice->chan == chan) {
       fluid_voice_set_param(voice, param, value, 0);
@@ -2859,7 +2908,7 @@
 
   fluid_channel_set_gen(synth->channel[chan], param, v, absolute);
 
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
     voice = synth->voice[i];
     if (voice->chan == chan) {
       fluid_voice_set_param(voice, param, v, absolute);
@@ -2966,7 +3015,7 @@
   int status = FLUID_FAILED;
   int count = 0;
   
-  for (i = 0; i < synth->nvoice; i++) {
+  for (i = 0; i < synth->polyphony; i++) {
 
     voice = synth->voice[i];
 
diff -ur fluidsynth-1.0.5/src/fluid_synth.h fluidsynth-1.0.5-patched/src/fluid_synth.h
--- fluidsynth-1.0.5/src/fluid_synth.h	2004-08-18 07:36:01.000000000 -0700
+++ fluidsynth-1.0.5-patched/src/fluid_synth.h	2005-04-26 08:05:07.000000000 -0700
@@ -205,6 +205,7 @@
 
 
 int fluid_synth_update_gain(fluid_synth_t* synth, char* name, double value);
+int fluid_synth_update_polyphony(fluid_synth_t* synth, char* name, int value);
 
 fluid_bank_offset_t* fluid_synth_get_bank_offset0(fluid_synth_t* synth, int sfont_id);
 void fluid_synth_remove_bank_offset(fluid_synth_t* synth, int sfont_id);