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