Cody
Cody

Reputation: 1869

Android: Loading Custom Midi Instruments DLS files into Sonivox EAS

I'm creating an Android midi application using the popular billthefarmer driver package. With the help of Markus Kauppinen in this thread I was able to make my app generate and control midi events (note on, pause, etc) successfully.

As some of you may know, the default GM1 instruments included with the Sonivox EAS Android library don't sound the greatest. For my app, I desire a way to load custom instruments into the synthesizer, like specific models of a saxophone for example.

I've found this thread from 5 years ago of asking how to do the same thing I am. The answer to that question suggests using the EAS_LoadDLSCollection() method in the EAS.h library. Unfortunately, the programmer could only find a way to load custom DLS files into the library, not actually generate the playable instrument's soundfont(wrong term?) which notes can be played through.

Can anyone shed some light on how to load and use custom instruments in Android via it's native Sonivox EAS Midi library?

Upvotes: 34

Views: 1027

Answers (1)

Ajit Sharma
Ajit Sharma

Reputation: 185

load a DLS file code

#include <EAS.h>

// Assuming `pEASData` is the initialized EASData handle, and `dlsFilePath` is the path to your DLS file.
EAS_RESULT result;
EAS_HANDLE dlsHandle;
result = EAS_LoadDLSCollection(pEASData, dlsFilePath, &dlsHandle);
if (result == EAS_SUCCESS) {
    // DLS file loaded successfully, you can now play MIDI with custom instruments.
}

Sample code to load an SF2 soundfont in FluidSynth

#include <fluidsynth.h>

// Create the synthesizer and settings
fluid_settings_t* settings = new_fluid_settings();
fluid_synth_t* synth = new_fluid_synth(settings);

// Load the SF2 soundfont
int soundfont_id = fluid_synth_sfload(synth, "path/to/soundfont.sf2", 1);
if (soundfont_id == -1) {
    printf("Error loading soundfont\n");
}

// Play a MIDI note using the soundfont
fluid_synth_noteon(synth, 0, 60, 127);  // Channel 0, note 60 (Middle C), velocity 127

Check around this your problem will solve.

Upvotes: 0

Related Questions