Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Loading a .dat file. Pat2dat and soundfonts.

This thread is locked; no one can reply to it. rss feed Print
Loading a .dat file. Pat2dat and soundfonts.
Tony A
Member #12,673
March 2011

Hello,

I have been reading about .dat files and their use in Allegro. I am a little confused about the .dat role in loading and reading soundfonts in Allegro.

Am I correct in my understanding, that I cannot use (load and read) a .sf2 (soundfont) file directly in Allegro? And that if you wish to use a .sf2 file, it must first be converted or "prepared" via the pat2dat utility?

Does the pat2dat utility convert the .sf2 file into a .pat file, and then wraps that .pat file (or files) into a .dat all at once like; .sf2 --> .pat --> .dat

I used pat2dat last night and it produced a "patches.dat" file and a .cfg file from my soundfont (.sf2 file).

Now that I have this "patches.dat" how can I use it in my program to read and play music?

I have:

//define objects in the datafile.
//I name the file (MACHINE_SF2) at 0 position. (0 indicates the first item contained inside the .dat file).
//Is my (above) assumption correct?
#define MACHINE_SF2 0

DATAFILE *data;
//load the datafile.
//My patches.dat file is in my media folder.
data = load_datafile("media/patches.dat");

//My patches.dat file seems to load correctly when tested with;
if (!data) {
allegro_message("Could not load data file.", allegro_error);
return 1; //exit to DOS if error.
}

Now that the patches.dat file seems to be loaded, how do I play the .pat file contained in it?

data[MACHINE_SF2].dat //Does this extract the .pat file defined above?

Thank you for any clarifications or references anyone might be able to offer me.
Tony

Audric
Member #907
January 2001

In the allegro configuration file : allegro.cfg
you must make the variable "patches" point to the patches.dat that you generated.
Then in your code, install_sound(DIGI_AUTODETECT, MIDI_DIGMID, NULL)
After that, all the MIDI functions in allegro (these) will use the samples from this file.

Note that this system is only useful if the samples sound much better than your soundcard's MIDI instruments. The "cost" is that allegro will play (and mix) one digital sound for each note being played, so it takes a bit of CPU time, especially if you start playing super complex music with many sounds at the same time.

Allegro has an example program miditest.c in "tests/" directory of the source distribution, it simulates a kind of piano. It can be helpful for testing the various instruments from your sound font. Be sure to replace the install_sound() line, because it will certainly have MIDI_AUTODETECT by default.

Tony A
Member #12,673
March 2011

Hello,

Thank you for the info and link, I sincerely appreciate it.

Tony

Audric
Member #907
January 2001

I haven't used allegro's DIGMID since I upgraded from a Soundblaster 16 (FM synthesis) to a Sound Blaster Live, almost 10 years ago. I'm even surprised that there are bad enough soundcards nowadays that make DIGMID useful.
The comment in your source code "//exit to DOS if error." is a hint that you're using some pretty old hardware, or a very old and infamous book (either the Necronomicon, or the other one whose name escapes me at the moment).
I hope you're not relying on very old advice - which used to be good, but no longer relevant.

Thomas Fjellstrom
Member #476
June 2000
avatar

Audric said:

I'm even surprised that there are bad enough soundcards nowadays that make DIGMID useful.

Sure, most machines have integrated audio chips which do NOT do hardware midi, or even wavetable type midi like the sblive. The only choice on such systems is DIGIMID or somehow making use of timidity++ on linux, or the softsynths on windows.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Tony A
Member #12,673
March 2011

I believe I am using old info. I was looking for a solution to use soundfonts in my program, rather than wav & mp3 samples. The only info I could find was about using pat2dat and GUS patches with Allegro.

With midi I could define the music, but not the sound (on someone else's computer). I would like to be able to define both, have the music sound exactly the same no matter what system or sound card.

Any ideas what could be a good, modern solution?

Thanks again,
T

Thomas Fjellstrom
Member #476
June 2000
avatar

DIGIMID is ok if you don't mind midi music. These days though people tend to use ogg voribs or mp3 for sounds and music.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Audric
Member #907
January 2001

For this, you'll need to distribute the patches.dat together with the game, so be careful of file size. Instead of providing a complete allegro.cfg that might be unsuitable for the end-user, I think you can provide a minimalistic .cfg file with only the line "patches=./patches.dat", and in your code, call override_config_file() to load it. (Click for details)
You may need to call it before install_allegro(), I'm not sure and I couldn't find this piece of info in the manual.

An alternative for distributable music that sounds the same on all machines is MOD music: .MOD, .S3M, .IT, .XM ... The common part of all these formats is that they contain the instrument samples as well as the musical track and effects. There are plenty of free composition software, a huge collection of free(*) music in modarchive.org, and several libraries allow playback in allegro programs, like DUMB, FMod, JGMOD...

Tony A
Member #12,673
March 2011

"An alternative for distributable music that sounds the same on all machines is MOD music: .MOD, .S3M, .IT, .XM ... The common part of all these formats is that they contain the instrument samples as well as the musical track and effects."

This is what I have been thinking. I don't know anything about MOD music, but it sounds like just what I need.

Thanks again for the info! (I'll be looking into this "MOD music" now.)

T.

Go to: