コード例 #1
0
ファイル: gstfluiddec.c プロジェクト: Lachann/gst-plugins-bad
/* initialize the new element
 * instantiate pads and add them to element
 * set functions
 * initialize structure
 */
static void
gst_fluid_dec_init (GstFluidDec * filter)
{
  filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
  gst_pad_set_event_function (filter->sinkpad, gst_fluid_dec_sink_event);
  gst_pad_set_chain_function (filter->sinkpad, gst_fluid_dec_chain);
  gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);

  filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
  gst_pad_use_fixed_caps (filter->srcpad);
  gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);

  filter->soundfont = g_strdup (DEFAULT_SOUNDFONT);
  filter->synth_chorus = DEFAULT_SYNTH_CHORUS;
  filter->synth_reverb = DEFAULT_SYNTH_REVERB;
  filter->synth_gain = DEFAULT_SYNTH_GAIN;
  filter->synth_polyphony = DEFAULT_SYNTH_POLYPHONY;

  filter->settings = new_fluid_settings ();
  filter->synth = new_fluid_synth (filter->settings);
  filter->sf = -1;

  fluid_synth_set_chorus_on (filter->synth, filter->synth_chorus);
  fluid_synth_set_reverb_on (filter->synth, filter->synth_reverb);
  fluid_synth_set_gain (filter->synth, filter->synth_gain);
  fluid_synth_set_polyphony (filter->synth, filter->synth_polyphony);
}
コード例 #2
0
FluidSynthSoundController::FluidSynthSoundController(QObject *parent)
    : Minuet::ISoundController(parent),
      m_audioDriver(0),
      m_sequencer(0),
      m_song(0)
{
    m_tempo = 60;

    m_settings = new_fluid_settings();
    fluid_settings_setstr(m_settings, "synth.reverb.active", "no");
    fluid_settings_setstr(m_settings, "synth.chorus.active", "no");

    m_synth = new_fluid_synth(m_settings);

    fluid_synth_cc(m_synth, 1, 100, 0);

#ifdef Q_OS_LINUX
    int fluid_res = fluid_synth_sfload(m_synth, QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("soundfonts/GeneralUser-v1.47.sf2")).toLatin1(), 1);
#endif
#ifdef Q_OS_WIN
    int fluid_res = fluid_synth_sfload(m_synth, QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("minuet/soundfonts/GeneralUser-v1.47.sf2")).toLatin1(), 1);
