SDL Mixer X

SDL Mixer X - SDL Mixer eXtended ( SDL2_mixer_ext ) - a fork from SDL mixer version 2.0 which an extension for Simple DirectMedia Layer (SDL) library which giving a complex audio functions, mainly for sound mixing.

This part appending to SDL additional functions which are giving able to play more sound and music formats.

Because of original SDL Mixer had some issues, Wohlstand has been forked it to resolve them and also implement a new features to it.

SDL Mixer X used in the Moondust Project as part of default audio engine and also included by Wohlstand and Kevsoft into the LunaLua to replace the MCI audio engine to take able play more music formats inside SMBX. SMBX-38A also uses SDL Mixer X since 1.4.2 version. Because that built on VisualBasic 6, VB6 Wrapper has been made. Assembly with VB6 binding support (SDL2MixerVB.dll) has statically linked SDL2 library, but with Audio-only support, other SDL subsystems are not binded yet.

Music Formats
SDL Mixer X have support for playback for next formats which can be played in the music stream:

Standard music formats

 * WAV — Microsoft PCM, Uncompressed audio (hardcoded), has loop support (by SMPL chunk).
 * VOC — Creative Labs Audio File (hardcoded).
 * MP3 — MPEG-2 Layer 3, Lossy data compressed audio (libMAD).
 * OGG — OGG Vorbis, Lossy data compressed audio (libOGG, libVorbis), has loop support (by LOOPSTART/LOOPEND/LOOPLENGTH meta tags, also LOOP_START and LOOP_END).
 * OPUS — OPUS, Lossy data compressed audio (libOpus) (Support was added Since June 18, 2018), has loop support (by LOOPSTART/LOOPEND/LOOPLENGTH meta tags, also LOOP_START and LOOP_END).
 * FLAC — Free Lossless Audio Codec, Loss-less compressed (libFLAC), has loop support (by LOOPSTART/LOOPEND/LOOPLENGTH meta tags, also LOOP_START and LOOP_END (Support for FLAC loop was added Since November 17, 2019)).
 * MIDI — Music Instrument Digital Interface, commands list (libADLMIDI, Timidity (hardcoded), Fluidsynth (Since March 29, 2021) ), has loop support (by loopStart/loopEnd markers and by CC111 like RPG Maker)

Extra music formats

 * XMI — ADLMIDI and OPNMIDI exclusive. MIDI-like format used in AIL library and was widely used in many DOS games. Has loop support (by CC116 and CC117).
 * MUS — ADLMIDI and OPNMIDI exclusive. MIDI-like format used in DMX library and known by Doom and Raptor game series are used DMX sound library.
 * CMF — ADLMIDI exclusive. Creative Music Format, A MIDI file mixed with OPL2 FM instruments, widely used in many DOS games.
 * IMF — ADLMIDI exclusive. Id-Software Music File. Supported IMF-files which have length chunk in begin and uses 700Hz of the ticks rate.

