2 * This source code is public domain.
4 * Authors: Kenton Varda <temporal@gauge3d.org> (C interface wrapper)
7 #ifndef MODPLUG_H__INCLUDED
8 #define MODPLUG_H__INCLUDED
15 typedef struct _ModPlugFile ModPlugFile
;
19 unsigned char Instrument
;
20 unsigned char VolumeEffect
;
23 unsigned char Parameter
;
25 typedef struct _ModPlugNote ModPlugNote
;
27 typedef void (*ModPlugMixerProc
)(int*, unsigned long, unsigned long);
29 /* Load a mod file. [data] should point to a block of memory containing the complete
30 * file, and [size] should be the size of that block.
31 * Return the loaded mod file on success, or NULL on failure. */
32 ModPlugFile
* ModPlug_Load(const void* data
, int size
);
33 /* Unload a mod file. */
34 void ModPlug_Unload(ModPlugFile
* file
);
36 /* Read sample data into the buffer. Returns the number of bytes read. If the end
37 * of the mod has been reached, zero is returned. */
38 int ModPlug_Read(ModPlugFile
* file
, void* buffer
, int size
);
40 /* Get the name of the mod. The returned buffer is stored within the ModPlugFile
41 * structure and will remain valid until you unload the file. */
42 const char* ModPlug_GetName(ModPlugFile
* file
);
44 /* Get the length of the mod, in milliseconds. Note that this result is not always
45 * accurate, especially in the case of mods with loops. */
46 int ModPlug_GetLength(ModPlugFile
* file
);
48 /* Seek to a particular position in the song. Note that seeking and MODs don't mix very
49 * well. Some mods will be missing instruments for a short time after a seek, as ModPlug
50 * does not scan the sequence backwards to find out which instruments were supposed to be
51 * playing at that time. (Doing so would be difficult and not very reliable.) Also,
52 * note that seeking is not very exact in some mods -- especially those for which
53 * ModPlug_GetLength() does not report the full length. */
54 void ModPlug_Seek(ModPlugFile
* file
, int millisecond
);
58 MODPLUG_ENABLE_OVERSAMPLING
= 1 << 0, /* Enable oversampling (*highly* recommended) */
59 MODPLUG_ENABLE_NOISE_REDUCTION
= 1 << 1, /* Enable noise reduction */
60 MODPLUG_ENABLE_REVERB
= 1 << 2, /* Enable reverb */
61 MODPLUG_ENABLE_MEGABASS
= 1 << 3, /* Enable megabass */
62 MODPLUG_ENABLE_SURROUND
= 1 << 4 /* Enable surround sound. */
65 enum _ModPlug_ResamplingMode
67 MODPLUG_RESAMPLE_NEAREST
= 0, /* No interpolation (very fast, extremely bad sound quality) */
68 MODPLUG_RESAMPLE_LINEAR
= 1, /* Linear interpolation (fast, good quality) */
69 MODPLUG_RESAMPLE_SPLINE
= 2, /* Cubic spline interpolation (high quality) */
70 MODPLUG_RESAMPLE_FIR
= 3 /* 8-tap fir filter (extremely high quality) */
73 typedef struct _ModPlug_Settings
75 int mFlags
; /* One or more of the MODPLUG_ENABLE_* flags above, bitwise-OR'ed */
77 /* Note that ModPlug always decodes sound at 44100kHz, 32 bit, stereo and then
78 * down-mixes to the settings you choose. */
79 int mChannels
; /* Number of channels - 1 for mono or 2 for stereo */
80 int mBits
; /* Bits per sample - 8, 16, or 32 */
81 int mFrequency
; /* Sampling rate - 11025, 22050, or 44100 */
82 int mResamplingMode
; /* One of MODPLUG_RESAMPLE_*, above */
84 int mStereoSeparation
; /* Stereo separation, 1 - 256 */
85 int mMaxMixChannels
; /* Maximum number of mixing channels (polyphony), 32 - 256 */
87 int mReverbDepth
; /* Reverb level 0(quiet)-100(loud) */
88 int mReverbDelay
; /* Reverb delay in ms, usually 40-200ms */
89 int mBassAmount
; /* XBass level 0(quiet)-100(loud) */
90 int mBassRange
; /* XBass cutoff in Hz 10-100 */
91 int mSurroundDepth
; /* Surround level 0(quiet)-100(heavy) */
92 int mSurroundDelay
; /* Surround delay in ms, usually 5-40ms */
93 int mLoopCount
; /* Number of times to loop. Zero prevents looping.
97 /* Get and set the mod decoder settings. All options, except for channels, bits-per-sample,
98 * sampling rate, and loop count, will take effect immediately. Those options which don't
99 * take effect immediately will take effect the next time you load a mod. */
100 void ModPlug_GetSettings(ModPlug_Settings
* settings
);
101 void ModPlug_SetSettings(const ModPlug_Settings
* settings
);
103 /* New ModPlug API Functions */
104 /* NOTE: Master Volume (1-512) */
105 unsigned int ModPlug_GetMasterVolume(ModPlugFile
* file
) ;
106 void ModPlug_SetMasterVolume(ModPlugFile
* file
,unsigned int cvol
) ;
108 int ModPlug_GetCurrentSpeed(ModPlugFile
* file
);
109 int ModPlug_GetCurrentTempo(ModPlugFile
* file
);
110 int ModPlug_GetCurrentOrder(ModPlugFile
* file
);
111 int ModPlug_GetCurrentPattern(ModPlugFile
* file
);
112 int ModPlug_GetCurrentRow(ModPlugFile
* file
);
113 int ModPlug_GetPlayingChannels(ModPlugFile
* file
);
115 void ModPlug_SeekOrder(ModPlugFile
* file
,int order
);
116 int ModPlug_GetModuleType(ModPlugFile
* file
);
117 char* ModPlug_GetMessage(ModPlugFile
* file
);
120 #ifndef MODPLUG_NO_FILESAVE
122 * EXPERIMENTAL Export Functions
124 /*Export to a Scream Tracker 3 S3M module. EXPERIMENTAL (only works on Little-Endian platforms)*/
125 char ModPlug_ExportS3M(ModPlugFile
* file
, const char* filepath
);
127 /*Export to a Extended Module (XM). EXPERIMENTAL (only works on Little-Endian platforms)*/
128 char ModPlug_ExportXM(ModPlugFile
* file
, const char* filepath
);
130 /*Export to a Amiga MOD file. EXPERIMENTAL.*/
131 char ModPlug_ExportMOD(ModPlugFile
* file
, const char* filepath
);
133 /*Export to a Impulse Tracker IT file. Should work OK in Little-Endian & Big-Endian platforms :-) */
134 char ModPlug_ExportIT(ModPlugFile
* file
, const char* filepath
);
135 #endif // MODPLUG_NO_FILESAVE
137 unsigned int ModPlug_NumInstruments(ModPlugFile
* file
);
138 unsigned int ModPlug_NumSamples(ModPlugFile
* file
);
139 unsigned int ModPlug_NumPatterns(ModPlugFile
* file
);
140 unsigned int ModPlug_NumChannels(ModPlugFile
* file
);
141 unsigned int ModPlug_SampleName(ModPlugFile
* file
, unsigned int qual
, char* buff
);
142 unsigned int ModPlug_InstrumentName(ModPlugFile
* file
, unsigned int qual
, char* buff
);
145 * Retrieve pattern note-data
147 ModPlugNote
* ModPlug_GetPattern(ModPlugFile
* file
, int pattern
, unsigned int* numrows
);
154 * Use this callback if you want to 'modify' the mixed data of LibModPlug.
156 * void proc(int* buffer,unsigned long channels,unsigned long nsamples) ;
158 * 'buffer': A buffer of mixed samples
159 * 'channels': N. of channels in the buffer
160 * 'nsamples': N. of samples in the buffeer (without taking care of n.channels)
162 * (Samples are signed 32-bit integers)
164 void ModPlug_InitMixerCallback(ModPlugFile
* file
,ModPlugMixerProc proc
) ;
165 void ModPlug_UnloadMixerCallback(ModPlugFile
* file
) ;