Exemple #1
0
    int init(CSOUND *csound) {
        int result = OK;
#pragma omp critical (critical_section_fluidopcodes)
        {
            toa(iFluidSynth, fluidSynth);
            channel = (int) *iChannelNumber;
            interpolationMethod = (int) *iInterpMethod;
            if (interpolationMethod != 0 && interpolationMethod != 1 &&
                    interpolationMethod != 4 && interpolationMethod != 7) {
                csound->InitError(csound,
                        Str("Illegal Interpolation Method: Must be "
                                "either 0, 1, 4, or 7.\n"));
                result = NOTOK;
            } else {
                fluid_synth_set_interp_method(fluidSynth, channel,
                                              interpolationMethod);
            }
        }
        return result;
    }
/**
  * @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);
  }

}
Exemple #3
0
void sf2Instrument::updateSampleRate()
{
	double tempRate;

	// Set & get, returns the true sample rate
	fluid_settings_setnum( m_settings, (char *) "synth.sample-rate", engine::mixer()->processingSampleRate() );
	fluid_settings_getnum( m_settings, (char *) "synth.sample-rate", &tempRate );
	m_internalSampleRate = static_cast<int>( tempRate );

	if( m_font )
	{
		// Now, delete the old one and replace
		m_synthMutex.lock();
		fluid_synth_remove_sfont( m_synth, m_font->fluidFont );
		delete_fluid_synth( m_synth );

		// New synth
		m_synth = new_fluid_synth( m_settings );
		m_fontId = fluid_synth_add_sfont( m_synth, m_font->fluidFont );
		m_synthMutex.unlock();

		// synth program change (set bank and patch)
		updatePatch();
		updateGain();
	}
	else
	{
		// Recreate synth with no soundfonts
		m_synthMutex.lock();
		delete_fluid_synth( m_synth );
		m_synth = new_fluid_synth( m_settings );
		m_synthMutex.unlock();
	}

	m_synthMutex.lock();
	if( engine::mixer()->currentQualitySettings().interpolation >=
			Mixer::qualitySettings::Interpolation_SincFastest )
	{
		fluid_synth_set_interp_method( m_synth, -1, FLUID_INTERP_7THORDER );
	}
	else
	{
		fluid_synth_set_interp_method( m_synth, -1, FLUID_INTERP_DEFAULT );
	}
	m_synthMutex.unlock();
	if( m_internalSampleRate < engine::mixer()->processingSampleRate() )
	{
		m_synthMutex.lock();
		if( m_srcState != NULL )
		{
			src_delete( m_srcState );
		}
		int error;
		m_srcState = src_new( engine::mixer()->currentQualitySettings().libsrcInterpolation(), DEFAULT_CHANNELS, &error );
		if( m_srcState == NULL || error )
		{
			qCritical( "error while creating libsamplerate data structure in Sf2Instrument::updateSampleRate()" );
		}
		m_synthMutex.unlock();
	}
	updateReverb();
	updateChorus();
}
Exemple #4
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);

	if (ConfMan.getBool("fluidsynth_chorus_activate")) {
		fluid_synth_set_chorus_on(_synth, 1);

		int chorusNr = ConfMan.getInt("fluidsynth_chorus_nr");
		double chorusLevel = (double)ConfMan.getInt("fluidsynth_chorus_level") / 100.0;
		double chorusSpeed = (double)ConfMan.getInt("fluidsynth_chorus_speed") / 100.0;
		double chorusDepthMs = (double)ConfMan.getInt("fluidsynth_chorus_depth") / 10.0;

		Common::String chorusWaveForm = ConfMan.get("fluidsynth_chorus_waveform");
		int chorusType = FLUID_CHORUS_MOD_SINE;
		if (chorusWaveForm == "sine") {
			chorusType = FLUID_CHORUS_MOD_SINE;
		} else {
			chorusType = FLUID_CHORUS_MOD_TRIANGLE;
		}

		fluid_synth_set_chorus(_synth, chorusNr, chorusLevel, chorusSpeed, chorusDepthMs, chorusType);
	} else {
		fluid_synth_set_chorus_on(_synth, 0);
	}

	if (ConfMan.getBool("fluidsynth_reverb_activate")) {
		fluid_synth_set_reverb_on(_synth, 1);

		double reverbRoomSize = (double)ConfMan.getInt("fluidsynth_reverb_roomsize") / 100.0;
		double reverbDamping = (double)ConfMan.getInt("fluidsynth_reverb_damping") / 100.0;
		int reverbWidth = ConfMan.getInt("fluidsynth_reverb_width");
		double reverbLevel = (double)ConfMan.getInt("fluidsynth_reverb_level") / 100.0;

		fluid_synth_set_reverb(_synth, reverbRoomSize, reverbDamping, reverbWidth, reverbLevel);
	} else {
		fluid_synth_set_reverb_on(_synth, 0);
	}

	Common::String interpolation = ConfMan.get("fluidsynth_misc_interpolation");
	int interpMethod = FLUID_INTERP_4THORDER;

	if (interpolation == "none") {
		interpMethod = FLUID_INTERP_NONE;
	} else if (interpolation == "linear") {
		interpMethod = FLUID_INTERP_LINEAR;
	} else if (interpolation == "4th") {
		interpMethod = FLUID_INTERP_4THORDER;
	} else if (interpolation == "7th") {
		interpMethod = FLUID_INTERP_7THORDER;
	}

	fluid_synth_set_interp_method(_synth, -1, interpMethod);

	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();

	_mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
	return 0;
}