initial import
[dosrtxon] / libs / mikmod / include / mikmod.h
1 /*  MikMod sound library
2     (c) 1998-2014 Miodrag Vallat and others - see the AUTHORS file
3     for complete list.
4
5     This library is free software; you can redistribute it and/or modify
6     it under the terms of the GNU Library General Public License as
7     published by the Free Software Foundation; either version 2 of
8     the License, or (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18     02111-1307, USA.
19 */
20
21 /*==============================================================================
22
23   MikMod sound library include file
24
25   ==============================================================================*/
26
27 #ifndef _MIKMOD_H_
28 #define _MIKMOD_H_
29
30 #include <stdio.h>
31 #include <stdlib.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #ifndef MIKMOD_STATIC
38 #define MIKMOD_STATIC
39 #endif
40
41 /*
42  * ========== Compiler magic for shared libraries
43  *
44  * ========== NOTE TO WINDOWS DEVELOPERS:
45  * If you are compiling for Windows and will link to the static library
46  * (libmikmod.a with MinGW, or mikmod_static.lib with MSVC or LCC, etc),
47  * you must define MIKMOD_STATIC in your project.  Otherwise, dllimport
48  * will be assumed.
49  */
50 #if defined(_WIN32) || defined(__CYGWIN__)
51 # if defined(MIKMOD_BUILD) && defined(DLL_EXPORT)       /* building libmikmod as a dll for windows */
52 #   define MIKMODAPI __declspec(dllexport)
53 # elif defined(MIKMOD_BUILD) || defined(MIKMOD_STATIC)  /* building or using static libmikmod for windows */
54 #   define MIKMODAPI
55 # else
56 #   define MIKMODAPI __declspec(dllimport)                      /* using libmikmod dll for windows */
57 # endif
58 #elif defined(__OS2__) && defined(__WATCOMC__)
59 # if defined(MIKMOD_BUILD) && defined(__SW_BD)          /* building libmikmod as a dll for os/2 */
60 #   define MIKMODAPI __declspec(dllexport)
61 # else
62 #   define MIKMODAPI                                    /* using dll or static libmikmod for os/2 */
63 # endif
64 /* SYM_VISIBILITY should be defined if both the compiler
65  * and the target support the visibility attributes. the
66  * configury does that automatically. for the standalone
67  * makefiles, etc, the developer should add the required
68  * flags, i.e.:  -DSYM_VISIBILITY -fvisibility=hidden  */
69 #elif defined(MIKMOD_BUILD) && defined(SYM_VISIBILITY)
70 #   define MIKMODAPI __attribute__((visibility("default")))
71 #else
72 #   define MIKMODAPI
73 #endif
74
75 /*
76  *  ========== Library version
77  */
78
79 #define LIBMIKMOD_VERSION_MAJOR 3L
80 #define LIBMIKMOD_VERSION_MINOR 3L
81 #define LIBMIKMOD_REVISION     10L
82
83 #define LIBMIKMOD_VERSION \
84     ((LIBMIKMOD_VERSION_MAJOR<<16)| \
85      (LIBMIKMOD_VERSION_MINOR<< 8)| \
86      (LIBMIKMOD_REVISION))
87
88 MIKMODAPI extern long MikMod_GetVersion(void);
89
90 /*
91  *  ========== Dependency platform headers
92  */
93
94 #ifdef _WIN32
95 #ifndef WIN32_LEAN_AND_MEAN
96 #define WIN32_LEAN_AND_MEAN
97 #endif
98 #include <windows.h>
99 #include <io.h>
100 #include <mmsystem.h>
101 #define _MIKMOD_WIN32
102 #endif
103
104 #if defined(__DJGPP__) || defined(MSDOS) || defined(__MSDOS__) || defined(__DOS__)
105 #define _MIKMOD_DOS
106 #endif
107
108 #if defined(__OS2__) || defined(__EMX__)
109 #define INCL_DOSSEMAPHORES
110 #include <os2.h>
111 #include <io.h>
112 #define _MIKMOD_OS2
113 #endif
114
115 #if defined(__MORPHOS__) || defined(__AROS__) || defined(_AMIGA) || defined(__AMIGA__) || defined(__amigaos__) || defined(AMIGAOS)
116 #include <exec/types.h>
117 #define _MIKMOD_AMIGA
118 #endif
119
120 /*
121  *  ========== Platform independent-type definitions
122  * (pain when it comes to cross-platform maintenance..)
123  */
124
125 #if !(defined(_MIKMOD_OS2) || defined(_MIKMOD_WIN32))
126 typedef char               CHAR;
127 #endif
128
129 /* BOOL:  0=false, <>0 true -- 16 bits on Amiga, int-wide on others. */
130 #if !(defined(_MIKMOD_OS2) || defined(_MIKMOD_WIN32) || defined(_MIKMOD_AMIGA))
131 typedef int                BOOL;
132 #endif
133
134 /* 1 byte, signed and unsigned: */
135 typedef signed char        SBYTE;
136 #ifndef _MIKMOD_AMIGA
137 typedef unsigned char      UBYTE;
138 #endif
139
140 /* 2 bytes, signed and unsigned: */
141 #ifndef __LCC__
142 typedef signed short int   SWORD;
143 #endif
144 #if !(defined(__LCC__) || defined(_MIKMOD_AMIGA))
145 typedef unsigned short int UWORD;
146 #endif
147
148 /* 4 bytes, signed and unsigned: */
149 #if defined(_LP64) || defined(__LP64__) || defined(__arch64__) || defined(__alpha) || defined(__x86_64) || defined(__powerpc64__)
150         /* 64 bit architectures: */
151 typedef signed int         SLONG;
152 #if !(defined(_WIN32) || defined(_MIKMOD_AMIGA))
153 typedef unsigned int       ULONG;
154 #endif
155
156 #else  /* 32 bit architectures: */
157 typedef signed long int    SLONG;
158 #if !(defined(_MIKMOD_OS2) || defined(_MIKMOD_WIN32) || defined(_MIKMOD_AMIGA))
159 typedef unsigned long int  ULONG;
160 #endif
161 #endif
162
163 /* make sure types are of correct sizes: */
164 typedef int __mikmod_typetest [
165    (
166         (sizeof(SBYTE)==1) && (sizeof(UBYTE)==1)
167      && (sizeof(SWORD)==2) && (sizeof(UWORD)==2)
168      && (sizeof(SLONG)==4) && (sizeof(ULONG)==4)
169 #ifndef _MIKMOD_AMIGA
170      && (sizeof(BOOL) == sizeof(int))
171 #endif
172      && (sizeof(CHAR) == sizeof(char))
173    ) * 2 - 1 ];
174
175 /*
176  *  ========== Error codes
177  */
178
179 enum {
180     MMERR_OPENING_FILE = 1,
181     MMERR_OUT_OF_MEMORY,
182     MMERR_DYNAMIC_LINKING,
183
184     MMERR_SAMPLE_TOO_BIG,
185     MMERR_OUT_OF_HANDLES,
186     MMERR_UNKNOWN_WAVE_TYPE,
187
188     MMERR_LOADING_PATTERN,
189     MMERR_LOADING_TRACK,
190     MMERR_LOADING_HEADER,
191     MMERR_LOADING_SAMPLEINFO,
192     MMERR_NOT_A_MODULE,
193     MMERR_NOT_A_STREAM,
194     MMERR_MED_SYNTHSAMPLES,
195     MMERR_ITPACK_INVALID_DATA,
196
197     MMERR_DETECTING_DEVICE,
198     MMERR_INVALID_DEVICE,
199     MMERR_INITIALIZING_MIXER,
200     MMERR_OPENING_AUDIO,
201     MMERR_8BIT_ONLY,
202     MMERR_16BIT_ONLY,
203     MMERR_STEREO_ONLY,
204     MMERR_ULAW,
205     MMERR_NON_BLOCK,
206
207     MMERR_AF_AUDIO_PORT,
208
209     MMERR_AIX_CONFIG_INIT,
210     MMERR_AIX_CONFIG_CONTROL,
211     MMERR_AIX_CONFIG_START,
212
213     MMERR_GUS_SETTINGS,
214     MMERR_GUS_RESET,
215     MMERR_GUS_TIMER,
216
217     MMERR_HP_SETSAMPLESIZE,
218     MMERR_HP_SETSPEED,
219     MMERR_HP_CHANNELS,
220     MMERR_HP_AUDIO_OUTPUT,
221     MMERR_HP_AUDIO_DESC,
222     MMERR_HP_BUFFERSIZE,
223
224     MMERR_OSS_SETFRAGMENT,
225     MMERR_OSS_SETSAMPLESIZE,
226     MMERR_OSS_SETSTEREO,
227     MMERR_OSS_SETSPEED,
228
229     MMERR_SGI_SPEED,
230     MMERR_SGI_16BIT,
231     MMERR_SGI_8BIT,
232     MMERR_SGI_STEREO,
233     MMERR_SGI_MONO,
234
235     MMERR_SUN_INIT,
236
237     MMERR_OS2_MIXSETUP,
238     MMERR_OS2_SEMAPHORE,
239     MMERR_OS2_TIMER,
240     MMERR_OS2_THREAD,
241
242     MMERR_DS_PRIORITY,
243     MMERR_DS_BUFFER,
244     MMERR_DS_FORMAT,
245     MMERR_DS_NOTIFY,
246     MMERR_DS_EVENT,
247     MMERR_DS_THREAD,
248     MMERR_DS_UPDATE,
249
250     MMERR_WINMM_HANDLE,
251     MMERR_WINMM_ALLOCATED,
252     MMERR_WINMM_DEVICEID,
253     MMERR_WINMM_FORMAT,
254     MMERR_WINMM_UNKNOWN,
255
256     MMERR_MAC_SPEED,
257     MMERR_MAC_START,
258
259     MMERR_OSX_UNKNOWN_DEVICE,
260     MMERR_OSX_BAD_PROPERTY,
261     MMERR_OSX_UNSUPPORTED_FORMAT,
262     MMERR_OSX_SET_STEREO,
263     MMERR_OSX_BUFFER_ALLOC,
264     MMERR_OSX_ADD_IO_PROC,
265     MMERR_OSX_DEVICE_START,
266     MMERR_OSX_PTHREAD,
267
268     MMERR_DOSWSS_STARTDMA,
269     MMERR_DOSSB_STARTDMA,
270
271     MMERR_NO_FLOAT32,/* should actually be after MMERR_ULAW or something */
272
273     MMERR_OPENAL_CREATECTX,
274     MMERR_OPENAL_CTXCURRENT,
275     MMERR_OPENAL_GENBUFFERS,
276     MMERR_OPENAL_GENSOURCES,
277     MMERR_OPENAL_SOURCE,
278     MMERR_OPENAL_QUEUEBUFFERS,
279     MMERR_OPENAL_UNQUEUEBUFFERS,
280     MMERR_OPENAL_BUFFERDATA,
281     MMERR_OPENAL_GETSOURCE,
282     MMERR_OPENAL_SOURCEPLAY,
283     MMERR_OPENAL_SOURCESTOP,
284
285     MMERR_ALSA_NOCONFIG,
286     MMERR_ALSA_SETPARAMS,
287     MMERR_ALSA_SETFORMAT,
288     MMERR_ALSA_SETRATE,
289     MMERR_ALSA_SETCHANNELS,
290     MMERR_ALSA_BUFFERSIZE,
291     MMERR_ALSA_PCM_START,
292     MMERR_ALSA_PCM_WRITE,
293     MMERR_ALSA_PCM_RECOVER,
294
295     MMERR_SNDIO_SETPARAMS,
296     MMERR_SNDIO_BADPARAMS,
297
298     MMERR_MAX
299 };
300
301 /*
302  *  ========== Error handling
303  */
304
305 typedef void (MikMod_handler)(void);
306 typedef MikMod_handler *MikMod_handler_t;
307
308 MIKMODAPI extern int  MikMod_errno;
309 MIKMODAPI extern BOOL MikMod_critical;
310 MIKMODAPI extern const char *MikMod_strerror(int);
311
312 MIKMODAPI extern MikMod_handler_t MikMod_RegisterErrorHandler(MikMod_handler_t);
313
314 /*
315  *  ========== Library initialization and core functions
316  */
317
318 struct MDRIVER;
319
320 MIKMODAPI extern void   MikMod_RegisterAllDrivers(void);
321
322 MIKMODAPI extern CHAR*  MikMod_InfoDriver(void);
323 MIKMODAPI extern void   MikMod_RegisterDriver(struct MDRIVER*);
324 MIKMODAPI extern int    MikMod_DriverFromAlias(const CHAR*);
325 MIKMODAPI extern struct MDRIVER *MikMod_DriverByOrdinal(int);
326
327 MIKMODAPI extern int    MikMod_Init(const CHAR*);
328 MIKMODAPI extern void   MikMod_Exit(void);
329 MIKMODAPI extern int    MikMod_Reset(const CHAR*);
330 MIKMODAPI extern int    MikMod_SetNumVoices(int,int);
331 MIKMODAPI extern BOOL   MikMod_Active(void);
332 MIKMODAPI extern int    MikMod_EnableOutput(void);
333 MIKMODAPI extern void   MikMod_DisableOutput(void);
334 MIKMODAPI extern void   MikMod_Update(void);
335
336 MIKMODAPI extern BOOL   MikMod_InitThreads(void);
337 MIKMODAPI extern void   MikMod_Lock(void);
338 MIKMODAPI extern void   MikMod_Unlock(void);
339
340 MIKMODAPI extern void*  MikMod_malloc(size_t);
341 MIKMODAPI extern void*  MikMod_calloc(size_t,size_t);
342 MIKMODAPI extern void*  MikMod_realloc(void*,size_t);
343 MIKMODAPI extern CHAR*  MikMod_strdup(const CHAR*);
344 MIKMODAPI extern void   MikMod_free(void*);  /* frees if ptr != NULL */
345
346 /*
347  *  ========== Reader, Writer
348  */
349
350 typedef struct MREADER {
351     int  (*Seek)(struct MREADER*,long,int);
352     long (*Tell)(struct MREADER*);
353     BOOL (*Read)(struct MREADER*,void*,size_t);
354     int  (*Get)(struct MREADER*);
355     BOOL (*Eof)(struct MREADER*);
356     long iobase;
357     long prev_iobase;
358 } MREADER;
359
360 typedef struct MWRITER {
361     int  (*Seek)(struct MWRITER*, long, int);
362     long (*Tell)(struct MWRITER*);
363     BOOL (*Write)(struct MWRITER*, const void*, size_t);
364     int  (*Put)(struct MWRITER*, int);
365 } MWRITER;
366
367 /*
368  *  ========== Samples
369  */
370
371 /* Sample playback should not be interrupted */
372 #define SFX_CRITICAL 1
373
374 /* Sample format [loading and in-memory] flags: */
375 #define SF_16BITS       0x0001
376 #define SF_STEREO       0x0002
377 #define SF_SIGNED       0x0004
378 #define SF_BIG_ENDIAN   0x0008
379 #define SF_DELTA        0x0010
380 #define SF_ITPACKED     0x0020
381
382 #define SF_FORMATMASK   0x003F
383
384 /* General Playback flags */
385
386 #define SF_LOOP         0x0100
387 #define SF_BIDI         0x0200
388 #define SF_REVERSE      0x0400
389 #define SF_SUSTAIN      0x0800
390
391 #define SF_PLAYBACKMASK 0x0C00
392
393 /* Module-only Playback Flags */
394
395 #define SF_OWNPAN       0x1000
396 #define SF_UST_LOOP     0x2000
397
398 #define SF_EXTRAPLAYBACKMASK    0x3000
399
400 /* Panning constants */
401 #define PAN_LEFT        0
402 #define PAN_HALFLEFT    64
403 #define PAN_CENTER      128
404 #define PAN_HALFRIGHT   192
405 #define PAN_RIGHT       255
406 #define PAN_SURROUND    512 /* panning value for Dolby Surround */
407
408 typedef struct SAMPLE {
409     SWORD  panning;     /* panning (0-255 or PAN_SURROUND) */
410     ULONG  speed;       /* Base playing speed/frequency of note */
411     UBYTE  volume;      /* volume 0-64 */
412     UWORD  inflags;     /* sample format on disk */
413     UWORD  flags;       /* sample format in memory */
414     ULONG  length;      /* length of sample (in samples!) */
415     ULONG  loopstart;   /* repeat position (relative to start, in samples) */
416     ULONG  loopend;     /* repeat end */
417     ULONG  susbegin;    /* sustain loop begin (in samples) \  Not Supported */
418     ULONG  susend;      /* sustain loop end                /      Yet! */
419
420     /* Variables used by the module player only! (ignored for sound effects) */
421     UBYTE  globvol;     /* global volume */
422     UBYTE  vibflags;    /* autovibrato flag stuffs */
423     UBYTE  vibtype;     /* Vibratos moved from INSTRUMENT to SAMPLE */
424     UBYTE  vibsweep;
425     UBYTE  vibdepth;
426     UBYTE  vibrate;
427     CHAR*  samplename;  /* name of the sample */
428
429     /* Values used internally only */
430     UWORD  avibpos;     /* autovibrato pos [player use] */
431     UBYTE  divfactor;   /* for sample scaling, maintains proper period slides */
432     ULONG  seekpos;     /* seek position in file */
433     SWORD  handle;      /* sample handle used by individual drivers */
434     void (*onfree)(void *ctx); /* called from Sample_Free if not NULL */
435     void *ctx;          /* context passed to previous function*/
436 } SAMPLE;
437
438 /* Sample functions */
439
440 MIKMODAPI extern SAMPLE *Sample_LoadRaw(const CHAR *,ULONG rate, ULONG channel, ULONG flags);
441 MIKMODAPI extern SAMPLE *Sample_LoadRawFP(FILE *fp,ULONG rate,ULONG channel, ULONG flags);
442 MIKMODAPI extern SAMPLE *Sample_LoadRawMem(const char *buf, int len, ULONG rate, ULONG channel, ULONG flags);
443 MIKMODAPI extern SAMPLE *Sample_LoadRawGeneric(MREADER*reader,ULONG rate, ULONG channel, ULONG flags);
444
445 MIKMODAPI extern SAMPLE *Sample_Load(const CHAR*);
446 MIKMODAPI extern SAMPLE *Sample_LoadFP(FILE*);
447 MIKMODAPI extern SAMPLE *Sample_LoadMem(const char *buf, int len);
448 MIKMODAPI extern SAMPLE *Sample_LoadGeneric(MREADER*);
449 MIKMODAPI extern void   Sample_Free(SAMPLE*);
450 MIKMODAPI extern SBYTE  Sample_Play(SAMPLE*,ULONG,UBYTE);
451
452 MIKMODAPI extern void   Voice_SetVolume(SBYTE,UWORD);
453 MIKMODAPI extern UWORD  Voice_GetVolume(SBYTE);
454 MIKMODAPI extern void   Voice_SetFrequency(SBYTE,ULONG);
455 MIKMODAPI extern ULONG  Voice_GetFrequency(SBYTE);
456 MIKMODAPI extern void   Voice_SetPanning(SBYTE,ULONG);
457 MIKMODAPI extern ULONG  Voice_GetPanning(SBYTE);
458 MIKMODAPI extern void   Voice_Play(SBYTE,SAMPLE*,ULONG);
459 MIKMODAPI extern void   Voice_Stop(SBYTE);
460 MIKMODAPI extern BOOL   Voice_Stopped(SBYTE);
461 MIKMODAPI extern SLONG  Voice_GetPosition(SBYTE);
462 MIKMODAPI extern ULONG  Voice_RealVolume(SBYTE);
463
464 /*
465  *  ========== Internal module representation (UniMod)
466  */
467
468 /*
469     Instrument definition - for information only, the only field which may be
470     of use in user programs is the name field
471 */
472
473 /* Instrument note count */
474 #define INSTNOTES 120
475
476 /* Envelope point */
477 typedef struct ENVPT {
478     SWORD pos;
479     SWORD val;
480 } ENVPT;
481
482 /* Envelope point count */
483 #define ENVPOINTS 32
484
485 /* Instrument structure */
486 typedef struct INSTRUMENT {
487     CHAR* insname;
488
489     UBYTE flags;
490     UWORD samplenumber[INSTNOTES];
491     UBYTE samplenote[INSTNOTES];
492
493     UBYTE nnatype;
494     UBYTE dca;              /* duplicate check action */
495     UBYTE dct;              /* duplicate check type */
496     UBYTE globvol;
497     UWORD volfade;
498     SWORD panning;          /* instrument-based panning var */
499
500     UBYTE pitpansep;        /* pitch pan separation (0 to 255) */
501     UBYTE pitpancenter;     /* pitch pan center (0 to 119) */
502     UBYTE rvolvar;          /* random volume varations (0 - 100%) */
503     UBYTE rpanvar;          /* random panning varations (0 - 100%) */
504
505     /* volume envelope */
506     UBYTE volflg;           /* bit 0: on 1: sustain 2: loop */
507     UBYTE volpts;
508     UBYTE volsusbeg;
509     UBYTE volsusend;
510     UBYTE volbeg;
511     UBYTE volend;
512     ENVPT volenv[ENVPOINTS];
513     /* panning envelope */
514     UBYTE panflg;           /* bit 0: on 1: sustain 2: loop */
515     UBYTE panpts;
516     UBYTE pansusbeg;
517     UBYTE pansusend;
518     UBYTE panbeg;
519     UBYTE panend;
520     ENVPT panenv[ENVPOINTS];
521     /* pitch envelope */
522     UBYTE pitflg;           /* bit 0: on 1: sustain 2: loop */
523     UBYTE pitpts;
524     UBYTE pitsusbeg;
525     UBYTE pitsusend;
526     UBYTE pitbeg;
527     UBYTE pitend;
528     ENVPT pitenv[ENVPOINTS];
529 } INSTRUMENT;
530
531 struct MP_CONTROL;
532 struct MP_VOICE;
533
534 /*
535     Module definition
536 */
537
538 /* maximum master channels supported */
539 #define UF_MAXCHAN      64
540
541 /* Module flags */
542 #define UF_XMPERIODS    0x0001 /* XM periods / finetuning */
543 #define UF_LINEAR       0x0002 /* LINEAR periods (UF_XMPERIODS must be set) */
544 #define UF_INST         0x0004 /* Instruments are used */
545 #define UF_NNA          0x0008 /* IT: NNA used, set numvoices rather
546                                   than numchn */
547 #define UF_S3MSLIDES    0x0010 /* uses old S3M volume slides */
548 #define UF_BGSLIDES     0x0020 /* continue volume slides in the background */
549 #define UF_HIGHBPM      0x0040 /* MED: can use >255 bpm */
550 #define UF_NOWRAP       0x0080 /* XM-type (i.e. illogical) pattern break
551                                   semantics */
552 #define UF_ARPMEM       0x0100 /* IT: need arpeggio memory */
553 #define UF_FT2QUIRKS    0x0200 /* emulate some FT2 replay quirks */
554 #define UF_PANNING      0x0400 /* module uses panning effects or have
555                                   non-tracker default initial panning */
556
557 typedef struct MODULE {
558  /* general module information */
559     CHAR*       songname;    /* name of the song */
560     CHAR*       modtype;     /* string type of module loaded */
561     CHAR*       comment;     /* module comments */
562
563     UWORD       flags;       /* See module flags above */
564     UBYTE       numchn;      /* number of module channels */
565     UBYTE       numvoices;   /* max # voices used for full NNA playback */
566     UWORD       numpos;      /* number of positions in this song */
567     UWORD       numpat;      /* number of patterns in this song */
568     UWORD       numins;      /* number of instruments */
569     UWORD       numsmp;      /* number of samples */
570
571     struct INSTRUMENT* instruments; /* all instruments */
572     struct SAMPLE*     samples;     /* all samples */
573
574     UBYTE       realchn;     /* real number of channels used */
575     UBYTE       totalchn;    /* total number of channels used (incl NNAs) */
576
577  /* playback settings */
578     UWORD       reppos;      /* restart position */
579     UBYTE       initspeed;   /* initial song speed */
580     UWORD       inittempo;   /* initial song tempo */
581     UBYTE       initvolume;  /* initial global volume (0 - 128) */
582     UWORD       panning[UF_MAXCHAN]; /* panning positions */
583     UBYTE       chanvol[UF_MAXCHAN]; /* channel positions */
584     UWORD       bpm;         /* current beats-per-minute speed */
585     UWORD       sngspd;      /* current song speed */
586     SWORD       volume;      /* song volume (0-128) (or user volume) */
587
588     BOOL        extspd;      /* extended speed flag (default enabled) */
589     BOOL        panflag;     /* panning flag (default enabled) */
590     BOOL        wrap;        /* wrap module ? (default disabled) */
591     BOOL        loop;        /* allow module to loop ? (default enabled) */
592     BOOL        fadeout;     /* volume fade out during last pattern */
593
594     UWORD       patpos;      /* current row number */
595     SWORD       sngpos;      /* current song position */
596     ULONG       sngtime;     /* current song time in 2^-10 seconds */
597
598     SWORD       relspd;      /* relative speed factor */
599
600  /* internal module representation */
601     UWORD       numtrk;      /* number of tracks */
602     UBYTE**     tracks;      /* array of numtrk pointers to tracks */
603     UWORD*      patterns;    /* array of Patterns */
604     UWORD*      pattrows;    /* array of number of rows for each pattern */
605     UWORD*      positions;   /* all positions */
606
607     BOOL        forbid;      /* if true, no player update! */
608     UWORD       numrow;      /* number of rows on current pattern */
609     UWORD       vbtick;      /* tick counter (counts from 0 to sngspd) */
610     UWORD       sngremainder;/* used for song time computation */
611
612     struct MP_CONTROL* control; /* Effects Channel info (size pf->numchn) */
613     struct MP_VOICE*   voice;   /* Audio Voice information (size md_numchn) */
614
615     UBYTE       globalslide; /* global volume slide rate */
616     UBYTE       pat_repcrazy;/* module has just looped to position -1 */
617     UWORD       patbrk;      /* position where to start a new pattern */
618     UBYTE       patdly;      /* patterndelay counter (command memory) */
619     UBYTE       patdly2;     /* patterndelay counter (real one) */
620     SWORD       posjmp;      /* flag to indicate a jump is needed... */
621     UWORD       bpmlimit;    /* threshold to detect bpm or speed values */
622 } MODULE;
623
624
625 /* This structure is used to query current playing voices status */
626 typedef struct VOICEINFO {
627     INSTRUMENT* i;            /* Current channel instrument */
628     SAMPLE*     s;            /* Current channel sample */
629     SWORD       panning;      /* panning position */
630     SBYTE       volume;       /* channel's "global" volume (0..64) */
631     UWORD       period;       /* period to play the sample at */
632     UBYTE       kick;         /* if true = sample has been restarted */
633 } VOICEINFO;
634
635 /*
636  *  ========== Module loaders
637  */
638
639 struct MLOADER;
640
641 MIKMODAPI extern CHAR*   MikMod_InfoLoader(void);
642 MIKMODAPI extern void    MikMod_RegisterAllLoaders(void);
643 MIKMODAPI extern void    MikMod_RegisterLoader(struct MLOADER*);
644
645 MIKMODAPI extern struct MLOADER load_669; /* 669 and Extended-669 (by Tran/Renaissance) */
646 MIKMODAPI extern struct MLOADER load_amf; /* DMP Advanced Module Format (by Otto Chrons) */
647 MIKMODAPI extern struct MLOADER load_asy; /* ASYLUM Music Format 1.0 */
648 MIKMODAPI extern struct MLOADER load_dsm; /* DSIK internal module format */
649 MIKMODAPI extern struct MLOADER load_far; /* Farandole Composer (by Daniel Potter) */
650 MIKMODAPI extern struct MLOADER load_gdm; /* General DigiMusic (by Edward Schlunder) */
651 MIKMODAPI extern struct MLOADER load_gt2; /* Graoumf tracker */
652 MIKMODAPI extern struct MLOADER load_it;  /* Impulse Tracker (by Jeffrey Lim) */
653 MIKMODAPI extern struct MLOADER load_imf; /* Imago Orpheus (by Lutz Roeder) */
654 MIKMODAPI extern struct MLOADER load_med; /* Amiga MED modules (by Teijo Kinnunen) */
655 MIKMODAPI extern struct MLOADER load_m15; /* Soundtracker 15-instrument */
656 MIKMODAPI extern struct MLOADER load_mod; /* Standard 31-instrument Module loader */
657 MIKMODAPI extern struct MLOADER load_mtm; /* Multi-Tracker Module (by Renaissance) */
658 MIKMODAPI extern struct MLOADER load_okt; /* Amiga Oktalyzer */
659 MIKMODAPI extern struct MLOADER load_stm; /* ScreamTracker 2 (by Future Crew) */
660 MIKMODAPI extern struct MLOADER load_stx; /* STMIK 0.2 (by Future Crew) */
661 MIKMODAPI extern struct MLOADER load_s3m; /* ScreamTracker 3 (by Future Crew) */
662 MIKMODAPI extern struct MLOADER load_ult; /* UltraTracker (by MAS) */
663 MIKMODAPI extern struct MLOADER load_umx; /* Unreal UMX container of Epic Games */
664 MIKMODAPI extern struct MLOADER load_uni; /* MikMod and APlayer internal module format */
665 MIKMODAPI extern struct MLOADER load_xm;  /* FastTracker 2 (by Triton) */
666
667 /*
668  *  ========== Module player
669  */
670
671 MIKMODAPI extern MODULE* Player_Load(const CHAR*,int,BOOL);
672 MIKMODAPI extern MODULE* Player_LoadFP(FILE*,int,BOOL);
673 MIKMODAPI extern MODULE* Player_LoadMem(const char *buffer,int len,int maxchan,BOOL curious);
674 MIKMODAPI extern MODULE* Player_LoadGeneric(MREADER*,int,BOOL);
675 MIKMODAPI extern CHAR*   Player_LoadTitle(const CHAR*);
676 MIKMODAPI extern CHAR*   Player_LoadTitleFP(FILE*);
677 MIKMODAPI extern CHAR*   Player_LoadTitleMem(const char *buffer,int len);
678 MIKMODAPI extern CHAR*   Player_LoadTitleGeneric(MREADER*);
679
680 MIKMODAPI extern void    Player_Free(MODULE*);
681 MIKMODAPI extern void    Player_Start(MODULE*);
682 MIKMODAPI extern BOOL    Player_Active(void);
683 MIKMODAPI extern void    Player_Stop(void);
684 MIKMODAPI extern void    Player_TogglePause(void);
685 MIKMODAPI extern BOOL    Player_Paused(void);
686 MIKMODAPI extern void    Player_NextPosition(void);
687 MIKMODAPI extern void    Player_PrevPosition(void);
688 MIKMODAPI extern void    Player_SetPosition(UWORD);
689 MIKMODAPI extern BOOL    Player_Muted(UBYTE);
690 MIKMODAPI extern void    Player_SetVolume(SWORD);
691 MIKMODAPI extern MODULE* Player_GetModule(void);
692 MIKMODAPI extern void    Player_SetSpeed(UWORD);
693 MIKMODAPI extern void    Player_SetTempo(UWORD);
694 MIKMODAPI extern void    Player_Unmute(SLONG,...);
695 MIKMODAPI extern void    Player_Mute(SLONG,...);
696 MIKMODAPI extern void    Player_ToggleMute(SLONG,...);
697 MIKMODAPI extern int     Player_GetChannelVoice(UBYTE);
698 MIKMODAPI extern UWORD   Player_GetChannelPeriod(UBYTE);
699 MIKMODAPI extern int     Player_QueryVoices(UWORD numvoices, VOICEINFO *vinfo);
700 MIKMODAPI extern int     Player_GetRow(void);
701 MIKMODAPI extern int     Player_GetOrder(void);
702
703 typedef void (*MikMod_player_t)(void);
704 typedef void (*MikMod_callback_t)(unsigned char *data, size_t len);
705
706 MIKMODAPI extern MikMod_player_t MikMod_RegisterPlayer(MikMod_player_t);
707
708 #define MUTE_EXCLUSIVE  32000
709 #define MUTE_INCLUSIVE  32001
710
711 /*
712  *  ========== Drivers
713  */
714
715 enum {
716     MD_MUSIC = 0,
717     MD_SNDFX
718 };
719
720 enum {
721     MD_HARDWARE = 0,
722     MD_SOFTWARE
723 };
724
725 /* Mixing flags */
726
727 /* These ones take effect only after MikMod_Init or MikMod_Reset */
728 #define DMODE_16BITS     0x0001 /* enable 16 bit output */
729 #define DMODE_STEREO     0x0002 /* enable stereo output */
730 #define DMODE_SOFT_SNDFX 0x0004 /* Process sound effects via software mixer */
731 #define DMODE_SOFT_MUSIC 0x0008 /* Process music via software mixer */
732 #define DMODE_HQMIXER    0x0010 /* Use high-quality (slower) software mixer */
733 #define DMODE_FLOAT      0x0020 /* enable float output */
734 /* These take effect immediately. */
735 #define DMODE_SURROUND   0x0100 /* enable surround sound */
736 #define DMODE_INTERP     0x0200 /* enable interpolation */
737 #define DMODE_REVERSE    0x0400 /* reverse stereo */
738 #define DMODE_SIMDMIXER  0x0800 /* enable SIMD mixing */
739 #define DMODE_NOISEREDUCTION 0x1000 /* Low pass filtering */
740
741
742 struct SAMPLOAD;
743
744 typedef struct MDRIVER {
745     struct MDRIVER* next;
746     const CHAR* Name;
747     const CHAR* Version;
748
749     UBYTE       HardVoiceLimit; /* Limit of hardware mixer voices */
750     UBYTE       SoftVoiceLimit; /* Limit of software mixer voices */
751
752     const CHAR* Alias;
753     const CHAR* CmdLineHelp;
754
755     void        (*CommandLine)      (const CHAR*);
756     BOOL        (*IsPresent)        (void);
757     SWORD       (*SampleLoad)       (struct SAMPLOAD*,int);
758     void        (*SampleUnload)     (SWORD);
759     ULONG       (*FreeSampleSpace)  (int);
760     ULONG       (*RealSampleLength) (int,struct SAMPLE*);
761     int         (*Init)             (void);
762     void        (*Exit)             (void);
763     int         (*Reset)            (void);
764     int         (*SetNumVoices)     (void);
765     int         (*PlayStart)        (void);
766     void        (*PlayStop)         (void);
767     void        (*Update)           (void);
768     void        (*Pause)            (void);
769     void        (*VoiceSetVolume)   (UBYTE,UWORD);
770     UWORD       (*VoiceGetVolume)   (UBYTE);
771     void        (*VoiceSetFrequency)(UBYTE,ULONG);
772     ULONG       (*VoiceGetFrequency)(UBYTE);
773     void        (*VoiceSetPanning)  (UBYTE,ULONG);
774     ULONG       (*VoiceGetPanning)  (UBYTE);
775     void        (*VoicePlay)        (UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD);
776     void        (*VoiceStop)        (UBYTE);
777     BOOL        (*VoiceStopped)     (UBYTE);
778     SLONG       (*VoiceGetPosition) (UBYTE);
779     ULONG       (*VoiceRealVolume)  (UBYTE);
780 } MDRIVER;
781
782 /* These variables can be changed at ANY time and results will be immediate */
783 MIKMODAPI extern UBYTE md_volume;      /* global sound volume (0-128) */
784 MIKMODAPI extern UBYTE md_musicvolume; /* volume of song */
785 MIKMODAPI extern UBYTE md_sndfxvolume; /* volume of sound effects */
786 MIKMODAPI extern UBYTE md_reverb;      /* 0 = none;  15 = chaos */
787 MIKMODAPI extern UBYTE md_pansep;      /* 0 = mono;  128 == 100% (full left/right) */
788
789 /* The variables below can be changed at any time, but changes will not be
790    implemented until MikMod_Reset is called. A call to MikMod_Reset may result
791    in a skip or pop in audio (depending on the soundcard driver and the settings
792    changed). */
793 MIKMODAPI extern UWORD md_device;      /* device */
794 MIKMODAPI extern UWORD md_mixfreq;     /* mixing frequency */
795 MIKMODAPI extern UWORD md_mode;        /* mode. See DMODE_? flags above */
796
797 /* The following variable should not be changed! */
798 MIKMODAPI extern MDRIVER* md_driver;   /* Current driver in use. */
799
800 /* Known drivers list */
801
802 MIKMODAPI extern struct MDRIVER drv_nos;    /* no sound */
803 MIKMODAPI extern struct MDRIVER drv_pipe;   /* piped output */
804 MIKMODAPI extern struct MDRIVER drv_raw;    /* raw file disk writer [music.raw] */
805 MIKMODAPI extern struct MDRIVER drv_stdout; /* output to stdout */
806 MIKMODAPI extern struct MDRIVER drv_wav;    /* RIFF WAVE file disk writer [music.wav] */
807 MIKMODAPI extern struct MDRIVER drv_aiff;   /* AIFF file disk writer [music.aiff] */
808
809 MIKMODAPI extern struct MDRIVER drv_ultra;  /* Linux Ultrasound driver */
810 MIKMODAPI extern struct MDRIVER drv_sam9407;/* Linux sam9407 driver */
811
812 MIKMODAPI extern struct MDRIVER drv_AF;     /* Dec Alpha AudioFile */
813 MIKMODAPI extern struct MDRIVER drv_ahi;    /* Amiga AHI */
814 MIKMODAPI extern struct MDRIVER drv_aix;    /* AIX audio device */
815 MIKMODAPI extern struct MDRIVER drv_alsa;   /* Advanced Linux Sound Architecture (ALSA) */
816 MIKMODAPI extern struct MDRIVER drv_esd;    /* Enlightened sound daemon (EsounD) */
817 MIKMODAPI extern struct MDRIVER drv_pulseaudio; /* PulseAudio  */
818 MIKMODAPI extern struct MDRIVER drv_hp;     /* HP-UX audio device */
819 MIKMODAPI extern struct MDRIVER drv_nas;    /* Network Audio System (NAS) */
820 MIKMODAPI extern struct MDRIVER drv_oss;    /* OpenSound System (Linux,FreeBSD...) */
821 MIKMODAPI extern struct MDRIVER drv_openal; /* OpenAL driver */
822 MIKMODAPI extern struct MDRIVER drv_sdl;    /* SDL audio driver */
823 MIKMODAPI extern struct MDRIVER drv_sgi;    /* SGI audio library */
824 MIKMODAPI extern struct MDRIVER drv_sndio;  /* OpenBSD sndio */
825 MIKMODAPI extern struct MDRIVER drv_sun;    /* Sun/NetBSD/OpenBSD audio device */
826
827 MIKMODAPI extern struct MDRIVER drv_dart;   /* OS/2 Direct Audio RealTime */
828 MIKMODAPI extern struct MDRIVER drv_os2;    /* OS/2 MMPM/2 */
829
830 MIKMODAPI extern struct MDRIVER drv_ds;     /* Win32 DirectSound driver */
831 MIKMODAPI extern struct MDRIVER drv_xaudio2;/* Win32 XAudio2 driver */
832 MIKMODAPI extern struct MDRIVER drv_win;    /* Win32 multimedia API driver */
833
834 MIKMODAPI extern struct MDRIVER drv_mac;    /* Macintosh Sound Manager driver */
835 MIKMODAPI extern struct MDRIVER drv_osx;    /* MacOS X CoreAudio Driver */
836
837 MIKMODAPI extern struct MDRIVER drv_dc;     /* Dreamcast driver */
838 MIKMODAPI extern struct MDRIVER drv_gp32;   /* GP32 Sound driver */
839 MIKMODAPI extern struct MDRIVER drv_psp;    /* PlayStation Portable driver */
840
841 MIKMODAPI extern struct MDRIVER drv_wss;    /* DOS WSS driver */
842 MIKMODAPI extern struct MDRIVER drv_sb;     /* DOS S/B driver */
843
844 MIKMODAPI extern struct MDRIVER drv_osles;  /* OpenSL ES driver for android */
845
846 /*========== Virtual channel mixer interface (for user-supplied drivers only) */
847
848 MIKMODAPI extern int   VC_Init(void);
849 MIKMODAPI extern void  VC_Exit(void);
850 MIKMODAPI extern void  VC_SetCallback(MikMod_callback_t callback);
851 MIKMODAPI extern int   VC_SetNumVoices(void);
852 MIKMODAPI extern ULONG VC_SampleSpace(int);
853 MIKMODAPI extern ULONG VC_SampleLength(int,SAMPLE*);
854
855 MIKMODAPI extern int   VC_PlayStart(void);
856 MIKMODAPI extern void  VC_PlayStop(void);
857
858 MIKMODAPI extern SWORD VC_SampleLoad(struct SAMPLOAD*,int);
859 MIKMODAPI extern void  VC_SampleUnload(SWORD);
860
861 MIKMODAPI extern ULONG VC_WriteBytes(SBYTE*,ULONG);
862 MIKMODAPI extern ULONG VC_SilenceBytes(SBYTE*,ULONG);
863
864 MIKMODAPI extern void  VC_VoiceSetVolume(UBYTE,UWORD);
865 MIKMODAPI extern UWORD VC_VoiceGetVolume(UBYTE);
866 MIKMODAPI extern void  VC_VoiceSetFrequency(UBYTE,ULONG);
867 MIKMODAPI extern ULONG VC_VoiceGetFrequency(UBYTE);
868 MIKMODAPI extern void  VC_VoiceSetPanning(UBYTE,ULONG);
869 MIKMODAPI extern ULONG VC_VoiceGetPanning(UBYTE);
870 MIKMODAPI extern void  VC_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD);
871
872 MIKMODAPI extern void  VC_VoiceStop(UBYTE);
873 MIKMODAPI extern BOOL  VC_VoiceStopped(UBYTE);
874 MIKMODAPI extern SLONG VC_VoiceGetPosition(UBYTE);
875 MIKMODAPI extern ULONG VC_VoiceRealVolume(UBYTE);
876
877 #ifdef __cplusplus
878 }
879 #endif
880
881 #endif
882
883 /* ex:set ts=4: */