Subversion Repositories eduke32

Rev

Rev 6161 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6158 hendricks2 1
#ifndef XMP_H
2
#define XMP_H
3
 
4
#ifdef __cplusplus
5
extern "C" {
6
#endif
7
 
8
#define XMP_VERSION "4.4.2"
9
#define XMP_VERCODE 0x040402
10
#define XMP_VER_MAJOR 4
11
#define XMP_VER_MINOR 4
12
#define XMP_VER_RELEASE 2
13
 
14
#if defined(_WIN32) && !defined(__CYGWIN__)
15
# if defined(BUILDING_STATIC)
16
#  define EXPORT
17
# elif defined(BUILDING_DLL)
18
#  define EXPORT __declspec(dllexport)
19
# else
20
#  define EXPORT __declspec(dllimport)
21
# endif
22
#elif defined(__OS2__) && defined(__WATCOMC__) && defined(__SW_BD)
23
#  define EXPORT __declspec(dllexport)
24
#elif (defined(__GNUC__) || defined(__clang__) || defined(__HP_cc)) && defined(XMP_SYM_VISIBILITY)
25
# define EXPORT __attribute__((visibility ("default")))
26
#elif defined(__SUNPRO_C) && defined(XMP_LDSCOPE_GLOBAL)
27
# define EXPORT __global
28
#elif defined(EMSCRIPTEN)
29
# define EXPORT EMSCRIPTEN_KEEPALIVE
30
#else
31
# define EXPORT 
32
#endif
33
 
34
#define XMP_NAME_SIZE           64      /* Size of module name and type */
35
 
36
#define XMP_KEY_OFF             0x81    /* Note number for key off event */
37
#define XMP_KEY_CUT             0x82    /* Note number for key cut event */
38
#define XMP_KEY_FADE            0x83    /* Note number for fade event */
39
 
40
/* mixer parameter macros */
41
 
42
/* sample format flags */
43
#define XMP_FORMAT_8BIT         (1 << 0) /* Mix to 8-bit instead of 16 */
44
#define XMP_FORMAT_UNSIGNED     (1 << 1) /* Mix to unsigned samples */
45
#define XMP_FORMAT_MONO         (1 << 2) /* Mix to mono instead of stereo */
46
 
47
/* player parameters */
48
#define XMP_PLAYER_AMP          0       /* Amplification factor */
49
#define XMP_PLAYER_MIX          1       /* Stereo mixing */
50
#define XMP_PLAYER_INTERP       2       /* Interpolation type */
51
#define XMP_PLAYER_DSP          3       /* DSP effect flags */
52
#define XMP_PLAYER_FLAGS        4       /* Player flags */
53
#define XMP_PLAYER_CFLAGS       5       /* Player flags for current module */
54
#define XMP_PLAYER_SMPCTL       6       /* Sample control flags */
55
#define XMP_PLAYER_VOLUME       7       /* Player module volume */
56
#define XMP_PLAYER_STATE        8       /* Internal player state (read only) */
57
#define XMP_PLAYER_SMIX_VOLUME  9       /* SMIX volume */
58
#define XMP_PLAYER_DEFPAN       10      /* Default pan setting */
59
#define XMP_PLAYER_MODE         11      /* Player personality */
60
#define XMP_PLAYER_MIXER_TYPE   12      /* Current mixer (read only) */
61
#define XMP_PLAYER_VOICES       13      /* Maximum number of mixer voices */
62
 
63
/* interpolation types */
64
#define XMP_INTERP_NEAREST      0       /* Nearest neighbor */
65
#define XMP_INTERP_LINEAR       1       /* Linear (default) */
66
#define XMP_INTERP_SPLINE       2       /* Cubic spline */
67
 
68
/* dsp effect types */
69
#define XMP_DSP_LOWPASS         (1 << 0) /* Lowpass filter effect */
70
#define XMP_DSP_ALL             (XMP_DSP_LOWPASS)
71
 
72
/* player state */
73
#define XMP_STATE_UNLOADED      0       /* Context created */
74
#define XMP_STATE_LOADED        1       /* Module loaded */
75
#define XMP_STATE_PLAYING       2       /* Module playing */
76
 
77
/* player flags */
78
#define XMP_FLAGS_VBLANK        (1 << 0) /* Use vblank timing */
79
#define XMP_FLAGS_FX9BUG        (1 << 1) /* Emulate FX9 bug */
80
#define XMP_FLAGS_FIXLOOP       (1 << 2) /* Emulate sample loop bug */
81
#define XMP_FLAGS_A500          (1 << 3) /* Use Paula mixer in Amiga modules */
82
 
83
/* player modes */
84
#define XMP_MODE_AUTO           0       /* Autodetect mode (default) */
85
#define XMP_MODE_MOD            1       /* Play as a generic MOD player */
86
#define XMP_MODE_NOISETRACKER   2       /* Play using Noisetracker quirks */
87
#define XMP_MODE_PROTRACKER     3       /* Play using Protracker quirks */
88
#define XMP_MODE_S3M            4       /* Play as a generic S3M player */
89
#define XMP_MODE_ST3            5       /* Play using ST3 bug emulation */
90
#define XMP_MODE_ST3GUS         6       /* Play using ST3+GUS quirks */
91
#define XMP_MODE_XM             7       /* Play as a generic XM player */
92
#define XMP_MODE_FT2            8       /* Play using FT2 bug emulation */
93
#define XMP_MODE_IT             9       /* Play using IT quirks */
94
#define XMP_MODE_ITSMP          10      /* Play using IT sample mode quirks */
95
 
96
/* mixer types */
97
#define XMP_MIXER_STANDARD      0       /* Standard mixer */
98
#define XMP_MIXER_A500          1       /* Amiga 500 */
99
#define XMP_MIXER_A500F         2       /* Amiga 500 with led filter */
100
 
101
/* sample flags */
102
#define XMP_SMPCTL_SKIP         (1 << 0) /* Don't load samples */
103
 
104
/* limits */
105
#define XMP_MAX_KEYS            121     /* Number of valid keys */
106
#define XMP_MAX_ENV_POINTS      32      /* Max number of envelope points */
107
#define XMP_MAX_MOD_LENGTH      256     /* Max number of patterns in module */
108
#define XMP_MAX_CHANNELS        64      /* Max number of channels in module */
109
#define XMP_MAX_SRATE           49170   /* max sampling rate (Hz) */
110
#define XMP_MIN_SRATE           4000    /* min sampling rate (Hz) */
111
#define XMP_MIN_BPM             20      /* min BPM */
112
/* frame rate = (50 * bpm / 125) Hz */
113
/* frame size = (sampling rate * channels * size) / frame rate */
114
#define XMP_MAX_FRAMESIZE       (5 * XMP_MAX_SRATE * 2 / XMP_MIN_BPM)
115
 
116
/* error codes */
117
#define XMP_END                 1
118
#define XMP_ERROR_INTERNAL      2       /* Internal error */
119
#define XMP_ERROR_FORMAT        3       /* Unsupported module format */
120
#define XMP_ERROR_LOAD          4       /* Error loading file */
121
#define XMP_ERROR_DEPACK        5       /* Error depacking file */
122
#define XMP_ERROR_SYSTEM        6       /* System error */
123
#define XMP_ERROR_INVALID       7       /* Invalid parameter */
124
#define XMP_ERROR_STATE         8       /* Invalid player state */
125
 
126
struct xmp_channel {
127
        int pan;                        /* Channel pan (0x80 is center) */
128
        int vol;                        /* Channel volume */
129
#define XMP_CHANNEL_SYNTH       (1 << 0)  /* Channel is synthesized */
130
#define XMP_CHANNEL_MUTE        (1 << 1)  /* Channel is muted */
131
#define XMP_CHANNEL_SPLIT       (1 << 2)  /* Split Amiga channel in bits 5-4 */
132
#define XMP_CHANNEL_SURROUND    (1 << 4)  /* Surround channel */
133
        int flg;                        /* Channel flags */
134
};
135
 
136
struct xmp_pattern {
137
        int rows;                       /* Number of rows */
138
        int index[1];                   /* Track index */
139
};
140
 
141
struct xmp_event {
142
        unsigned char note;             /* Note number (0 means no note) */
143
        unsigned char ins;              /* Patch number */
144
        unsigned char vol;              /* Volume (0 to basevol) */
145
        unsigned char fxt;              /* Effect type */
146
        unsigned char fxp;              /* Effect parameter */
147
        unsigned char f2t;              /* Secondary effect type */
148
        unsigned char f2p;              /* Secondary effect parameter */
149
        unsigned char _flag;            /* Internal (reserved) flags */
150
};
151
 
152
struct xmp_track {
153
        int rows;                       /* Number of rows */
154
        struct xmp_event event[1];      /* Event data */
155
};
156
 
157
struct xmp_envelope {
158
#define XMP_ENVELOPE_ON         (1 << 0)  /* Envelope is enabled */
159
#define XMP_ENVELOPE_SUS        (1 << 1)  /* Envelope has sustain point */
160
#define XMP_ENVELOPE_LOOP       (1 << 2)  /* Envelope has loop */
161
#define XMP_ENVELOPE_FLT        (1 << 3)  /* Envelope is used for filter */
162
#define XMP_ENVELOPE_SLOOP      (1 << 4)  /* Envelope has sustain loop */
163
#define XMP_ENVELOPE_CARRY      (1 << 5)  /* Don't reset envelope position */
164
        int flg;                        /* Flags */
165
        int npt;                        /* Number of envelope points */
166
        int scl;                        /* Envelope scaling */
167
        int sus;                        /* Sustain start point */
168
        int sue;                        /* Sustain end point */
169
        int lps;                        /* Loop start point */
170
        int lpe;                        /* Loop end point */
171
        short data[XMP_MAX_ENV_POINTS * 2];
172
};
173
 
6161 hendricks2 174
struct xmp_subinstrument {
175
    int vol;            /* Default volume */
176
    int gvl;            /* Global volume */
177
    int pan;            /* Pan */
178
    int xpo;            /* Transpose */
179
    int fin;            /* Finetune */
180
    int vwf;            /* Vibrato waveform */
181
    int vde;            /* Vibrato depth */
182
    int vra;            /* Vibrato rate */
183
    int vsw;            /* Vibrato sweep */
184
    int rvv;            /* Random volume/pan variation (IT) */
185
    int sid;            /* Sample number */
186
#define XMP_INST_NNA_CUT        0x00
187
#define XMP_INST_NNA_CONT       0x01
188
#define XMP_INST_NNA_OFF        0x02
189
#define XMP_INST_NNA_FADE       0x03
190
    int nna;            /* New note action */
191
#define XMP_INST_DCT_OFF        0x00
192
#define XMP_INST_DCT_NOTE       0x01
193
#define XMP_INST_DCT_SMP        0x02
194
#define XMP_INST_DCT_INST       0x03
195
    int dct;            /* Duplicate check type */
196
#define XMP_INST_DCA_CUT        XMP_INST_NNA_CUT
197
#define XMP_INST_DCA_OFF        XMP_INST_NNA_OFF
198
#define XMP_INST_DCA_FADE       XMP_INST_NNA_FADE
199
    int dca;            /* Duplicate check action */
200
    int ifc;            /* Initial filter cutoff */
201
    int ifr;            /* Initial filter resonance */
202
};
203
 
6158 hendricks2 204
struct xmp_instrument {
205
        char name[32];                  /* Instrument name */
206
        int vol;                        /* Instrument volume */
207
        int nsm;                        /* Number of samples */
208
        int rls;                        /* Release (fadeout) */
209
        struct xmp_envelope aei;        /* Amplitude envelope info */
210
        struct xmp_envelope pei;        /* Pan envelope info */
211
        struct xmp_envelope fei;        /* Frequency envelope info */
212
 
213
        struct {
214
                unsigned char ins;      /* Instrument number for each key */
215
                signed char xpo;        /* Instrument transpose for each key */
216
        } map[XMP_MAX_KEYS];
217
 
6161 hendricks2 218
    struct xmp_subinstrument *sub;
6158 hendricks2 219
 
220
        void *extra;                    /* Extra fields */
221
};
222
 
223
struct xmp_sample {
224
        char name[32];                  /* Sample name */
225
        int len;                        /* Sample length */
226
        int lps;                        /* Loop start */
227
        int lpe;                        /* Loop end */
228
#define XMP_SAMPLE_16BIT        (1 << 0)  /* 16bit sample */
229
#define XMP_SAMPLE_LOOP         (1 << 1)  /* Sample is looped */
230
#define XMP_SAMPLE_LOOP_BIDIR   (1 << 2)  /* Bidirectional sample loop */
231
#define XMP_SAMPLE_LOOP_REVERSE (1 << 3)  /* Backwards sample loop */
232
#define XMP_SAMPLE_LOOP_FULL    (1 << 4)  /* Play full sample before looping */
233
#define XMP_SAMPLE_SLOOP        (1 << 5)  /* Sample has sustain loop */
234
#define XMP_SAMPLE_SLOOP_BIDIR  (1 << 6)  /* Bidirectional sustain loop */
235
#define XMP_SAMPLE_SYNTH        (1 << 15) /* Data contains synth patch */
236
        int flg;                        /* Flags */
237
        unsigned char *data;            /* Sample data */
238
};
239
 
240
struct xmp_sequence {
241
        int entry_point;
242
        int duration;
243
};
244
 
245
struct xmp_module {
246
        char name[XMP_NAME_SIZE];       /* Module title */
247
        char type[XMP_NAME_SIZE];       /* Module format */
248
        int pat;                        /* Number of patterns */
249
        int trk;                        /* Number of tracks */
250
        int chn;                        /* Tracks per pattern */
251
        int ins;                        /* Number of instruments */
252
        int smp;                        /* Number of samples */
253
        int spd;                        /* Initial speed */
254
        int bpm;                        /* Initial BPM */
255
        int len;                        /* Module length in patterns */
256
        int rst;                        /* Restart position */
257
        int gvl;                        /* Global volume */
258
 
259
        struct xmp_pattern **xxp;       /* Patterns */
260
        struct xmp_track **xxt;         /* Tracks */
261
        struct xmp_instrument *xxi;     /* Instruments */
262
        struct xmp_sample *xxs;         /* Samples */
263
        struct xmp_channel xxc[XMP_MAX_CHANNELS]; /* Channel info */
264
        unsigned char xxo[XMP_MAX_MOD_LENGTH];  /* Orders */
265
};
266
 
267
struct xmp_test_info {
268
        char name[XMP_NAME_SIZE];       /* Module title */
269
        char type[XMP_NAME_SIZE];       /* Module format */
270
};
271
 
272
struct xmp_module_info {
273
        unsigned char md5[16];          /* MD5 message digest */
274
        int vol_base;                   /* Volume scale */
275
        struct xmp_module *mod;         /* Pointer to module data */
276
        char *comment;                  /* Comment text, if any */
277
        int num_sequences;              /* Number of valid sequences */
278
        struct xmp_sequence *seq_data;  /* Pointer to sequence data */
279
};
280
 
6161 hendricks2 281
struct xmp_channel_info {       /* Current channel information */
282
    unsigned int period;        /* Sample period (* 4096) */
283
    unsigned int position;      /* Sample position */
284
    short pitchbend;    /* Linear bend from base note*/
285
    unsigned char note; /* Current base note number */
286
    unsigned char instrument; /* Current instrument number */
287
    unsigned char sample;       /* Current sample number */
288
    unsigned char volume;       /* Current volume */
289
    unsigned char pan;  /* Current stereo pan */
290
    unsigned char reserved;     /* Reserved */
291
    struct xmp_event event;     /* Current track event */
292
};
293
 
6158 hendricks2 294
struct xmp_frame_info {                 /* Current frame information */
295
        int pos;                        /* Current position */
296
        int pattern;                    /* Current pattern */
297
        int row;                        /* Current row in pattern */
298
        int num_rows;                   /* Number of rows in current pattern */
299
        int frame;                      /* Current frame */
300
        int speed;                      /* Current replay speed */
301
        int bpm;                        /* Current bpm */
302
        int time;                       /* Current module time in ms */
303
        int total_time;                 /* Estimated replay time in ms*/
304
        int frame_time;                 /* Frame replay time in us */
305
        void *buffer;                   /* Pointer to sound buffer */
306
        int buffer_size;                /* Used buffer size */
307
        int total_size;                 /* Total buffer size */
308
        int volume;                     /* Current master volume */
309
        int loop_count;                 /* Loop counter */
310
        int virt_channels;              /* Number of virtual channels */
311
        int virt_used;                  /* Used virtual channels */
312
        int sequence;                   /* Current sequence */
313
 
6161 hendricks2 314
        struct xmp_channel_info channel_info[XMP_MAX_CHANNELS];
6158 hendricks2 315
};
316
 
317
 
318
typedef char *xmp_context;
319
 
320
EXPORT extern const char *xmp_version;
321
EXPORT extern const unsigned int xmp_vercode;
322
 
323
EXPORT xmp_context xmp_create_context  (void);
324
EXPORT void        xmp_free_context    (xmp_context);
7138 hendricks2 325
#ifdef EDUKE32_DISABLED
6158 hendricks2 326
EXPORT int         xmp_test_module     (char *, struct xmp_test_info *);
327
EXPORT int         xmp_load_module     (xmp_context, char *);
7138 hendricks2 328
#endif
6158 hendricks2 329
EXPORT void        xmp_scan_module     (xmp_context);
330
EXPORT void        xmp_release_module  (xmp_context);
331
EXPORT int         xmp_start_player    (xmp_context, int, int);
332
EXPORT int         xmp_play_frame      (xmp_context);
333
EXPORT int         xmp_play_buffer     (xmp_context, void *, int, int);
334
EXPORT void        xmp_get_frame_info  (xmp_context, struct xmp_frame_info *);
335
EXPORT void        xmp_end_player      (xmp_context);
336
EXPORT void        xmp_inject_event    (xmp_context, int, struct xmp_event *);
337
EXPORT void        xmp_get_module_info (xmp_context, struct xmp_module_info *);
6160 hendricks2 338
EXPORT const char**xmp_get_format_list (void);
6158 hendricks2 339
EXPORT int         xmp_next_position   (xmp_context);
340
EXPORT int         xmp_prev_position   (xmp_context);
341
EXPORT int         xmp_set_position    (xmp_context, int);
342
EXPORT void        xmp_stop_module     (xmp_context);
343
EXPORT void        xmp_restart_module  (xmp_context);
344
EXPORT int         xmp_seek_time       (xmp_context, int);
345
EXPORT int         xmp_channel_mute    (xmp_context, int, int);
346
EXPORT int         xmp_channel_vol     (xmp_context, int, int);
347
EXPORT int         xmp_set_player      (xmp_context, int, int);
348
EXPORT int         xmp_get_player      (xmp_context, int);
349
EXPORT int         xmp_set_instrument_path (xmp_context, char *);
350
EXPORT int         xmp_load_module_from_memory (xmp_context, void *, long);
7138 hendricks2 351
#ifdef EDUKE32_DISABLED
6158 hendricks2 352
EXPORT int         xmp_load_module_from_file (xmp_context, void *, long);
7138 hendricks2 353
#endif
6158 hendricks2 354
 
355
/* External sample mixer API */
356
EXPORT int         xmp_start_smix       (xmp_context, int, int);
357
EXPORT void        xmp_end_smix         (xmp_context);
358
EXPORT int         xmp_smix_play_instrument(xmp_context, int, int, int, int);
359
EXPORT int         xmp_smix_play_sample (xmp_context, int, int, int, int);
360
EXPORT int         xmp_smix_channel_pan (xmp_context, int, int);
7138 hendricks2 361
#ifdef EDUKE32_DISABLED
6158 hendricks2 362
EXPORT int         xmp_smix_load_sample (xmp_context, int, char *);
7138 hendricks2 363
#endif
6158 hendricks2 364
EXPORT int         xmp_smix_release_sample (xmp_context, int);
365
 
366
#ifdef __cplusplus
367
}
368
#endif
369
 
370
#endif  /* XMP_H */