#endif
    if (fluid_res == FLUID_FAILED)
        qDebug() << "Error when loading soundfont!";

    resetEngine();
}
コード例 #3
0
ファイル: soundfonts.c プロジェクト: EQ4/Pd-for-LibPd
void *soundfonts_new(void)
{
    // Get Class Instance
    t_soundfonts *instance = (t_soundfonts *)pd_new(soundfonts_class);

    instance->settings = new_fluid_settings();
    instance->synth = new_fluid_synth(instance->settings);
    instance->sfont_id = -1;
    instance->current_id = 0;
    for(int i = 0; i < NUMSOUNDFONTS; i++) {
        instance->soundfonts[i] = -1;
    }
    
    instance->chorus_nr = FLUID_CHORUS_DEFAULT_N;
    instance->chorus_level = FLUID_CHORUS_DEFAULT_LEVEL;
    instance->chorus_depth = FLUID_CHORUS_DEFAULT_DEPTH;
    instance->chorus_speed = FLUID_CHORUS_DEFAULT_SPEED;
    instance->chorus_type = FLUID_CHORUS_DEFAULT_TYPE;
    
    instance->reverb_damping = FLUID_REVERB_DEFAULT_DAMP;
    instance->reverb_level = FLUID_REVERB_DEFAULT_LEVEL;
    instance->reverb_size = FLUID_REVERB_DEFAULT_ROOMSIZE;
    instance->reverb_width = FLUID_REVERB_DEFAULT_WIDTH;
    
    // Spawn outlets
    instance->x_outL = outlet_new(&instance->x_obj, &s_signal);
    instance->x_outR = outlet_new(&instance->x_obj, &s_signal);
    
    return (void *)instance;
}
コード例 #4
0
ファイル: MusicPlayer.cpp プロジェクト: paulsapps/vgmtrans
MusicPlayer::MusicPlayer()
{
    /* Create the settings. */
    this->settings = new_fluid_settings();

    fluid_sfloader_t* loader;

    /* Change the settings if necessary*/
    fluid_settings_setstr(this->settings, "synth.reverb.active", "yes");
    fluid_settings_setstr(this->settings, "synth.chorus.active", "no");
    fluid_settings_setstr(this->settings, "synth.midi-bank-select", "mma");
    fluid_settings_setint(this->settings, "synth.midi-channels", 48);
    fluid_settings_setstr(this->settings, "player.timing-source", "system");

    /* Create the synthesizer. */
    this->synth = new_fluid_synth(this->settings);


    // allocate and add our custom memory sfont loader
    loader = new_memsfloader(settings);

    if (loader == NULL) {
        FLUID_LOG(FLUID_WARN, "Failed to create the default SoundFont loader");
    } else {
        fluid_synth_add_sfloader(synth, loader);
    }


    //    fluid_synth_set_reverb(synth, 0.5, 0.8, FLUID_REVERB_DEFAULT_WIDTH, 0.5);
    fluid_synth_set_reverb(this->synth, 0.7, 0.8, 0.9, 0.4);
    //fluid_synth_set_interp_method(synth, -1, FLUID_INTERP_NONE);

//    this->player = new_vgmtrans_fluid_player(this->synth);
//    fluid_player_set_playback_callback(this->player, &midi_event_callback, this->synth);
}
コード例 #5
0
ファイル: midiplayer.cpp プロジェクト: kirinja/GhettoBlaster
MidiPlayer::MidiPlayer()
{
    settings = new_fluid_settings();
    synth = new_fluid_synth(settings);
    player = new_fluid_player(synth);
    adriver = new_fluid_audio_driver(settings, synth);
}
コード例 #6
0
int main(int argc, char** argv)
{
    int i;
    fluid_settings_t* settings;
    fluid_synth_t* synth;
    fluid_player_t* player;
    fluid_audio_driver_t* adriver;
    settings = new_fluid_settings();
    synth = new_fluid_synth(settings);
    player = new_fluid_player(synth);
    adriver = new_fluid_audio_driver(settings, synth);
    /* process command line arguments */
    for (i = 1; i < argc; i++) {
        if (fluid_is_soundfont(argv[i])) {
            fluid_synth_sfload(synth, argv[1], 1);
        }
        if (fluid_is_midifile(argv[i])) {
            fluid_player_add(player, argv[i]);
        }
    }
    /* play the midi files, if any */
    fluid_player_play(player);
    /* wait for playback termination */
    fluid_player_join(player);
    /* cleanup */
    delete_fluid_audio_driver(adriver);
    delete_fluid_player(player);
    delete_fluid_synth(synth);
    delete_fluid_settings(settings);
    return 0;
}
コード例 #7
0
ファイル: fluidsynth.c プロジェクト: shanewfx/vlc-arib
static int Open (vlc_object_t *p_this)
{
    decoder_t *p_dec = (decoder_t *)p_this;
    decoder_sys_t *p_sys;

    if (p_dec->fmt_in.i_codec != VLC_CODEC_MIDI)
        return VLC_EGENERIC;

    char *font_path = var_CreateGetNonEmptyString (p_this, "soundfont");
    if (font_path == NULL)
    {
        msg_Err (p_this, "sound fonts file required for synthesis");
        return VLC_EGENERIC;
    }

    p_dec->pf_decode_audio = DecodeBlock;
    p_sys = p_dec->p_sys = malloc (sizeof (*p_sys));
    if (p_sys == NULL)
    {
        free (font_path);
        return VLC_ENOMEM;
    }

    p_sys->settings = new_fluid_settings ();
    p_sys->synth = new_fluid_synth (p_sys->settings);
    /* FIXME: I bet this is not thread-safe */
    p_sys->soundfont = fluid_synth_sfload (p_sys->synth, font_path, 1);
    free (font_path);
    if (p_sys->soundfont == -1)
    {
        msg_Err (p_this, "cannot load sound fonts file");
        Close (p_this);
        return VLC_EGENERIC;
    }

    p_dec->fmt_out.i_cat = AUDIO_ES;
    p_dec->fmt_out.audio.i_rate = 44100;
    p_dec->fmt_out.audio.i_channels = 2;
    p_dec->fmt_out.audio.i_original_channels =
    p_dec->fmt_out.audio.i_physical_channels =
        AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
    if (HAVE_FPU)
    {
        p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
        p_dec->fmt_out.audio.i_bitspersample = 32;
        p_sys->fixed = false;
    }
    else
    {
        p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
        p_dec->fmt_out.audio.i_bitspersample = 16;
        p_sys->fixed = true;
    }
    date_Init (&p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1);
    date_Set (&p_sys->end_date, 0);

    return VLC_SUCCESS;
}
コード例 #8
0
ファイル: Fluidsynth-code.cpp プロジェクト: lmaxwell/chugins
 // constructor
 fluidsynth(t_CKFLOAT fs)
 {
     m_srate = fs;
     
     m_settings = new_fluid_settings();
     m_synth = new_fluid_synth(m_settings);
     
     fluid_synth_set_sample_rate(m_synth, m_srate);
 }
