Пример #1
0
	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;
	}
Пример #2
0
void SynthSequencer::engineActivityChanged()
{
    if (m_engine) {
        if (m_engine->active()) {
            //create
            m_synthID = fluid_sequencer_register_fluidsynth(m_sequencer, m_engine->synthHandle());
            m_clientID = fluid_sequencer_register_client(m_sequencer, "SynthSequencer", sequencer_callback, this);
            qDebug("created sequencer");
        } else {
            //destroy
            m_synthID = 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;
}
Пример #4
0
	size_t load_buffer(ALuint buf) {
		if (is_end()) {
			source_.seq.reset(new_fluid_sequencer2(false), &delete_fluid_sequencer);
			BOOST_VERIFY(fluid_sequencer_register_fluidsynth(source_.seq.get(),
			                                                 source_.synth.get()) != FLUID_FAILED);

			BOOST_VERIFY(fluid_player_add(source_.player.get(), filename_.c_str()) != FLUID_FAILED);
		}

		data_.resize(2 * source_.sample_rate * SECOND_PER_BUFFER);
		if (fluid_synth_write_s16(source_.synth.get(), data_.size() / 2, &data_.front(), 0, 2,
		                          &data_.front(), 1, 2) == FLUID_FAILED) {
			Output::Error("synth error: %s", fluid_synth_error(source_.synth.get()));
		}
		alBufferData(buf, AL_FORMAT_STEREO16, &data_.front(), sizeof(int16_t) * data_.size(),
		             source_.sample_rate);

		return data_.size() / 2;
	}
Пример #5
0
	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);
	}
Пример #6
0
	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.");
	}
Пример #7
0
static void *create_data(const wchar_t *filename, float samplerate){
  Data *data = calloc(1,sizeof(Data));

  data->pitch = 16384/2;
  data->pitch_range = 1;
  data->modulation = 0;
  data->sustain_on = 0;

  data->signal_from_RT = RSEMAPHORE_create(0);

  data->settings = new_fluid_settings();
  if(data->settings==NULL){
    RError("Unable to create fluidsynth settings");
    delete_data(data);
    return NULL;
  }

  if(fluid_settings_setnum(data->settings, "synth.sample-rate", samplerate)==0){
    RError("Unable to set sample rate of fluidsynth to %f\n",samplerate);
    //delete_data(data);
    //return NULL;
  }

  if(fluid_settings_setint(data->settings, "synth.threadsafe-api", 0)==0){
    printf("Unable to set threadsafe-api to 0 (we don't need it)\n");
  }

  if(fluid_settings_setint(data->settings, "synth.chorus.active", 0)==0){
    printf("Unable to set synth.chorus.active to 0 (we don't use it)\n");
  }

  if(fluid_settings_setint(data->settings, "synth.reverb.active", 0)==0){
    printf("Unable to set synth.reverb.active to 0 (we don't use it)\n");
  }



  // TODO: Decide whether we need fluidsynth's reverb and chorus.
  //fluid_settings_setstr(settings, "synth.reverb.active", "yes");
  //fluid_settings_setstr(settings, "synth.chorus.active", "no");

  data->synth = new_fluid_synth(data->settings);
  if(data->synth==NULL){
    RError("Unable to create fluidsynth synth");
    delete_data(data);
    return NULL;
  }

  data->sequencer = new_fluid_sequencer2(0);
  if(data->sequencer==NULL){
    RError("Unable to create fluidsynth sequencer");
    delete_data(data);
    return NULL;
  }

  fluid_sequencer_set_time_scale(data->sequencer, samplerate); // it's a shame that time in fluidsynth is only 32 bit. Hopefully the values wrap properly around.......
  data->time_scale = fluid_sequencer_get_time_scale(data->sequencer);
  data->samplerate = samplerate;

#if 0 // This test always succeeds. Max time_scale in fluidsynth is 1000.0. :-(
  if( data->time_scale != sample_rate){
    RError("Could not set time scale to %f (set to %f instead)\n",(float)samplerate,(float)fluid_sequencer_get_time_scale(data->sequencer));
  }
#endif

  data->synth_seq_ID = fluid_sequencer_register_fluidsynth(data->sequencer, data->synth);
  data->event = new_fluid_event();
  if(data->event==NULL){
    RError("Unable to create fluidsynth event");
    delete_data(data);
    return NULL;
  }

  data->filename = wcsdup(OS_loading_get_resolved_file_path(filename));

  data->soundfont_id = fluid_synth_sfload(data->synth,STRING_get_chars(data->filename),true);

  if(data->soundfont_id==FLUID_FAILED){
    printf("Soundfont loading failed for \"%s\"\n",STRING_get_chars(data->filename));

    delete_data(data);

    return NULL;

  }

  return data;
}