DEADSOFTWARE

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