コード例 #9
0
ファイル: Synth.c プロジェクト: jasonLaster/team7
FluidSynth* fluidsynth_new() {
  fluid_settings_t* settings = new_fluid_settings();
  FluidSynth* synth = new_fluid_synth(settings);
  fluid_synth_program_change(synth, 0, 4);
  fluid_settings_setstr(settings, "audio.driver", audio_driver());
  new_fluid_audio_driver(settings, synth);
  fluid_synth_sfload(synth, "FluidR3_GM.sf2", 1);
  return synth;
}
コード例 #10
0
ファイル: fluid.c プロジェクト: curiousbadger/denemo
int
fluidsynth_init (DenemoPrefs * config, unsigned int samplerate)
{
  g_debug ("Starting FLUIDSYNTH");

  settings = new_fluid_settings ();
  if (!settings)
    {
      g_warning ("Failed to create the settings");
      return -1;
    }

  fluid_settings_setnum (settings, "synth.sample-rate", (double) samplerate);

  fluid_settings_setint (settings, "synth.reverb.active", config->fluidsynth_reverb ? 1 : 0);
  fluid_settings_setint (settings, "synth.chorus.active", config->fluidsynth_chorus ? 1 : 0);

  // create the synthesizer
  synth = new_fluid_synth (settings);
  if (!synth)
    {
      g_warning ("Failed to create the settings");
      fluidsynth_shutdown ();
      return -1;
    }

  if(g_file_test(config->fluidsynth_soundfont->str, G_FILE_TEST_EXISTS))
    sfont_id = fluid_synth_sfload (synth, config->fluidsynth_soundfont->str, FALSE);

  if (sfont_id == -1)
    {
      g_debug ("Failed to load the user soundfont. Now trying the default soundfont.");
      gchar *default_soundfont = find_denemo_file(DENEMO_DIR_SOUNDFONTS, "A320U.sf2");
      if(default_soundfont)
        sfont_id = fluid_synth_sfload (synth, default_soundfont, FALSE);
      g_string_assign (Denemo.prefs.fluidsynth_soundfont, default_soundfont);
      g_free (default_soundfont);
    }
  if (sfont_id == -1)
    {
      fluidsynth_shutdown ();
      return -1;
    }
  else
    {
      g_message ("The default fluidsynth soundfont has been loaded");
    }
 reset_synth_channels ();

  return 0;
}
コード例 #11
0
ファイル: midi.cpp プロジェクト: Mailaender/XL-Engine
	bool init(MidiFormat format, const char* patchLoc)
	{
		free();
		s_mutex = Mutex::create();
		s_midiFormat = format;

		if (s_midiFormat == MFMT_GUS_PATCH)
		{
			s_volume = c_volumeScale[0];
			s_sampleRate = 32072.0;
			if (WildMidi_Init(patchLoc, 32072, WM_MO_ENHANCED_RESAMPLING) >= 0)
			{
				s_initialized = true;
				WildMidi_MasterVolume(100);
				
				return true;
			}
		}
		else if (s_midiFormat == MFMT_SOUND_FONT)
		{
			s_volume = c_volumeScale[1];
			if (!loadFluidsythDLL())
			{
				LOG( LOG_ERROR, "cannot find or load the \"libfluidsynth\" dynamic library." );
				return false;
			}
			
			s_fluidSettings = new_fluid_settings();
			fluid_settings_setstr(s_fluidSettings, "player.timing-source", "sample");
			fluid_settings_setstr(s_fluidSettings, "synth.lock-memory", 0);
			fluid_settings_setstr(s_fluidSettings, "synth.chorus-active", "0");

			s_fluidSynth = new_fluid_synth(s_fluidSettings);
			if (fluid_synth_sfload(s_fluidSynth, patchLoc, 1) < 0)
			{
				LOG( LOG_ERROR, "cannot load sound font \"%s\"", patchLoc );
				unloadFluidsynthDLL();
				return false;
			}
			
			s_fluidSeq = new_fluid_sequencer2(false);
			fluid_sequencer_register_fluidsynth(s_fluidSeq, s_fluidSynth);
			fluid_settings_getnum(s_fluidSettings, "synth.sample-rate", &s_sampleRate);

			s_initialized = true;
			s_fluidPlayer = new_fluid_player(s_fluidSynth);
			return true;
		}

		return false;
	}
コード例 #12
0
    void SetupSynth()
    {
        fluidSettings = new_fluid_settings();
        if(fluidSettings)
        {
            fluid_settings_setnum(fluidSettings, "synth.gain", 0.5);
            fluid_settings_setstr(fluidSettings, "synth.reverb.active", "yes");
            fluid_settings_setstr(fluidSettings, "synth.chorus.active", "yes");
            fluid_settings_setint(fluidSettings, "synth.polyphony", 256);
            fluid_settings_setnum(fluidSettings, "synth.sample-rate", (double)sampleRate);

            fluidSynth = new_fluid_synth(fluidSettings);
        }
    }
