Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » ok... how do i load a .sf2 file in allegro 4?

This thread is locked; no one can reply to it. rss feed Print
ok... how do i load a .sf2 file in allegro 4?
jktech
Member #23,248
May 2022

i am using allegro 4.2.1 and i cant find anything that can load a patch for the midi i will play.. how do i set it up?
i have a roland d50 fantasia patch but i cant find any function to load patches.. there is load_patches(AL_CONST char *patches, AL_CONST char *drums) but it doesnt say if i should put a file name nor how i choose the sample in the patch.. what do i do?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

jktech
Member #23,248
May 2022

well... what i am have trouble with isnt playing the midi itself... but choosing a patch/instrument for the midi.
i will use wav till i can get midi then, thank you.
but if someone find a way just tell here, i would love to know how to change the midi instrument

Todd Cope
Member #998
November 2000
avatar

The information you seek is here. You'll also need to use the MIDI_DIGMID driver (install_sound(DIGI_AUTODETECT, MIDI_DIGMID, NULL)).

jktech
Member #23,248
May 2022

ok but like.. what are the functions to load the sf2 and to choose the patches for the midi? i have come to these links before... and i have installed midi and digi.. other works and does sound.. but i dont know how to choose instruments and load them with the midi or something

Todd Cope
Member #998
November 2000
avatar

You don't load the SF2, you have to convert it to a format Allegro understands. Quoted from the linked page:

Quote:

To convert a SoundFont into the patches.dat format, run “pat2dat -o patches.dat filename.sf2 -8”, and then copy the resulting patches.dat into either the same directory as your program, the location pointed to by the ALLEGRO environment variable, or the location specified by the “patches=” line in your allegro.cfg.

As for choosing instruments, that depends on what you're trying to do. If you are playing back MIDI files with play_midi(), that information needs to be changed in the MIDI file itself.

If you are generating MIDI information yourself and sending it to the MIDI device, you'll need to send the appropriate MIDI event for selecting the instrument (MIDI Program Change) before sending notes with midi_out().

If you are doing the latter, you'll need to call load_midi_patches() before sending note playback commands to ensure the patches are loaded before attempting to be played.

Chris Katko
Member #1,881
January 2002
avatar

I was going to say, isn't a soundfont file basically a set of software sound patches (the way a MIDI hardware ships with its own internal sound patches). So you can't play it. It's just (essentially) a zip file full of waves with some metadata.

Basically, you can take any MIDI "song" and play it with any number of different "soundfont"s and it'll sound different because one sound font's "piano" may sound different than another soundfont's "piano."

I honestly didn't know Allegro 4 had a soundfont tool, as soundfonts have been dead since forever ago except in niche music applications. I used those things on my Creative Labs Audigy 2 in Windows 2000/XP (terrible soundcard, terrible marketting hype only company, btw).

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: