DEADSOFTWARE

Sound: OpenAL: Add MIDI support via FluidSynth
[d2df-sdl.git] / src / lib / xmp / xmp.pas
1 unit XMP;
3 interface
5 {$IFDEF FPC}
6 {$PACKRECORDS C}
7 {$MODE OBJFPC}
8 {$ENDIF}
10 {$IFDEF WINDOWS}
11 {$IFNDEF LIBXMP_WINDOZE_STATIC}
12 {$DEFINE XMP_DYNAMIC}
13 {$ENDIF}
14 {$ENDIF}
16 {$IF DEFINED(XMP_DYNAMIC)}
17 const
18 {$IF DEFINED(WINDOWS)}
19 {$IF DEFINED(USE_XMP_FULL)}
20 xmplib = 'libxmp.dll';
21 {$ELSE}
22 xmplib = 'libxmp-lite.dll';
23 {$ENDIF}
24 {$ELSEIF DEFINED(UNIX)}
25 {$IF DEFINED(USE_XMP_FULL)}
26 xmplib = 'libxmp.so';
27 {$ELSE}
28 xmplib = 'libxmp-lite.so';
29 {$ENDIF}
30 {$ELSE}
31 {$MESSAGE ERROR 'XMP_DYNAMIC not supported'}
32 {$IFEND}
33 {$ELSE}
34 {$IF DEFINED(USE_XMP_FULL)}
35 {$LINKLIB libxmp.a}
36 {$ELSE}
37 {$LINKLIB libxmp-lite.a}
38 {$ENDIF}
39 {$ENDIF}
41 const
42 XMP_VER_STRING = '4.4.1';
43 XMP_VER_CODE = $040401;
44 XMP_VER_MAJOR = 4;
45 XMP_VER_MINOR = 4;
46 XMP_VER_RELEASE = 1;
48 const
49 XMP_NAME_SIZE = 64; (* Size of module name and type *)
50 XMP_KEY_OFF = $81; (* Note number for key off event *)
51 XMP_KEY_CUT = $82; (* Note number for key cut event *)
52 XMP_KEY_FADE = $83; (* Note number for fade event *)
53 (* mixer parameter macros *)
54 (* sample format flags *)
55 XMP_FORMAT_8BIT = (1 shl 0); (* Mix to 8-bit instead of 16 *)
56 XMP_FORMAT_UNSIGNED = (1 shl 1); (* Mix to unsigned samples *)
57 XMP_FORMAT_MONO = (1 shl 2); (* Mix to mono instead of stereo *)
58 (* player parameters *)
59 XMP_PLAYER_AMP = 0; (* Amplification factor *)
60 XMP_PLAYER_MIX = 1; (* Stereo mixing *)
61 XMP_PLAYER_INTERP = 2; (* Interpolation type *)
62 XMP_PLAYER_DSP = 3; (* DSP effect flags *)
63 XMP_PLAYER_FLAGS = 4; (* Player flags *)
64 XMP_PLAYER_CFLAGS = 5; (* Player flags for current module *)
65 XMP_PLAYER_SMPCTL = 6; (* Sample control flags *)
66 XMP_PLAYER_VOLUME = 7; (* Player module volume *)
67 XMP_PLAYER_STATE = 8; (* Internal player state (read only) *)
68 XMP_PLAYER_SMIX_VOLUME = 9; (* SMIX volume *)
69 XMP_PLAYER_DEFPAN = 10; (* Default pan setting *)
70 XMP_PLAYER_MODE = 11; (* Player personality *)
71 XMP_PLAYER_MIXER_TYPE = 12; (* Current mixer (read only) *)
72 XMP_PLAYER_VOICES = 13; (* Maximum number of mixer voices *)
73 (* interpolation types *)
74 XMP_INTERP_NEAREST = 0; (* Nearest neighbor *)
75 XMP_INTERP_LINEAR = 1; (* Linear (default) *)
76 XMP_INTERP_SPLINE = 2; (* Cubic spline *)
77 (* dsp effect types *)
78 XMP_DSP_LOWPASS = (1 shl 0); (* Lowpass filter effect *)
79 XMP_DSP_ALL = (XMP_DSP_LOWPASS);
80 (* player state *)
81 XMP_STATE_UNLOADED = 0; (* Context created *)
82 XMP_STATE_LOADED = 1; (* Module loaded *)
83 XMP_STATE_PLAYING = 2; (* Module playing *)
84 (* player flags *)
85 XMP_FLAGS_VBLANK = (1 shl 0); (* Use vblank timing *)
86 XMP_FLAGS_FX9BUG = (1 shl 1); (* Emulate FX9 bug *)
87 XMP_FLAGS_FIXLOOP = (1 shl 2); (* Emulate sample loop bug *)
88 XMP_FLAGS_A500 = (1 shl 3); (* Use Paula mixer in Amiga modules *)
89 (* player modes *)
90 XMP_MODE_AUTO = 0; (* Autodetect mode (default) *)
91 XMP_MODE_MOD = 1; (* Play as a generic MOD player *)
92 XMP_MODE_NOISETRACKER = 2; (* Play using Noisetracker quirks *)
93 XMP_MODE_PROTRACKER = 3; (* Play using Protracker quirks *)
94 XMP_MODE_S3M = 4; (* Play as a generic S3M player *)
95 XMP_MODE_ST3 = 5; (* Play using ST3 bug emulation *)
96 XMP_MODE_ST3GUS = 6; (* Play using ST3+GUS quirks *)
97 XMP_MODE_XM = 7; (* Play as a generic XM player *)
98 XMP_MODE_FT2 = 8; (* Play using FT2 bug emulation *)
99 XMP_MODE_IT = 9; (* Play using IT quirks *)
100 XMP_MODE_ITSMP = 10; (* Play using IT sample mode quirks *)
101 (* mixer types *)
102 XMP_MIXER_STANDARD = 0; (* Standard mixer *)
103 XMP_MIXER_A500 = 1; (* Amiga 500 *)
104 XMP_MIXER_A500F = 2; (* Amiga 500 with led filter *)
105 (* sample flags *)
106 XMP_SMPCTL_SKIP = (1 shl 0); (* Don't load samples *)
107 (* limits *)
108 XMP_MAX_KEYS = 121; (* Number of valid keys *)
109 XMP_MAX_ENV_POINTS = 32; (* Max number of envelope points *)
110 XMP_MAX_MOD_LENGTH = 256; (* Max number of patterns in module *)
111 XMP_MAX_CHANNELS = 64; (* Max number of channels in module *)
112 XMP_MAX_SRATE = 49170; (* max sampling rate (Hz) *)
113 XMP_MIN_SRATE = 4000; (* min sampling rate (Hz) *)
114 XMP_MIN_BPM = 20; (* min BPM *)
115 (* frame rate = (50 * bpm / 125) Hz *)
116 (* frame size = (sampling rate * channels * size) / frame rate *)
117 XMP_MAX_FRAMESIZE = (5*XMP_MAX_SRATE*2 div XMP_MIN_BPM);
118 (* error codes *)
119 XMP_END = 1;
120 XMP_ERROR_INTERNAL = 2; (* Internal error *)
121 XMP_ERROR_FORMAT = 3; (* Unsupported module format *)
122 XMP_ERROR_LOAD = 4; (* Error loading file *)
123 XMP_ERROR_DEPACK = 5; (* Error depacking file *)
124 XMP_ERROR_SYSTEM = 6; (* System error *)
125 XMP_ERROR_INVALID = 7; (* Invalid parameter *)
126 XMP_ERROR_STATE = 8; (* Invalid player state *)
128 const
129 XMP_CHANNEL_SYNTH = (1 shl 0); (* Channel is synthesized *)
130 XMP_CHANNEL_MUTED = (1 shl 1); (* Channel is muted *)
131 XMP_CHANNEL_SPLIT = (1 shl 2); (* Split Amiga channel in bits 5-4 *)
132 XMP_CHANNEL_SURROUND = (1 shl 4); (* Surround channel *)
134 const
135 XMP_ENVELOPE_ON = (1 shl 0); (* Envelope is enabled *)
136 XMP_ENVELOPE_SUS = (1 shl 1); (* Envelope has sustain point *)
137 XMP_ENVELOPE_LOOP = (1 shl 2); (* Envelope has loop *)
138 XMP_ENVELOPE_FLT = (1 shl 3); (* Envelope is used for filter *)
139 XMP_ENVELOPE_SLOOP = (1 shl 4); (* Envelope has sustain loop *)
140 XMP_ENVELOPE_CARRY = (1 shl 5); (* Don't reset envelope position *)
142 const
143 XMP_INST_NNA_CUT = $00;
144 XMP_INST_NNA_CONT = $01;
145 XMP_INST_NNA_OFF = $02;
146 XMP_INST_NNA_FADE = $03;
147 XMP_INST_DCT_OFF = $00;
148 XMP_INST_DCT_NOTE = $01;
149 XMP_INST_DCT_SMP = $02;
150 XMP_INST_DCT_INST = $03;
151 XMP_INST_DCA_CUT = XMP_INST_NNA_CUT;
152 XMP_INST_DCA_OFF = XMP_INST_NNA_OFF;
153 XMP_INST_DCA_FADE = XMP_INST_NNA_FADE;
155 const
156 XMP_SAMPLE_16BIT = (1 shl 0); (* 16bit sample *)
157 XMP_SAMPLE_LOOP = (1 shl 1); (* Sample is looped *)
158 XMP_SAMPLE_LOOP_BIDIR = (1 shl 2); (* Bidirectional sample loop *)
159 XMP_SAMPLE_LOOP_REVERSE = (1 shl 3); (* Backwards sample loop *)
160 XMP_SAMPLE_LOOP_FULL = (1 shl 4); (* Play full sample before looping *)
161 XMP_SAMPLE_SLOOP = (1 shl 5); (* Sample has sustain loop *)
162 XMP_SAMPLE_SLOOP_BIDIR = (1 shl 6); (* Bidirectional sustain loop *)
163 XMP_SAMPLE_SYNTH = (1 shl 15); (* Data contains synth patch *)
165 type
166 xmp_channel = record
167 pan: longint; (* Channel pan (0x80 is center) *)
168 vol: longint; (* Channel volume *)
169 flg: longint; (* Channel flags *)
170 end;
172 xmp_pattern = record
173 rows: longint; (* Number of rows *)
174 index: array [0..0] of longint; (* Track index *)
175 end;
177 xmp_event = record
178 note: byte; (* Note number (0 means no note) *)
179 ins: byte; (* Patch number *)
180 vol: byte; (* Volume (0 to basevol) *)
181 fxt: byte; (* Effect type *)
182 fxp: byte; (* Effect parameter *)
183 f2t: byte; (* Secondary effect type *)
184 f2p: byte; (* Secondary effect parameter *)
185 _flag: byte; (* Internal (reserved) flags *)
186 end;
188 pxmp_event = ^xmp_event;
190 xmp_track = record
191 rows: longint; (* Number of rows *)
192 event: array [0..0] of xmp_event; (* Event data *)
193 end;
195 xmp_envelope = record
196 flg: longint; (* Flags *)
197 npt: longint; (* Number of envelope points *)
198 scl: longint; (* Envelope scaling *)
199 sus: longint; (* Sustain start point *)
200 sue: longint; (* Sustain end point *)
201 lps: longint; (* Loop start point *)
202 lpe: longint; (* Loop end point *)
203 data: array [0..(XMP_MAX_ENV_POINTS*2)-1] of smallint;
204 end;
206 xmp_subinstrument = record
207 vol: longint; (* Default volume *)
208 gvl: longint; (* Global volume *)
209 pan: longint; (* Pan *)
210 xpo: longint; (* Transpose *)
211 fin: longint; (* Finetune *)
212 vwf: longint; (* Vibrato waveform *)
213 vde: longint; (* Vibrato depth *)
214 vra: longint; (* Vibrato rate *)
215 vsw: longint; (* Vibrato sweep *)
216 rvv: longint; (* Random volume/pan variation (IT) *)
217 sid: longint; (* Sample number *)
218 nna: longint; (* New note action *)
219 dct: longint; (* Duplicate check type *)
220 dca: longint; (* Duplicate check action *)
221 ifc: longint; (* Initial filter cutoff *)
222 ifr: longint; (* Initial filter resonance *)
223 end;
225 pxmp_subinstrument = ^xmp_subinstrument;
227 xmp_instrument = record
228 name: array [0..31] of char; (* Instrument name *)
229 vol: longint; (* Instrument volume *)
230 nsm: longint; (* Number of samples *)
231 rls: longint; (* Release (fadeout) *)
232 aei: xmp_envelope; (* Amplitude envelope info *)
233 pei: xmp_envelope; (* Pan envelope info *)
234 fei: xmp_envelope; (* Frequency envelope info *)
235 map : array[0..(XMP_MAX_KEYS)-1] of record
236 ins : byte;
237 xpo : char;
238 end;
239 sub: pxmp_subinstrument;
240 extra: pointer;
241 end;
243 xmp_sample = record
244 name: array [0..31] of char; (* Sample name *)
245 len: longint; (* Sample length *)
246 lps: longint; (* Loop start *)
247 lpe: longint; (* Loop end *)
248 flg: longint; (* Flags *)
249 data: pbyte; (* Sample data *)
250 end;
252 xmp_sequence = record
253 entry_point: longint;
254 duration: longint;
255 end;
257 pxmp_sequence = ^xmp_sequence;
259 xmp_module = record
260 name: array [0..XMP_NAME_SIZE-1] of char; (* Module title *)
261 format: array [0..XMP_NAME_SIZE-1] of char; (* Module format *)
263 pat: longint; (* Number of patterns *)
264 trk: longint; (* Number of tracks *)
265 chn: longint; (* Tracks per pattern *)
266 ins: longint; (* Number of instruments *)
267 smp: longint; (* Number of samples *)
268 spd: longint; (* Initial speed *)
269 bpm: longint; (* Initial BPM *)
270 len: longint; (* Module length in patterns *)
271 rst: longint; (* Restart position *)
272 gvl: longint; (* Global volume *)
274 xxp: pointer; // xmp_pattern**
275 xxt: pointer; // xmp_track**
276 xxi: pointer; // xmp_instrument*
277 xxs: pointer; // xmp_sample*
278 xxc: array [0..XMP_MAX_CHANNELS-1] of xmp_channel;
279 xxo: array [0..XMP_MAX_MOD_LENGTH-1] of byte;
280 end;
282 pxmp_module = ^xmp_module;
284 xmp_test_info = record
285 name: array [0..XMP_NAME_SIZE-1] of char; (* Module title *)
286 format: array [0..XMP_NAME_SIZE-1] of char; (* Module format *)
287 end;
289 xmp_module_info = record
290 md5: array [0..15] of byte; (* MD5 message digest *)
291 vol_base: longint; (* Volume scale *)
292 module: pxmp_module; (* Pointer to module data *)
293 comment: pchar; (* Comment text, if any *)
294 num_sequences: longint; (* Number of valid sequences *)
295 seq_data: pxmp_sequence; (* Pointer to sequence data *)
296 end;
298 xmp_channel_info = record
299 period: longword; (* Sample period (times 4096) *)
300 position: longword; (* Sample position *)
301 pitchbend: word; (* Linear bend from base note*)
302 note: byte; (* Current base note number *)
303 instrument: byte; (* Current instrument number *)
304 usample: byte; (* Current sample number *)
305 volume: byte; (* Current volume *)
306 pan: byte; (* Current stereo pan *)
307 reserved: byte; (* Reserved *)
308 event: xmp_event; (* Current track event *)
309 end;
311 (* Current frame information *)
312 xmp_frame_info = record
313 pos: longint; (* Current position *)
314 pattern: longint; (* Current pattern *)
315 row: longint; (* Current row in pattern *)
316 num_rows: longint; (* Number of rows in current pattern *)
317 frame: longint; (* Current frame *)
318 speed: longint; (* Current replay speed *)
319 bpm: longint; (* Current bpm *)
320 time: longint; (* Current module time in ms *)
321 total_time: longint; (* Estimated replay time in ms*)
322 frame_time: longint; (* Frame replay time in us *)
323 buffer: plongint; (* Pointer to sound buffer *)
324 buffer_size: longint; (* Used buffer size *)
325 total_size: longint; (* Total buffer size *)
326 volume: longint; (* Current master volume *)
327 loop_count: longint; (* Loop counter *)
328 virt_channels: longint; (* Number of virtual channels *)
329 virt_used: longint; (* Used virtual channels *)
330 sequence: longint; (* Current sequence *)
331 channel_info: array [0..XMP_MAX_CHANNELS-1] of xmp_channel_info;
332 end;
334 xmp_context = pointer;
336 var
337 xmp_version: pchar; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
338 xmp_vercode: longword; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
340 function xmp_create_context(): xmp_context; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
341 procedure xmp_free_context(ctx: xmp_context); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
342 function xmp_get_format_list(): ppchar; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
344 function xmp_test_module(fname: pchar; var info: xmp_test_info): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
345 function xmp_load_module(ctx: xmp_context; fname: pchar): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
346 function xmp_load_module_from_memory(ctx: xmp_context; buf: pointer; bufsiz: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
347 function xmp_load_module_from_file(ctx: xmp_context; fstream: pointer; msize: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
348 procedure xmp_scan_module(ctx: xmp_context); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
349 procedure xmp_get_module_info(ctx: xmp_context; var info: xmp_module_info); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
350 procedure xmp_release_module(ctx: xmp_context); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
352 function xmp_start_player(ctx: xmp_context; rate, format: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
353 function xmp_play_frame(ctx: xmp_context): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
354 function xmp_play_buffer(ctx: xmp_context; buf: pointer; bufsiz: longint; loop: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
355 procedure xmp_get_frame_info(ctx: xmp_context; var info: xmp_frame_info); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
356 procedure xmp_end_player(ctx: xmp_context); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
358 procedure xmp_inject_event(ctx: xmp_context; ch: longint; ev: pxmp_event); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
360 function xmp_next_position(ctx: xmp_context): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
361 function xmp_prev_position(ctx: xmp_context): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
362 function xmp_set_position(ctx: xmp_context; pos: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
363 function xmp_seek_time(ctx: xmp_context; ms: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
364 procedure xmp_stop_module(ctx: xmp_context); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
365 procedure xmp_restart_module(ctx: xmp_context); cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
367 function xmp_channel_mute(ctx: xmp_context; ch, mute: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
368 function xmp_channel_vol(ctx: xmp_context; ch, vol: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
370 function xmp_set_player(ctx: xmp_context; param, value: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
371 function xmp_get_player(ctx: xmp_context; param: longint): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
372 function xmp_set_instrument_path(ctx: xmp_context; path: pchar): longint; cdecl; external {$IFDEF XMP_DYNAMIC}xmplib{$ENDIF};
374 (*
375 function xmp_start_smix;
376 procedure xmp_end_smix;
377 function xmp_smix_play_instrument;
378 function xmp_smix_play_sample;
379 function xmp_smix_channel_pan;
380 function xmp_smix_load_sample;
381 function xmp_smix_release_sample;
382 *)
384 implementation
387 end.