コード例 #13
0
int
main (int argc, char *argv[])
{
    int n;
    fluid_settings_t *settings;
    settings = new_fluid_settings ();
    if (argc < 2) {
        usage (argv[0]);
    } else {
        /* create the synth, driver and sequencer instances */
        synth = new_fluid_synth (settings);
        audiodriver = new_fluid_audio_driver (settings, synth);
        sequencer = new_fluid_sequencer ();
        /* register the synth with the sequencer */
        synth_destination = fluid_sequencer_register_fluidsynth (sequencer,
                synth);
        /* register the client name and callback */
        client_destination = fluid_sequencer_register_client (sequencer,
                "fluidsynth_metronome", sequencer_callback, NULL);
        /* load a SoundFont */
        n = fluid_synth_sfload (synth, argv[1], 1);
        if (n != -1) {
            if (argc > 2) {
                n = atoi (argv[2]);
                if (n > 0) pattern_size = n;
            }
            if (argc > 3) {
                n = atoi (argv[3]);
                if (n > 0) note_duration = 60000 / n;
            }
            /* get the current time in ticks */
            time_marker = fluid_sequencer_get_tick (sequencer);
            /* schedule patterns */
            schedule_pattern ();
            schedule_timer_event ();
            schedule_pattern ();
            /* wait for user input */
            printf ("press <Enter> to stop\n");
            n = getchar ();
        }
        /* clean and exit */
        delete_fluid_sequencer (sequencer);
        delete_fluid_audio_driver (audiodriver);
        delete_fluid_synth (synth);
    }
    delete_fluid_settings (settings);
    return 0;
}
コード例 #14
0
ファイル: fluidsynth.cpp プロジェクト: J0anJosep/OpenTTD
const char *MusicDriver_FluidSynth::Start(const char * const *param)
{
	const char *driver_name = GetDriverParam(param, "driver");
	const char *sfont_name = GetDriverParam(param, "soundfont");
	int sfont_id;

	if (!driver_name) driver_name = "alsa";

	DEBUG(driver, 1, "Fluidsynth: driver %s, sf %s", driver_name, sfont_name);

	/* Create the settings. */
	_midi.settings = new_fluid_settings();
	if (!_midi.settings) return "Could not create midi settings";

	if (fluid_settings_setstr(_midi.settings, "audio.driver", driver_name) != 1) {
		return "Could not set audio driver name";
	}

	/* Create the synthesizer. */
	_midi.synth = new_fluid_synth(_midi.settings);
	if (!_midi.synth) return "Could not open synth";

	/* Create the audio driver. The synthesizer starts playing as soon
	   as the driver is created. */
	_midi.adriver = new_fluid_audio_driver(_midi.settings, _midi.synth);
	if (!_midi.adriver) return "Could not open audio driver";

	/* Load a SoundFont and reset presets (so that new instruments
	 * get used from the SoundFont) */
	if (!sfont_name) {
		int i;
		sfont_id = FLUID_FAILED;
		for (i = 0; default_sf[i]; i++) {
			if (!fluid_is_soundfont(default_sf[i])) continue;
			sfont_id = fluid_synth_sfload(_midi.synth, default_sf[i], 1);
			if (sfont_id != FLUID_FAILED) break;
		}
		if (sfont_id == FLUID_FAILED) return "Could not open any sound font";
	} else {
		sfont_id = fluid_synth_sfload(_midi.synth, sfont_name, 1);
		if (sfont_id == FLUID_FAILED) return "Could not open sound font";
	}

	_midi.player = NULL;

	return NULL;
}
JNIEXPORT jlong JNICALL Java_org_herac_tuxguitar_player_impl_midiport_fluidsynth_MidiSynth_malloc(JNIEnv* env, jobject obj)
{
	jlong ptr = 0;
	
	fluid_handle_t *handle = (fluid_handle_t *) malloc( sizeof(fluid_handle_t) );
	
	handle->settings = new_fluid_settings();
	handle->synth = new_fluid_synth(handle->settings);
	handle->driver = new_fluid_audio_driver(handle->settings,handle->synth);
	handle->soundfont_id = 0;
	
	fluid_synth_set_gain( handle->synth, 1.0 );
	
	memcpy(&ptr, &handle, sizeof( handle ));
	
	return ptr;
}
コード例 #16
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;
}
コード例 #17
0
/**
   Create temporary fluid synthesiser and get the list of presets for the
   combo box.
*/
static void get_presets(FluidUI *self)
{
    fluid_preset_t p;

    fluid_settings_t *settings = new_fluid_settings();
    fluid_synth_t *synth = new_fluid_synth(settings);
    fluid_synth_sfload(synth, SOUNDFONT_FILE, 1);

    fluid_sfont_t *sfont = fluid_synth_get_sfont_by_id(synth, 1);

    sfont->iteration_start(sfont);
    while (sfont->iteration_next(sfont, &p)) {
        gtk_combo_box_text_append_text((GtkComboBoxText *)self->combo_box,
                                       p.get_name(&p));
    }

    delete_fluid_synth(synth);
    delete_fluid_settings(settings);
}
/*
 * Class:     org_tritonus_midi_device_fluidsynth_FluidSynthesizer
 * Method:    newSynth
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_tritonus_midi_device_fluidsynth_FluidSynthesizer_newSynth
(JNIEnv *env, jobject obj)
{
	fluid_synth_t* synth = NULL;
	fluid_settings_t* settings = NULL;
	fluid_audio_driver_t* adriver = NULL;

	synth = get_synth(env, obj);
	if (synth == 0)
	{
		settings = new_fluid_settings();
		if (settings == 0) {
			goto error_recovery;
		}
		
		synth = new_fluid_synth(settings);
		if (synth == 0) {
			goto error_recovery;
		}
#ifdef VARIADIC_MACROS
		out("newSynth: synth: %p\n", synth);
#else
		if (debug_flag)
		{
			fprintf(debug_file, "newSynth: synth: %p\n", synth);
			fflush(debug_file);
		}
#endif
		
		adriver = new_fluid_audio_driver(settings, synth);
		if (adriver == 0) {
			goto error_recovery;
		}
		(*env)->SetLongField(env, obj, settingsPtrFieldID, (jlong) ((unsigned int) settings));
		(*env)->SetLongField(env, obj, synthPtrFieldID, (jlong) ((unsigned int) synth));
		(*env)->SetLongField(env, obj, audioDriverPtrFieldID, (jlong) ((unsigned int) adriver));
	}
	return 0;

error_recovery:
	fluid_jni_delete_synth(env, obj, settings, synth, adriver);
	return -1;
}
コード例 #19
0
int main(int argc, char** argv)
{
  fluid_settings_t* settings;
  fluid_synth_t* synth;
  fluid_audio_driver_t* adriver1, *adriver2, *adriver3;
  int sfont_id;
  int i, key;
  /* Create the settings. */
  settings = new_fluid_settings();
  /* Change the settings if necessary*/
  /* Create the synthesizer. */
  synth = new_fluid_synth(settings);
  /* Create the audio driver. The synthesizer starts playing as soon
     as the driver is created. */
  adriver1 = new_fluid_audio_driver(settings, synth);
  fluid_settings_setstr(settings, "audio.driver", "pulseaudio");
  adriver2 = new_fluid_audio_driver(settings, synth);
  fluid_settings_setstr(settings, "audio.driver", "alsa");
  adriver3 = new_fluid_audio_driver(settings, synth);
  /* Load a SoundFont and reset presets (so that new instruments
   * get used from the SoundFont) */
  sfont_id = fluid_synth_sfload(synth, "/usr/share/soundfonts/SGM-V2.01.sf2", 1);
  /* Initialize the random number generator */
  srand(time(NULL));
  for (i = 0; i < 12; i++) {
    /* Generate a random key */
    key = 60 + (int) (12.0f * rand() / (float) RAND_MAX);
    /* Play a note */
    fluid_synth_noteon(synth, 0, key, 80);
    /* Sleep for 1 second */
    sleep(1);
    /* Stop the note */
    fluid_synth_noteoff(synth, 0, key);
  }
  /* Clean up */
  delete_fluid_audio_driver(adriver1);
  delete_fluid_audio_driver(adriver2);
  delete_fluid_audio_driver(adriver3);
  delete_fluid_synth(synth);
  delete_fluid_settings(settings);
  return 0;
}
コード例 #20
0
ファイル: al_audio.cpp プロジェクト: Ancurio/Player
	void init_midi() {
		if (synth) {
			return;
		}

		settings.reset(new_fluid_settings(), &delete_fluid_settings);
		fluid_settings_setstr(settings.get(), "player.timing-source", "sample");
		fluid_settings_setint(settings.get(), "synth.lock-memory", 0);

		synth.reset(new_fluid_synth(settings.get()), &delete_fluid_synth);
		BOOST_VERIFY(fluid_synth_sfload(synth.get(), getenv("DEFAULT_SOUNDFONT"), 1) !=
		             FLUID_FAILED);

		double sample_rate = 0;
		fluid_settings_getnum(settings.get(), "synth.sample-rate", &sample_rate);
		BOOST_ASSERT(sample_rate != 0);
		this->sample_rate = sample_rate;

		seq.reset(new_fluid_sequencer2(false), &delete_fluid_sequencer);
		BOOST_VERIFY(fluid_sequencer_register_fluidsynth(seq.get(), synth.get()) != FLUID_FAILED);
	}
