Ejemplo n.º 1
0
static int
fluidsynth_init(sfx_softseq_t *self, byte *data_ptr, int data_length,
		byte *data2_ptr, int data2_length)
{
	int sfont_id;
	double min, max;

	if (0) {
		sciprintf("FluidSynth ERROR: Mono sound output not supported.\n");
		return SFX_ERROR;
	}

	gmseq = sfx_find_sequencer("General MIDI");
	if (!gmseq) {
		sciprintf("FluidSynth ERROR: Unable to find General MIDI sequencer.\n");
		return SFX_ERROR;
	}

	settings = new_fluid_settings();

	fluid_settings_getnum_range(settings, "synth.sample-rate", &min, &max);
	if (SAMPLE_RATE < min || SAMPLE_RATE > max) {
		sciprintf("FluidSynth ERROR: Sample rate '%i' not supported. Valid "
			"range is (%i-%i).\n", SAMPLE_RATE, (int) min, (int) max);
		delete_fluid_settings(settings);
		return SFX_ERROR;
	}

	fluid_settings_setnum(settings, "synth.sample-rate", SAMPLE_RATE);
	fluid_settings_setnum(settings, "synth.gain", 0.5f);

	synth = new_fluid_synth(settings);

	if ((sfont_id = fluid_synth_sfload(synth, soundfont, 1)) < 0) {
		delete_fluid_synth(synth);
		delete_fluid_settings(settings);
		return SFX_ERROR;
	}

	gmseq->open(data_length, data_ptr, data2_length, data2_ptr,
		    &midi_writer_fluidsynth);

	return SFX_OK;
}
Ejemplo n.º 2
0
/* fluid_settings_foreach function for displaying option help  "-o help" */
static void
settings_foreach_func (void *data, char *name, int type)
{
  fluid_settings_t *settings = (fluid_settings_t *)data;
  double dmin, dmax, ddef;
  int imin, imax, idef, hints;
  char *defstr;
  int count;
  OptionBag bag;

  switch (type)
  {
  case FLUID_NUM_TYPE:
    fluid_settings_getnum_range (settings, name, &dmin, &dmax);
    ddef = fluid_settings_getnum_default (settings, name);
    printf ("%-24s FLOAT [min=%0.3f, max=%0.3f, def=%0.3f]\n",
	    name, dmin, dmax, ddef);
    break;
  case FLUID_INT_TYPE:
    fluid_settings_getint_range (settings, name, &imin, &imax);
    idef = fluid_settings_getint_default (settings, name);
    hints = fluid_settings_get_hints (settings, name);

    if (!(hints & FLUID_HINT_TOGGLED))
    {
      printf ("%-24s INT   [min=", name);
      print_pretty_int (imin);
      printf (", max=");
      print_pretty_int (imax);
      printf (", def=");
      print_pretty_int (idef);
      printf ("]\n");
    }
    else printf ("%-24s BOOL  [def=%s]\n", name, idef ? "True" : "False");
    break;
  case FLUID_STR_TYPE:
    printf ("%-24s STR", name);

    defstr = fluid_settings_getstr_default (settings, name);
    count = fluid_settings_option_count (settings, name);

    if (defstr || count > 0)
    {
      if (defstr && count > 0) printf ("   [def='%s' vals:", defstr);
      else if (defstr) printf ("   [def='%s'", defstr);
      else printf ("   [vals:");

      if (count > 0)
      {
        bag.count = count;
        bag.curindex = 0;
        fluid_settings_foreach_option (settings, name, &bag,
                                       settings_option_foreach_func);
      }

      printf ("]\n");
    }
    else printf ("\n");
    break;
  case FLUID_SET_TYPE:
    printf ("%-24s SET\n", name);
    break;
  }
}