[ English | Español | Pyccκuú ] |
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: FASM, MASM32 and NASM.
KolibriOS port should run correctly on any PC meeting the following requirements:
KolibriOS is an operating system written is assembly language. That's why it is so small and extremely fast. It is very powerful as well, as you've probably found out already. That's also uFMOD's spirit ;)
Most of the tasks described below can be accomplished directly in Kolibri. However, since many novice Kolibri coders prefer compiling their programs in Windows and then moving them to Kolibri for testing, we'll use crosscompilation here for the sake of universality.
There are 2 freeware tools currently available to use along with uFMOD: XMStrip and Eff. None of them has been ported to KolibriOS yet. So, you should pick one of the other platform-specific distros (Win32, Linux or Unix/BSD) and use XMStrip and Eff crossplatformly. No matter which platform-specific version you choose, both utilities have dual interface: terminal and GUI. 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. Running xmstrip /h
produces the following output:
USAGE: xmstrip [options] file [output] file - input file name. output - optional output file name. options: /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 for 'recovering' such a stripped file or just cleaning a regular file intended to be played with any other 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. Running eff /h
requests the following prompt:
USAGE: eff [options] file file - input file name options: /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:
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 src/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!
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 src/ufmodlib/src/:
Once you are done modifying the uFMOD sources, if you want to rebuild ufmod.obj, open src/ufmodlib/makeobj.bat in a plain text editor. Everything contained between the following lines:
rem *** CONFIG STARTand
rem *** CONFIG ENDis configurable. First, check the
Pathes
section. There is an option saying:SET UF_NASM=\nasmIf 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:SET UF_NASM=D:\TOOLS\NASMNot 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. 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:
Option | Description | Values |
UF_RAMP | This 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 128-stage linear ramp. WEAK involves only 16 stages. 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_FREQ | Mixing rate (in Hz). 48KHz is the value recommended for most applications. | 22050, 44100, 48000 |
UF_ASM | Assembler. Yes, the uFMOD library is compilable with various assemblers. Choose your favorite :) | MASM, NASM, FASM |
UF_MODE | NORMAL 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! When AC97SND mode is on, ufmod.obj will contain a special codec-like uFMOD version, used in Serge's AC'97 player. It features a different API (if interested, check the ufmod-plugin.h header file for additional info). | NORMAL, UNSAFE, AC97SND |
Run the batch file to build the library. That's all!
There are currently 2 examples available: mini and jmp2pat. Precompiled executables are located in bin/. None of the executables are packed/compressed.
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.
Packers, such as mtappack by diamond, make executables smaller. Anyway, to make things fair, the sample executables are not compressed at all!
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 I31Legend: 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 I31Now, 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 I24You'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. The jmp2pat example uses this feature.
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. For example, bin/mini is 4.768 bytes without compression.
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.
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.
Copyright
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 |