Game music emulators formats
All Game Music Emulators formats are provided with GME library.


 * AY — ZX Spectrum/Amstrad CPC
 * GBS — Nintendo Game Boy
 * GYM — Sega Genesis/Mega Drive
 * HES — NEC TurboGrafx-16/PC Engine
 * KSS — MSX Home Computer/other Z80 systems (doesn't support FM sound)
 * NSF/NSFE — Nintendo NES/Famicom (with VRC 6, Namco 106, and FME-7 sound)
 * SAP — Atari systems using POKEY sound chip
 * SPC — Super Nintendo/Super Famicom
 * VGM/VGZ — Sega Master System/Mark III, Sega Genesis/Mega Drive,BBC Micro

Tracker music formats
All tracker music formats are provided with libXMP and libModPlug libraries.
 * 669 — Composer 669, Unis 669
 * AMF — DSMI Advanced Module Format
 * AMF — ASYLUM Music Format V1.0
 * APUN — APlayer
 * DSM — DSIK internal format
 * DBM — DigiBooster Pro (libXMP)
 * DTM — Digital Tracker (libXMP)
 * DIGI — DIGI Booster (libXMP)
 * EMOD — Quadra Composer (libXMP)
 * FAR — Farandole Composer
 * FLX — Flextrax (libXMP)
 * FNK — Funktracker (libXMP)
 * GDM — General DigiMusic
 * IT — Impulse Tracker
 * IMF — Imago Orpheus (Support has been repaired with using of libXMP since March 10, 2019)
 * LIQ — Liquid Tracker (libXMP)
 * MDL — Digitrakker (libXMP)
 * MOD — 15 and 31 instruments
 * MED — OctaMED
 * MTM — MultiTracker Module editor
 * MTN — ST 2.6, Ice Tracker (libXMP)
 * MGT — Megatracker (libXMP)
 * OKT — Amiga Oktalyzer
 * PTM — Poly Tracker (libXMP)
 * RTM — Real Tracker (libXMP)
 * S3M — Scream Tracker 3
 * STM — Scream Tracker
 * STX — Scream Tracker Music Interface Kit
 * SFX — Amiga SoundFX (libXMP)
 * ULT — UltraTracker
 * UNI — MikMod
 * WOW — Mod's Grave (libXMP)
 * XM — FastTracker 2

SFX Formats
SDL Mixer X have a support for playback for next sound effects which can be preloaded into memory played in difference channels with mixing:
 * Almost all formats of music — since SDL Mixer X 2.0, almost any music format also can be used as SFX
 * WAV — Microsoft PCM, Uncompressed audio
 * VOC — Creative Labs Audio File
 * OGG — OGG Vorbis, Lossy data compressed audio
 * FLAC — Free Lossless Audio Codec, Loss-less compressed
 * MP3 — MPEG-2 Layer 3, Lossy data compressed audio (Note: before update since February 2 2016 MP3 chunks are not supported!)

Differences and improvements in comparison to original SDL Mixer

 * Added much more music formats (Such a game music emulators)
 * Added support of the loop points in the OGG files (via LOOPSTART and LOOPEND (or LOOPLENGTH ) meta-tags)
 * In the Modplug module enabled internal loops (tracker musics with internal loops are will be looped rightly)
 * Added ability to append custom config path for Timidity synthesizer
 * Forked version now has ADLMIDI and OPNMIDI midi synthesizers together with Native MIDI, Timidity and Fluidsynth. ADLMIDI is a synthesizer based on Yamaha YMF262 OPL3 FM Synthesizer chip emulation. OPNMIDI is a synthesizer based on Yamaha YM2612 OPN2 FM Synthesizer chip emulation.
 * Added new API functions
 * Ability to redefine Timidity patches path. So, patches folders are can be stored in any place!
 * Added functions to retrieve some meta-tags: Title, Artist, Album, Copyright
 * Added ADLMIDI Extra functions: Change bank ID, enable/disable high-level tremolo, enable/disable high-level vibrato, enable/disable scalable modulation
 * Added chunk play functions with initial volume value
 * Own re-sampling implementation which avoids glitches caused with inaccurate re-sampler implementation from SDL. Removed, no more needed as SDL2 since 2.0.8 has much better resampler.
 * Added support of extra arguments in the tail of the file path, passed into Mix_LoadMUS function.
 * Added ability to build shared library in the stdcall mode with static linking of libSDL on Windows to use it as independent audio library with other languages like VB6 or .NET.
 * Improved support for WAV and AIFF files, addedd support for more sample formats like PCM24, PCM32, PCM64, Float32, Float64, ALAW, and uLAW.

Path arguments
SDL Mixer X has the support of additional path arguments in the Mix_LoadMUS function to allow changing of some decoding properties.

Game music emulators formats

The first argument - an integer from 0 to n - a number of the track from multi-track file formats like NSF, NSFE, HES, GBS, etc.

Example: mymusic.nsf|21

Since October 15, 2019 the syntax has been extened and now it supports addional arguments: mymusic.nsf|21;g=1.0;t=1.0 All arguments after the first integer are optional. The leading integer is required, even it's a single-track file. The last argument must be closed with semicolon.
 * t= - Initial tempo factor (1.0 is the default value, accepting positive floating-point number values, for example, `t=1.75;`), increase or decrease the initial tempo of the song.
 * g= - Gain factor (1.0 is the default value, accepting positive floating-point number values, for example, `g=1.75;`), increase or decrease the volume level of the song. Use it to increase the volume of too silent songs, or decrease the volume of too loud songs.

MIDI

Accepts a list of letter-marked integer arguments separated by semicolons.

Example 1: mymusic.mid|s0;b62;t0;v0;a0;m0;t=1.0;g=2.0;x=/path/to/bank1.wopl;

Example 2: mymusic.mid|s4;r1;rr0.2;rd0.4;rw0.9;rl0.8;c1;cn10;cl4.2;cs3.5;p256;t=1.0;g=1.0;x=/path/to/bank1.sf2&/path/to/bank2.sf2&/path/to/bank3.sf2;

All arguments are optional. The last argument must be closed with semicolon.
 * s - Synthesizer type:
 * 0 - ADLMIDI, emulated OPL3 (YMF262) synthesizer with loop tags and System Exclusive Messages support. Working by Default. (Recorded examples to listen to are presented here). OPL3 chip was widely used on PC sound cards in 80/90'th years.
 * 1 - Timidity, requires patches bank in the "timidity" folder in the application path (can be customized with "MIX_Timidity_addToPathList(const char*path)" function called before library initialization) **
 * 2 - Native MIDI, uses the default operating system MIDI interface. Don't use it on Windows (MSGS only) due to Microsoft side bug that may mute sound of entire app (details below) .***
 * 3 - OPNMIDI, emulated OPN2 (YM2612) synthesizer with loop tags and System Exclusive Messages support. OPN2 chip is used on the Sega MegaDrive / Genesis game console. This synthesizer has been added since May 14, 2017.
 * 4 - FluidSynth, the WaveTable MIDI synthesizer with SoundFont banks support, has the support for loop tags support. This synthesizer has been added since March 29, 2021. Doesn't support System Exclusive Messages.

General flags
 * t= - (ADLMIDI, OPNMIDI and FluidSynth) Initial tempo factor (1.0 is the default value, accepting positive floating-point number values, for example, `t=1.75;`), increase or decrease the initial tempo of the song. Don't confuse with `t0` and `t1` which is different.
 * g= - (ADLMIDI, OPNMIDI and FluidSynth) Gain factor (2.0 is the default value, accepting positive floating-point number values, for example, `g=1.75;`), increase or decrease the volume level of the song. Use it to increase the volume of too silent songs, or decrease the volume of too loud songs.

ADLMIDI and OPNMIDI
 * b - (ADLMIDI) Set bank ID (look for available banks list into Moondust Music Player application to preview them). Default is 58.
 * t - (ADLMIDI) Deep tremolo (1 or 0), increase the amplitude of tremolo effect for instruments that are using tremolo OPL flag. Default 1. Don't confuse with `t=` which is different.
 * v - (ADLMIDI) Deep vibrato (1 or 0), increase the amplitude of vibrato effect for instruments that are using vibrato OPL flag. Default 1.
 * a - (ADLMIDI) Enables AdLIB drums mode (1 or 0), enables legacy OPL2 drums mode. Default 0.
 * m - (ADLMIDI) Enables scalable modulation (1 or 0), Allows dynamic scaling of the modulator result with volume. Default 0.
 * c - (ADLMIDI and OPNMIDI) Count of chip emulators are allowing to excite limit of voice channels. Default 4. Allowed value from 1 to 100.
 * f - (ADLMIDI) Count of four-operator channels between all chip emulators (6 channels maximum per every chip. For example, you have used 2 chips, you can have 12 four-op channels maximum).
 * l - (ADLMIDI and OPNMIDI) Volume scaling model code (0 - auto, 1 - Generic, - 2 OPL3-Native, 3 - DMX, 4 - Apogee, - 5 - Win9X-like) - an algorithm to scale a volume level, affects music expressionism.
 * r - (ADLMIDI and OPNMIDI) Use full-ranged CC74 Brightness MIDI controller (1 or 0). Default 0.
 * p - (ADLMIDI and OPNMIDI) Enable full-panning stereo support (1 or 0). Default 1.
 * e - (ADLMIDI) Choose OPL3 emulator: 0 - Nuked OPL3 (Very accurate, may lag on older CPUs), 1 - Nuked OPL3 1.7.4 that was optimized by Troosh, and 2 - DosBox 0.74 (Well-accurate, fastest).
 * e - (OPNMIDI) Choose OPN2 emulator: 0 - Mame YM2612 (Well-accurate, fast), 1 - Nuked OPN2 (Very accurate, requires VERY powerful CPU. Suggested to use up to 2 chips max with it), 2 - GENS 2.10 (Very outdated, inaccurate, but fastest)
 * x= - (ADLMIDI and OPNMIDI) Load custom bank file by absolute path (WOPN bank for OPNMIDI or WOPL for ADLMIDI). Accepting strings without quotes, for example, `x=/path/to/bank/file.wopn;`

FluidSynth (Since March 29, 2021)


 * r - (FluidSynth) Enable or disable the reverb effect: 0 - disabled, 1 - enabled
 * rr - (FluidSynth) Reverb room size value (0.0-1.0)
 * rd - (FluidSynth) Reverb damping value (0.0-1.0)
 * rw - (FluidSynth) Reverb width value (0.0-100.0)
 * rl - (FluidSynth) Reverb level value (0.0-1.0)
 * c - (FluidSynth) Enable or disable the chorus effect: 0 - disabled, 1 - enabled
 * cn - (FluidSynth) Chorus voice count (0-99, CPU time consumption proportional to this value)
 * cl - (FluidSynth) Chorus level (0.0-10.0)
 * cs - (FluidSynth) Chorus speed in Hz (0.1-5.0)
 * cd - (FluidSynth) Chorus depth (max value depends on synth sample-rate, 0.0-21.0 is safe for sample-rate values up to 96KHz)
 * ct - (FluidSynth) Chorus waveform type: 0 - Sine, 1 - Triangle
 * p - (FluidSynth) Define the allowed polyphony (8-512)
 * x= - (FluidSynth) Load custom SoundFont files by absolute path. Accepting strings without quotes, for example, x=/path/to/bank/file.sf2;. You can specify multiple SoundFont files by using an ampersand separator: x=/p/file1.sf2&/p/file2.sf2&/p/filen.sf2;

Preview examples of difference between ADLMIDI flags

Special engine-specific values
Since September 10, 2021, development builds for TheXTech have the support of engine exclusive arguments intended to use the functionality of the engine itself.


 * ym=x; - Set the track (or channel) number for the Yoshi mode. That means the selected track/channel of the chiptune, tracker, or MIDI song will be muted by default while the player doesn't ride Yoshi. When a player gets Yoshi riding, the selected track gets resumed. Example: . Note: track number count starts with 0.

Macros
Since March 31, 2020, development builds for TheXTech, Moondust Editor, and Moondust Engine has the support for the macros in the path arguments. They allow you to specify the relative path to a certain file (such as a WOPL/WOPN bank file, or the SoundFont, depending on the synthesizer used):


 * {e} - The absolute path to the current episode root.
 * {d} - The absolute path to the current level/world data directory.
 * {r} - The absolute path to the config-pack default music root.

Example: mymusic.mid|s0;b62;t0;v0;a0;m0;t=1.0;g=2.0;x={e}bank1.wopl;

Projects using the MixerX library
There are some known projects that using this library. That means, all formats and the rest of MixerX features supported by this library, will work with those projects in a condition the library is up to date.


 * Moondust Project (formerly known as PGE Project) - the WIP game engine and the development kit for it. The Moondust Devkit is also often combined with other projects while the main engine is still in development.
 * Moondust Engine - The main runtime engine of the Moondust Project, still in development.
 * Moondust Editor - The level and world map editor. Is part of the Moondust Development Kit.
 * Moondust Music Player - The simple music player for music testing out of the game, for example, to verify the work of loop points or other things. Is part of the Moondust Development Kit.
 * LunaLua-SMBX - The SMBX game modded using the LunaLua hacking library.
 * Super Mario Bros. X2 - is a collaborative, open-source project to improve and expand upon the original SMBX, the successor of the LunaLua-SMBX.
 * Super Mario Bros. X by 38A - is a Mario fan game engine, written by 5438A38A as an unofficial successor to the original Super Mario Bros. X by Redigit.
 * TheXTech - it's a platform game engine written in C++, is a full port of the source code of SMBX 1.3 which was originally written in Visual Basic 6.

Links

 * SDL Mixer X documentation, based on original SDL_mixer documentation
 * Official documentation of original SDL Mixer library API
 * Source code of a forked SDL Mixer version by Wohlstand (SDL Mixer X) (Building with CMake).