Beispiel #1
0
static bool set_new_sample(struct SoundPlugin *plugin, const wchar_t *filename, int instrument_number, int resampler_type){
  bool success=false;

  Data *data = NULL;
  Data *old_data = plugin->data;

  filename = OS_loading_get_resolved_file_path(filename);
  if (filename==NULL)
    goto exit;

  data = create_data(old_data->samplerate, plugin->data, filename, instrument_number, resampler_type);

  if(load_sample(data,filename,instrument_number)==false)
    goto exit;

  // Put loop_onoff into storage.
  PLUGIN_set_effect_value2(plugin, -1, EFF_LOOP_ONOFF, data->loop_onoff==true?1.0f:0.0f, PLUGIN_STORED_TYPE, PLUGIN_STORE_VALUE, FX_single, PLAYERLOCK_NOT_REQUIRED);

  if(SP_is_plugin_running(plugin)){

    PLAYER_lock();{  
      old_data->new_data = data;
    }PLAYER_unlock();

    if (PLAYER_is_running())
      RSEMAPHORE_wait(old_data->signal_from_RT,1);

  } else {

    plugin->data = data;

  }

  delete_data(old_data);

  update_peaks(plugin);

  volatile struct Patch *patch = plugin->patch;
  if(patch!=NULL)
    GFX_update_instrument_widget((struct Patch*)patch); // Update "loop" button.

  success = true;

 exit:
  if(success==false)
    free(data);

  return success;
}
Beispiel #2
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;
}