コード例 #21
0
int MidiDriver_FluidSynth::open() {
    if (_isOpen)
        return MERR_ALREADY_OPEN;

    if (!ConfMan.hasKey("soundfont"))
        error("FluidSynth requires a 'soundfont' setting");

    _settings = new_fluid_settings();

    // The default gain setting is ridiculously low - at least for me. This
    // cannot be fixed by ScummVM's volume settings because they can only
    // soften the sound, not amplify it, so instead we add an option to
    // adjust the gain of FluidSynth itself.

    double gain = (double)ConfMan.getInt("midi_gain") / 100.0;

    setNum("synth.gain", gain);
    setNum("synth.sample-rate", _outputRate);

    _synth = new_fluid_synth(_settings);

    // In theory, this ought to reduce CPU load... but it doesn't make any
    // noticeable difference for me, so disable it for now.

    // fluid_synth_set_interp_method(_synth, -1, FLUID_INTERP_LINEAR);
    // fluid_synth_set_reverb_on(_synth, 0);
    // fluid_synth_set_chorus_on(_synth, 0);

    const char *soundfont = ConfMan.get("soundfont").c_str();

    _soundFont = fluid_synth_sfload(_synth, soundfont, 1);
    if (_soundFont == -1)
        error("Failed loading custom sound font '%s'", soundfont);

    MidiDriver_Emulated::open();

    // The MT-32 emulator uses kSFXSoundType here. I don't know why.
    _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_handle, this, -1, 255, 0, false, true);
    return 0;
}
コード例 #22
0
ファイル: fluid.cpp プロジェクト: AndreeeCZ/muse
bool ISynth::init(const char* name)
      {
      fluid_settings_t* settings;
      settings = new_fluid_settings();
      fluid_settings_setnum(settings, (char*) "synth.sample-rate", float(sampleRate()));

      _fluidsynth = new_fluid_synth(settings);

      //---------------------------------------
      //    create non realtime helper thread
      //    create message channels
      //
      int filedes[2];         // 0 - reading   1 - writing
      if (pipe(filedes) == -1) {
            perror("ISynth::thread:creating pipe");
            return true;
            }
      readFd  = filedes[0];
      writeFd = filedes[1];

      pthread_attr_t* attributes = (pthread_attr_t*) malloc(sizeof(pthread_attr_t));
      pthread_attr_init(attributes);
      if (pthread_create(&helperThread, attributes, ::helper, this))
            perror("creating thread failed:");
      pthread_attr_destroy(attributes);

      char* p = getenv("DEFAULT_SOUNDFONT");
      if (p) {
            sfont = new char[strlen(p)+1];
            strcpy(sfont, p);
            char c = 'x';
            _busy = true;
            write(writeFd, &c, 1);
            }

      gui = new FLUIDGui;
      gui->setWindowTitle(QString(name));
      gui->show();
      return false;
      }
