[ English | Español | Pyccκuú ]

μFMOD v1.24 for Unix/BSD (i386)

uFMOD is an XM player library written in assembly language. It's perfect for size- and speed-critical applications, click free, highly reliable, easy to use, open source, multiplatform. File and direct memory playback supported. It is able to play even damaged and non-standard XM tracks. Usage examples available for the following compilers: GCC, Tcl/Tk, FreePascal, FASM, NASM and GAS.

Unix/BSD port has been tested with FreeBSD and Linux (there's a separate Linux port available with many additional features). However, it should run on most other Unix-like operating systems, assuming the following requirements are met:

  1. An x86 CPU or VM compatible with i386 or later.
  2. Support for the ELF executable and linkable object format.
  3. Standard C library (aka LIBC) v3 or later.
  4. OSS-compatible sound drivers.
If your machine meets the above requirements but uFMOD doesn't run properly, let us know (check the contact information near the bottom of this page).

Getting started

First thing to do after downloading ufmod-X.YZ-unix.tar.gz and unpacking it's contents to a suitable directory of your choice is linking the utilities (you will most probably need them later). Just cd to the directory where you've just untared uFMOD and issue the following commands:

   gcc -nostdlib eff.o -lc -o eff
   gcc -nostdlib xmstrip.o -lc -o xmstrip
Invoking the linker ld directly instead of gcc is not recommended. If you get any errors linking the utilities, you can download the complete source code via SVN (see the link below) and recompile them. You can even skip this stage at all if you don't need the utilities. Check the following section for a detailed description of what EFF and XMStrip are used for.


There are 2 freeware tools currently available to use along with uFMOD: XMStrip and Eff. Both utilities are terminal-based, but there are also graphical (GUI) frontends available made in Tcl/Tk: effgui and xmstripgui respectively. On most machines you can just doubleclick the executable script file in order to launch Tcl/Tk and start executing the given script, assuming Tcl/Tk has been properly installed. Sometimes an explicit wish ./<script-name> command should be entered in a terminal emulator or a more complex set of steps be performed in order to make it work. For instance, in FreeBSD you have to specify the version of Tk, like this: wish8.5 ./<script-name>, assuming you have Tk8.5 installed. A better alternative whould be making wish a symbolic link to the latest Tk release installed. GUI is rather self-explanatory. Next, we'll explain the terminal interface.

 SVN  Complete source code available 

XMStrip expects an XM filename on input, repacks the file contents to make it smaller, without losing sound quality. What it does exactly is removing overhead data (dummy instruments, patterns and junk metadata), stripping reserved and currently unused bytes, repacking pattern data. Typing ./xmstrip produces the following output:

 USAGE:  xmstrip [options] file [output]
         file   - input file name.
         output - optional output file name.          
  -c - clean only (don't strip)
 When [output] is not specified, XMSTRIP
 attempts to overwrite the input. If file
 name contains spaces, enclose it in "".

Keep in mind, that other XM players whould probably reject a 'stripped' XM file. The -c option is useful to 'recover' such a stripped file or just clean a regular file you mean to play with another XM player.

Eff is useful for advanced users, willing to squeeze every single byte out of their applications. The general idea is to extract only those features you do mean to use in your application, recompile the uFMOD library from source and obtain the smallest possible footprint. So, let's start opening a terminal and typing ./eff to request the following prompt:

 USAGE:  eff [options] file
         file - input file name
          /Dm - generate a masm32/tasm dump
          /Dd - generate a Pascal (Delphi) dump
          /Dc - generate a C/C++ dump
          /Ds - generate an RCDATA resource dump
          /Di - disable infoAPI:
                    uFMOD_GetStats, uFMOD_GetRowOrder,
                    uFMOD_GetTitle and uFMOD_GetTime
          /Dp - disable uFMOD_Pause, uFMOD_Resume
                    and XM_SUSPENDED
          /Dv - disable volume control
          /Dj - disable Jump2Pattern
          /Df - disable loading XM from file
          /Dl - disable XM_NOLOOP
          /M  - mark & clear unused chunks of
                data in a masm32/tasm compatible dump

As you can see, the last parameter is expected to be a filename, specifying the XM file you plan to use in your application. Additional options:

On success, Eff produces a file EFF.INC and a hex dump, if requested. Some examples (all correct):

eff /Dmpvjfl /M example.xm
eff /M /Dm /Dp /Dv /Dj /Df /Dl example.xm
eff -M -Dmpvjfl example.xm

The above commands produce an assembly dump with all the 'holes' properly outlined and cleared by default. The EFF.INC header contains the XM effects actually used in the given XM file and some additional flags to disable pause/resume, volume control, Jump2Pattern, loading files and XM_NOLOOP. Copy EFF.INC to ufmodlib/src/ and recompile the library (check the following section for a quick guide). Enjoy your own extremely optimized uFMOD build, but keep in mind that it contains a subset of XM effects. So, it will play normally only the given XM file!

Compiling the library

Recompiling the library sources is required after using Eff or to enable some special features in a regular build (check the Options table below). Some people might consider modifying the source code of the library just to practice assembly programming or for any other reason. Well, the following information is intended only for those interested in the subject.

The complete source code is included in ufmodlib/src/:

Once you are done modifying the uFMOD sources, next step is compiling them. Pick one of the makefiles located in ufmodlib/ depending on whether you are compiling the library in Unix or crosscompiling it in Win32.

MakefileGNU Make
make.batThis is a Win32 batch file for crosscompiling uFMOD for Unix.

Now open the selected make or batch file in a plain text editor. Everything contained between the following lines:

is configurable. An additional step should be taken when crosscompiling in Win32 (skip the following frame when compiling in Unix):
Check the Pathes section. There is an option saying:
If you do have NASM installed, make sure the above path points exactly to where nasmw.exe is located. Let's say NASM has been installed to D:\TOOLS\NASM. Then, you'd have to modify the above entry as follows:
Not all of the pathes are used to recompile the library. For example, if you prefer using FASM as your default assembler, you don't need to setup the NASM path. The UF_ARCH path contains a filename:
ar.exe is supposed to be in one of the directories that are listed in the PATH environment variable. If not, you'd have to modify the above entry. Let's say C:\Program files\BlitzMax\bin\ar.exe is the correct path. So, let's modify the UF_ARCH variable:
SET UF_ARCH=C:\Program files\BlitzMax\bin\ar.exe
Make sure all the pathes actually required to build the library have been set correctly.
Then, procede modifying the available options, according to the following table:

UF_RAMPThis option controls the volume ramping (interpolation) mechanism. Ramping is intended to suppress audible clicks, but sometimes it may introduce distortion. STRONG is the default value recommended for most applications. It detects volume changes during sample playback and softens them using a 32 stage linear ramp. WEAK uses 16 linear stages only. It is less effective than STRONG, but distortion is also less likely to happen. NONE doesn't perform ramping at all. No ramping = no distortion, but most XM samples will produce clicks, unless the samples are well balanced enough.NONE, WEAK, STRONG
UF_FREQMixing rate (in Hz). 44100 was the default value until uFMOD v1.20. It is useful only for compatibility with QEMU-embedded Unix/Linux boxes. 48KHz actually sounds better on most soundcards and uses less system resources. So, 48000 is the new default value recommended for most applications. 22050 is supported just for fun (rememder the Amiga days...)22050, 44100, 48000
UF_FMTProduce a static library (lib*.a) or a plain object file (*.o). FreePascal example uses a static library, while all other examples use plain object files.OBJ, LIB
UF_ASMAssembler. Yes, the uFMOD library is compilable with either FASM or NASM. Choose your favorite :)FASM, NASM
UF_MODENORMAL is the default value. Nothing special. UNSAFE disables checking an XM track for validity at load time. When you are sure all XM tracks are valid (you can use Eff or XMStrip to verify an XM file), you can recompile uFMOD in UNSAFE mode to reduce the file size and maximize the loading speed. Keep in mind that a damaged XM file can actually crash uFMOD while in UNSAFE mode! Recompiling uFMOD in BENCHMARK mode makes available a performance counter, which tells the exact amount of clock cycles used to produce about 21 ms of sound @ 48KHz. This mode is meant to be used for comparing the performance of different uFMOD versions. BENCHMARK mode is available only in C, FASM, NASM and GAS.NORMAL, UNSAFE, BENCHMARK

When using the Makefile, just run Make to compile the library: make   or   make -f MakeBSD. Run the make or batch file to build the library. That's all!


Compiler-specific usage examples are provided in separate directories.
TclTkTcl/TkSimple graphical XM player.
GccGNU CA GTK example showing how to use the Jump2Pattern feature is available here. It uses a composite XM tracked by Kim (aka norki). For more information on composite XM files and the Jump2Pattern feature, refer to the following section.
FasmFlat Assembler
NasmNetwide Assembler
GasGNU Assembler
FreePascalFreePascalTested with FPC v2.0.4.

Reducing the executable file size

Use Eff to optimize the library and make it smaller.

When embedding the XM track directly into the executable or attaching it as a raw binary resource, it's sometimes worth it trying to optimize the XM itself. Modplug Player features ADPCM compression, which makes the XM somewhat smaller, but it's a lossy compression! Use XMStrip for lossless (in terms of sound quality) size optimization.

If you're sure all XM tracks your application is going to use are valid (not damaged or otherwise modified), rebuild the library in UNSAFE mode.

Use strip and sstrip to remove unnecessary data introduced by the compiler/linker. Whole sections may sometimes be removed without breaking the executable.

Packers, such as UPX, make executables smaller.

Take a look at "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux" by Brian Raiter for additional size optimization tips (most tips are suitable for FreeBSD as well).

Let's talk some more about optimizing the XM file size:

An advanced XM file size optimization method involves merging various XM tracks in a single composite file. Since you can share the instruments in a composite file, the resulting file size could be a lot smaller than the sum of the separate file sizes before merging. Even without sharing the instruments it will be smaller because of the XM file header being declared only once. Let's see an example with 3 XM files:

File 1 : XM1_HEADER P11 P12 P13     I11 I12
File 2 : XM2_HEADER P21 P22 P23 P24 I21 I22 I23 I24
File 3 : XM3_HEADER P31             I31
Legend: XMn_HEADER is the header of the n-th XM file. Pni is the i-th pattern of the n-th XM file. Ini is the i-th instrument of the n-th XM file.

First, let's merge them in a single file without sharing the instruments:

File 4 : XM4_HEADER P11 P12 P13 P21 P22 P23 P24 P31 I11 I12 I21 I22 I23 I24 I31
Now, let's say I12 is very similar or even equal to I23 and I24 is the same as I31. So, we can modify P2n to make them use I12 instead of I23 and P31 to use I24, so that we can remove I23 and I31:
File 4 : XM4_HEADER P11 P12 P13 P21 P22 P23 P24 P31 I11 I12 I21 I22 I24
You'll have to modify the looping and pattern jumping commands and the references to instruments in "files" 2 and 3. Obviously, you can merge just 2 files or more than 3. XM file format limits the amount of patterns and instruments in a single file. That's the general idea. You'd have to learn how to use a tracker in order to perform this kind of optimization. Once you've got all your files merged, you can issue a single uFMOD_PlaySong function call and trigger all the "files" with uFMOD_Jump2Pattern. For example, uFMOD_Jump2Pattern(3) will start playing the 2nd "file", uFMOD_Jump2Pattern(7) will launch the 3rd and uFMOD_Jump2Pattern(0) will reset to the first "file". The exact indexes depend on your pattern layout. Gcc/ contains a practical example.

Using Jump2Pattern has another advantage: switching is done much faster (practically in no time), as opposed to stopping and reloading a track. So, you can use this feature when quickly switching the background music is required.


Q: Is uFMOD free for any type of use? Even commercial?
A: Yes, currently it is.

Q: Where can I get XM files from?
A: Try visiting The Mod Archive. They have a huge archive of free tracker music in XM, IT, S3M and MOD format. You can use Open Modplug Tracker to convert IT, S3M and MOD tracks to XM format without apparent degradation. There are many talented composers out there in the web sharing their music at no cost. Just don't forget the copyright!

Q: Is uFMOD related in some way to Firelight Technologies® FMOD and miniFMOD sound libraries?
A: Not any more. Up until 2004 uFMOD was based on the latest miniFMOD public source code release. Since then, library sources had been completely rewritten, introducing many new features. So, uFMOD is in no way representative of FMOD and miniFMOD sources.

Q: Some XM player libraries claim to add only N kilobytes to the executable file. How many Kb does uFMOD add exactly to the executable's size?
A: It is impossible to tell an exact value, because it depends on library features used (especially, when using the Eff utility), test program code layout, XM file size (when embedding the XM into the executable file). It also depends on the linker options. Just build one of the included examples and check it's size.

Q: Where can I get the official XM file format specification from?
A: No official and up to date specification exists. However, you can take a look at "The Unofficial XM File Format Specification: FastTracker II, ADPCM and Stripped Module Subformats". This document covers most aspects of the original XM file format and all the non-standard extensions currently supported by uFMOD. ModePlug's public source code (it's C++) also serves as reference material on module file formats.

Thanks go out to

antarman, Barracuda, bogrus, chris_b, cresta, dododo, flaith, Four-F, GL#0M, norki, q_q, SofT MANiAC, S_T_A_S_, voodooattack and yoxola for reporting bugs, requesting interesting features, submitting usage examples and otherwise helping us improve uFMOD.

[WASM.RU] and SourceForge.net for support and hosting.


uFMOD sources, binaries and utility programs © 2005 - 2007 Asterix and Quantum.
All rights reserved.

Sample tunes:

Found a bug? Got a question or a suggestion?
Starting to develop a cool application using uFMOD? Please, let us know: ufmod@users.sf.net