コード例 #23
0
int main(int argc, char** argv)
{
    int i;
    fluid_settings_t* settings;
    fluid_synth_t* synth;
    fluid_player_t* player;
    fluid_audio_driver_t* adriver;
    settings = new_fluid_settings();
    fluid_settings_setstr(settings, "audio.driver", "alsa");
    fluid_settings_setint(settings, "synth.polyphony", 64);
    synth = new_fluid_synth(settings);
    player = new_fluid_player(synth);

    /* Set the MIDI event callback to our own functions rather than the system default */
    fluid_player_set_playback_callback(player, event_callback, synth);

    /* Add an onload callback so we can get information from new data before it plays */
    fluid_player_set_onload_callback(player, onload_callback, NULL);

    adriver = new_fluid_audio_driver(settings, synth);
    /* process command line arguments */
    for (i = 1; i < argc; i++) {
        if (fluid_is_soundfont(argv[i])) {
	    fluid_synth_sfload(synth, argv[1], 1);
        } else {
            fluid_player_add(player, argv[i]);
        }
    }
    /* play the midi files, if any */
    fluid_player_play(player);
    /* wait for playback termination */
    fluid_player_join(player);
    /* cleanup */
    delete_fluid_audio_driver(adriver);
    delete_fluid_player(player);
    delete_fluid_synth(synth);
    delete_fluid_settings(settings);
    return 0;
}
コード例 #24
0
ファイル: audio_al.cpp プロジェクト: FaithFeather/Player
	void init_midi() {
		if (synth) {
			return;
		}

		settings.reset(new_fluid_settings(), &delete_fluid_settings);
		fluid_settings_setstr(settings.get(), "player.timing-source", "sample");
		fluid_settings_setint(settings.get(), "synth.lock-memory", 0);

		synth.reset(new_fluid_synth(settings.get()), &delete_fluid_synth);
		if (fluid_synth_sfload(synth.get(), getenv("DEFAULT_SOUNDFONT"), 1) == FLUID_FAILED)
			Output::Error("Couldn't load soundfont\n%s.", getenv("DEFAULT_SOUNDFONT"));

		double sample_rate = 0;
		fluid_settings_getnum(settings.get(), "synth.sample-rate", &sample_rate);
		assert(sample_rate != 0);
		this->sample_rate = sample_rate;

		seq.reset(new_fluid_sequencer2(false), &delete_fluid_sequencer);
		if (fluid_sequencer_register_fluidsynth(seq.get(), synth.get()) == FLUID_FAILED)
			Output::Error("Couldn't initialize MIDI playback.");
	}
コード例 #25
0
int FluidSynthMidiDriver::open() {

	if (!stereo) {
		perr << "FluidSynth only works with Stereo output" << std::endl;
		return -1;
	}

	std::string soundfont = getConfigSetting("soundfont", "");

	if (soundfont == "") {
		perr << "FluidSynth requires a 'soundfont' setting" << std::endl;
		return -2;
	}

	_settings = new_fluid_settings();

	// The default gain setting is ridiculously low, but we can't set it
	// too high either or sound will be clipped. This may need tuning...

	setNum("synth.gain", 2.1);
	setNum("synth.sample-rate", sample_rate);

	_synth = new_fluid_synth(_settings);

	// In theory, this ought to reduce CPU load... but it doesn't make any
	// noticeable difference for me, so disable it for now.

	// fluid_synth_set_interp_method(_synth, -1, FLUID_INTERP_LINEAR);
	// fluid_synth_set_reverb_on(_synth, 0);
	// fluid_synth_set_chorus_on(_synth, 0);

	_soundFont = fluid_synth_sfload(_synth, soundfont.c_str(), 1);
	if (_soundFont == -1) {
		perr << "Failed loading custom sound font '" << soundfont << "'" << std::endl;
		return -3;
	}

	return 0;
}
コード例 #26
0
ファイル: alMidi.c プロジェクト: Neurochrom/OpenAL-Soft
static ALboolean FSynth_init(FSynth *self, ALCdevice *device)
{
    self->Settings = new_fluid_settings();
    if(!self->Settings)
    {
        ERR("Failed to create FluidSettings\n");
        return AL_FALSE;
    }

    fluid_settings_setint(self->Settings, "synth.reverb.active", 1);
    fluid_settings_setint(self->Settings, "synth.chorus.active", 1);
    fluid_settings_setint(self->Settings, "synth.polyphony", 256);
    fluid_settings_setnum(self->Settings, "synth.sample-rate", device->Frequency);

    self->Synth = new_fluid_synth(self->Settings);
    if(!self->Synth)
    {
        ERR("Failed to create FluidSynth\n");
        return AL_FALSE;
    }

    return AL_TRUE;
}
コード例 #27
0
int open_sequencer(seq_context_t *seq)
{
  int err;
  seq->f_settings = new_fluid_settings();
  seq->f_synth = new_fluid_synth(seq->f_settings);
  if (seq->f_synth == NULL)
  {
    perror("failed: new_fluid_synth");
    return FALSE;
  }
  err = fluid_synth_system_reset(seq->f_synth);
  if (err == FLUID_FAILED)
  {
    perror("failed: fluid_synth_system_reset");
    return FALSE;
  }
  fluid_settings_setstr(seq->f_settings, "audio.driver", F_AUDIO_DRIVER);
  seq->f_adriver = new_fluid_audio_driver(seq->f_settings, seq->f_synth);
  if (seq->f_adriver == NULL)
  {
    perror("failed: new_fluid_audio_driver");
    return FALSE;
  }
  if (fluid_is_soundfont(F_SF_PATH) == FALSE)
  {
    perror("failed: fluid_is_soundfont");
    return FALSE;
  }
  err = fluid_synth_sfload(seq->f_synth, F_SF_PATH, 1);
  if (err == FLUID_FAILED)
  {
    perror("failed: fluid_synth_sfload");
    return FALSE;
  }
  return TRUE;
}
コード例 #28
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Configure the MPU attributes as Write Through */
  MPU_Config();

  /* Enable the CPU Cache */
  CPU_CACHE_Enable();

  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Systick timer is configured by default as source of time base, but user
         can eventually implement his proper time base source (a general purpose
         timer for example or other time source), keeping in mind that Time base
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 200 MHz */
  SystemClock_Config();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);

  HAL_Delay(100);

  setbuf(stdout, NULL);

  BSP_LED_On(LED1);

  SD_init();
  HAL_Delay(100);

  fluid_settings_t* settings;
  int sfont_id;

  /* Create the settings. */
  settings = new_fluid_settings();
  fluid_settings_setnum(settings, "synth.sample-rate", SAMPLE_RATE); 

  fluid_settings_setstr(settings, "synth.reverb.active", "no");
  fluid_settings_setstr(settings, "synth.chorus.active", "no");
  fluid_settings_setint(settings, "synth.polyphony", POLYPHONY);

  /* Create the synthesizer. */
  synth = new_fluid_synth(settings);

  sfont_id = fluid_synth_sfload(synth, SOUNDFONT_FILE, 1);
  fluid_synth_set_interp_method(synth, -1, FLUID_INTERP_NONE);
//  fluid_synth_set_interp_method(synth, -1, FLUID_INTERP_LINEAR);

  /* Make the connection and initialize to USB_OTG/usbdc_core */
  USBD_Init(&USBD_Device, &AUDIO_Desc, 0);
  USBD_RegisterClass(&USBD_Device, &USBD_Midi_ClassDriver);
  USBD_Midi_RegisterInterface(&USBD_Device, &USBD_Midi_fops);
  USBD_Start(&USBD_Device);

  HAL_Delay(5);

  BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, MASTER_VOLUME, SAMPLE_RATE);
  BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);  // PCM 2-channel

#ifdef AUDIO_FORMAT_32BITS
  BSP_AUDIO_OUT_Play((uint32_t *)&buf[0], AUDIO_BUF_SIZE);
#else
  BSP_AUDIO_OUT_Play((uint16_t *)&buf[0], AUDIO_BUF_SIZE);
#endif

  BSP_LED_Off(LED1);

  while (1)
  {
                BSP_LED_Toggle(LED1);
                HAL_Delay(1000);
  }

}
コード例 #29
0
ファイル: sf2_player.cpp プロジェクト: AHudon/lmms
sf2Instrument::sf2Instrument( InstrumentTrack * _instrument_track ) :
	Instrument( _instrument_track, &sf2player_plugin_descriptor ),
	m_srcState( NULL ),
	m_font( NULL ),
	m_fontId( 0 ),
	m_filename( "" ),
	m_lastMidiPitch( -1 ),
	m_lastMidiPitchRange( -1 ),
	m_channel( 1 ),
	m_bankNum( 0, 0, 999, this, tr("Bank") ),
	m_patchNum( 0, 0, 127, this, tr("Patch") ),
	m_gain( 1.0f, 0.0f, 5.0f, 0.01f, this, tr( "Gain" ) ),
	m_reverbOn( false, this, tr( "Reverb" ) ),
	m_reverbRoomSize( FLUID_REVERB_DEFAULT_ROOMSIZE, 0, 1.0, 0.01f, this, tr( "Reverb Roomsize" ) ),
	m_reverbDamping( FLUID_REVERB_DEFAULT_DAMP, 0, 1.0, 0.01, this, tr( "Reverb Damping" ) ),
	m_reverbWidth( FLUID_REVERB_DEFAULT_WIDTH, 0, 1.0, 0.01f, this, tr( "Reverb Width" ) ),
	m_reverbLevel( FLUID_REVERB_DEFAULT_LEVEL, 0, 1.0, 0.01f, this, tr( "Reverb Level" ) ),
	m_chorusOn( false, this, tr( "Chorus" ) ),
	m_chorusNum( FLUID_CHORUS_DEFAULT_N, 0, 10.0, 1.0, this, tr( "Chorus Lines" ) ),
	m_chorusLevel( FLUID_CHORUS_DEFAULT_LEVEL, 0, 10.0, 0.01, this, tr( "Chorus Level" ) ),
	m_chorusSpeed( FLUID_CHORUS_DEFAULT_SPEED, 0.29, 5.0, 0.01, this, tr( "Chorus Speed" ) ),
	m_chorusDepth( FLUID_CHORUS_DEFAULT_DEPTH, 0, 46.0, 0.05, this, tr( "Chorus Depth" ) )
{
	for( int i = 0; i < 128; ++i )
	{
		m_notesRunning[i] = 0;
	}

	m_settings = new_fluid_settings();

	fluid_settings_setint( m_settings, (char *) "audio.period-size", engine::mixer()->framesPerPeriod() );

	// This is just our starting instance of synth.  It is recreated
	// everytime we load a new soundfont.
	m_synth = new_fluid_synth( m_settings );

	InstrumentPlayHandle * iph = new InstrumentPlayHandle( this );
	engine::mixer()->addPlayHandle( iph );

	loadFile( configManager::inst()->defaultSoundfont() );

	updateSampleRate();
	updateReverbOn();
	updateReverb();
	updateChorusOn();
	updateChorus();
	updateGain();

	connect( &m_bankNum, SIGNAL( dataChanged() ), this, SLOT( updatePatch() ) );
	connect( &m_patchNum, SIGNAL( dataChanged() ), this, SLOT( updatePatch() ) );

	connect( engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( updateSampleRate() ) );

	// Gain
	connect( &m_gain, SIGNAL( dataChanged() ), this, SLOT( updateGain() ) );

	// Reverb
	connect( &m_reverbOn, SIGNAL( dataChanged() ), this, SLOT( updateReverbOn() ) );
	connect( &m_reverbRoomSize, SIGNAL( dataChanged() ), this, SLOT( updateReverb() ) );
	connect( &m_reverbDamping, SIGNAL( dataChanged() ), this, SLOT( updateReverb() ) );
	connect( &m_reverbWidth, SIGNAL( dataChanged() ), this, SLOT( updateReverb() ) );
	connect( &m_reverbLevel, SIGNAL( dataChanged() ), this, SLOT( updateReverb() ) );

	// Chorus
	connect( &m_chorusOn, SIGNAL( dataChanged() ), this, SLOT( updateChorusOn() ) );
	connect( &m_chorusNum, SIGNAL( dataChanged() ), this, SLOT( updateChorus() ) );
	connect( &m_chorusLevel, SIGNAL( dataChanged() ), this, SLOT( updateChorus() ) );
	connect( &m_chorusSpeed, SIGNAL( dataChanged() ), this, SLOT( updateChorus() ) );
	connect( &m_chorusDepth, SIGNAL( dataChanged() ), this, SLOT( updateChorus() ) );

}
コード例 #30
0
static int Open (vlc_object_t *p_this)
{
    decoder_t *p_dec = (decoder_t *)p_this;

    if (p_dec->fmt_in.i_codec != VLC_CODEC_MIDI)
        return VLC_EGENERIC;

    decoder_sys_t *p_sys = (decoder_sys_t *)malloc (sizeof (*p_sys));			// sunqueen modify
    if (unlikely(p_sys == NULL))
        return VLC_ENOMEM;

    p_sys->settings = new_fluid_settings ();
    p_sys->synth = new_fluid_synth (p_sys->settings);
    p_sys->soundfont = -1;

    char *font_path = var_InheritString (p_this, "soundfont");
    if (font_path != NULL)
    {
        msg_Dbg (p_this, "loading sound fonts file %s", font_path);
        p_sys->soundfont = fluid_synth_sfload (p_sys->synth, font_path, 1);
        if (p_sys->soundfont == -1)
            msg_Err (p_this, "cannot load sound fonts file %s", font_path);
        free (font_path);
    }
#ifdef _POSIX_VERSION
    else
    {
        glob_t gl;

        glob ("/usr/share/sounds/sf2/*.sf2", GLOB_NOESCAPE, NULL, &gl);
        for (size_t i = 0; i < gl.gl_pathc; i++)
        {
            const char *path = gl.gl_pathv[i];

            msg_Dbg (p_this, "loading sound fonts file %s", path);
            p_sys->soundfont = fluid_synth_sfload (p_sys->synth, path, 1);
            if (p_sys->soundfont != -1)
                break; /* it worked! */
            msg_Err (p_this, "cannot load sound fonts file %s", path);
        }
        globfree (&gl);
    }
#endif

    if (p_sys->soundfont == -1)
    {
        msg_Err (p_this, "sound font file required for synthesis");
        dialog_Fatal (p_this, _("MIDI synthesis not set up"),
            _("A sound font file (.SF2) is required for MIDI synthesis.\n"
              "Please install a sound font and configure it "
              "from the VLC preferences "
              "(Input / Codecs > Audio codecs > FluidSynth).\n"));
        delete_fluid_synth (p_sys->synth);
        delete_fluid_settings (p_sys->settings);
        free (p_sys);
        return VLC_EGENERIC;
    }

    fluid_synth_set_chorus_on (p_sys->synth,
                               var_InheritBool (p_this, "synth-chorus"));
    fluid_synth_set_gain (p_sys->synth,
                          var_InheritFloat (p_this, "synth-gain"));
    fluid_synth_set_polyphony (p_sys->synth,
                               var_InheritInteger (p_this, "synth-polyphony"));
    fluid_synth_set_reverb_on (p_sys->synth,
                               var_InheritBool (p_this, "synth-reverb"));

    p_dec->fmt_out.i_cat = AUDIO_ES;
    p_dec->fmt_out.audio.i_rate =
        var_InheritInteger (p_this, "synth-sample-rate");;
    fluid_synth_set_sample_rate (p_sys->synth, p_dec->fmt_out.audio.i_rate);
    p_dec->fmt_out.audio.i_channels = 2;
    p_dec->fmt_out.audio.i_original_channels =
    p_dec->fmt_out.audio.i_physical_channels =
        AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
    p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
    p_dec->fmt_out.audio.i_bitspersample = 32;
    date_Init (&p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1);
    date_Set (&p_sys->end_date, 0);

    p_dec->p_sys = p_sys;
    p_dec->pf_decode_audio = DecodeBlock;
    return VLC_SUCCESS;
}