DEADSOFTWARE

Sound: OpenAL: Add MIDI support via FluidSynth
[d2df-sdl.git] / src / lib / mpg123 / mpg123.pas
1 //
2 // mpg123.h header binding for the Free Pascal Compiler aka FPC
3 //
4 // Binaries and demos available at http://www.djmaster.com/
5 //
7 (*
8 libmpg123: MPEG Audio Decoder library
10 copyright 1995-2015 by the mpg123 project
11 free software under the terms of the LGPL 2.1
12 see COPYING and AUTHORS files in distribution or http://mpg123.org
13 *)
16 (** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder *)
18 unit mpg123;
20 {$MODE OBJFPC}{$H+}
22 interface
24 uses
25 ctypes;
27 {$IFDEF FPC}
28 {$PACKRECORDS C}
29 {$ENDIF}
31 {$IFDEF WINDOWS}
32 {$IFNDEF LIBMPG123_WINDOZE_STATIC}
33 {$DEFINE MPG123_DYNAMIC}
34 {$ENDIF}
35 {$ENDIF}
37 {$IF DEFINED(MPG123_DYNAMIC)}
38 const
39 {$IF DEFINED(WINDOWS)}
40 LIB_MPG123 = 'libmpg123-0.dll';
41 {$ELSEIF DEFINED(UNIX)}
42 LIB_MPG123 = 'libmpg123.so';
43 {$ELSE}
44 {$MESSAGE ERROR 'MPG123_DYNAMIC not supported'}
45 {$IFEND}
46 {$ELSE}
47 {$LINKLIB libmpg123.a}
48 {$ENDIF}
50 type
51 ppcchar = ^pcchar;
52 ppclong = ^pclong;
53 pcsize_t = ^csize_t;
54 ppcint = ^pcint;
55 (* off_t = cint; *)
56 off_t = coff_t;
57 ppoff_t = ^poff_t;
58 poff_t = ^coff_t;
59 ppcuchar = ^pcuchar;
61 const
62 (** A macro to check at compile time which set of API functions to expect.
63 * This should be incremented at least each time a new symbol is added
64 * to the header.
65 *)
66 MPG123_LIB_VERSION = '1.25.11';
67 MPG123_API_VERSION = 44;
68 MPG123_LIB_PATCHLEVEL = 7;
70 //TODO /** Defines needed for MS Visual Studio(tm) DLL builds.
71 //TODO * Every public function must be prefixed with MPG123_EXPORT. When building
72 //TODO * the DLL ensure to define BUILD_MPG123_DLL. This makes the function accessible
73 //TODO * for clients and includes it in the import library which is created together
74 //TODO * with the DLL. When consuming the DLL ensure to define LINK_MPG123_DLL which
75 //TODO * imports the functions from the DLL.
76 //TODO */
77 //TODO #ifdef BUILD_MPG123_DLL
78 //TODO /* The dll exports. */
79 //TODO #define MPG123_EXPORT __declspec(dllexport)
80 //TODO #else
81 //TODO #ifdef LINK_MPG123_DLL
82 //TODO /* The exe imports. */
83 //TODO #define MPG123_EXPORT __declspec(dllimport)
84 //TODO #else
85 //TODO /* Nothing on normal/UNIX builds */
86 //TODO #define MPG123_EXPORT
87 //TODO #endif
88 //TODO #endif
89 //TODO
90 //TODO /* This is for Visual Studio, so this header works as distributed in the binary downloads */
91 //TODO #if defined(_MSC_VER) && !defined(MPG123_DEF_SSIZE_T)
92 //TODO #define MPG123_DEF_SSIZE_T
93 //TODO #include <stddef.h>
94 //TODO typedef ptrdiff_t ssize_t;
95 //TODO #endif
96 //TODO
97 //TODO #ifndef MPG123_NO_CONFIGURE /* Enable use of this file without configure. */
98 //TODO #include <stdlib.h>
99 //TODO #include <sys/types.h>
100 //TODO
101 //TODO /* Simplified large file handling.
102 //TODO I used to have a check here that prevents building for a library with conflicting large file setup
103 //TODO (application that uses 32 bit offsets with library that uses 64 bits).
104 //TODO While that was perfectly fine in an environment where there is one incarnation of the library,
105 //TODO it hurt GNU/Linux and Solaris systems with multilib where the distribution fails to provide the
106 //TODO correct header matching the 32 bit library (where large files need explicit support) or
107 //TODO the 64 bit library (where there is no distinction).
108 //TODO
109 //TODO New approach: When the app defines _FILE_OFFSET_BITS, it wants non-default large file support,
110 //TODO and thus functions with added suffix (mpg123_open_64).
111 //TODO Any mismatch will be caught at link time because of the _FILE_OFFSET_BITS setting used when
112 //TODO building libmpg123. Plus, there's dual mode large file support in mpg123 since 1.12 now.
113 //TODO Link failure is not the expected outcome of any half-sane usage anymore.
114 //TODO
115 //TODO More complication: What about client code defining _LARGEFILE64_SOURCE? It might want direct access to the _64 functions, along with the ones without suffix. Well, that's possible now via defining MPG123_NO_LARGENAME and MPG123_LARGESUFFIX, respectively, for disabling or enforcing the suffix names.
116 //TODO */
117 //TODO
118 //TODO /*
119 //TODO Now, the renaming of large file aware functions.
120 //TODO By default, it appends underscore _FILE_OFFSET_BITS (so, mpg123_seek_64 for mpg123_seek), if _FILE_OFFSET_BITS is defined. You can force a different suffix via MPG123_LARGESUFFIX (that must include the underscore), or you can just disable the whole mess by defining MPG123_NO_LARGENAME.
121 //TODO */
122 //TODO #if (!defined MPG123_NO_LARGENAME) && ((defined _FILE_OFFSET_BITS) || (defined MPG123_LARGESUFFIX))
123 //TODO
124 //TODO /* Need some trickery to concatenate the value(s) of the given macro(s). */
125 //TODO #define MPG123_MACROCAT_REALLY(a, b) a ## b
126 //TODO #define MPG123_MACROCAT(a, b) MPG123_MACROCAT_REALLY(a, b)
127 //TODO #ifndef MPG123_LARGESUFFIX
128 //TODO #define MPG123_LARGESUFFIX MPG123_MACROCAT(_, _FILE_OFFSET_BITS)
129 //TODO #endif
130 //TODO #define MPG123_LARGENAME(func) MPG123_MACROCAT(func, MPG123_LARGESUFFIX)
131 //TODO
132 //TODO #define mpg123_open MPG123_LARGENAME(mpg123_open)
133 //TODO #define mpg123_open_fd MPG123_LARGENAME(mpg123_open_fd)
134 //TODO #define mpg123_open_handle MPG123_LARGENAME(mpg123_open_handle)
135 //TODO #define mpg123_framebyframe_decode MPG123_LARGENAME(mpg123_framebyframe_decode)
136 //TODO #define mpg123_decode_frame MPG123_LARGENAME(mpg123_decode_frame)
137 //TODO #define mpg123_tell MPG123_LARGENAME(mpg123_tell)
138 //TODO #define mpg123_tellframe MPG123_LARGENAME(mpg123_tellframe)
139 //TODO #define mpg123_tell_stream MPG123_LARGENAME(mpg123_tell_stream)
140 //TODO #define mpg123_seek MPG123_LARGENAME(mpg123_seek)
141 //TODO #define mpg123_feedseek MPG123_LARGENAME(mpg123_feedseek)
142 //TODO #define mpg123_seek_frame MPG123_LARGENAME(mpg123_seek_frame)
143 //TODO #define mpg123_timeframe MPG123_LARGENAME(mpg123_timeframe)
144 //TODO #define mpg123_index MPG123_LARGENAME(mpg123_index)
145 //TODO #define mpg123_set_index MPG123_LARGENAME(mpg123_set_index)
146 //TODO #define mpg123_position MPG123_LARGENAME(mpg123_position)
147 //TODO #define mpg123_length MPG123_LARGENAME(mpg123_length)
148 //TODO #define mpg123_framelength MPG123_LARGENAME(mpg123_framelength)
149 //TODO #define mpg123_set_filesize MPG123_LARGENAME(mpg123_set_filesize)
150 //TODO #define mpg123_replace_reader MPG123_LARGENAME(mpg123_replace_reader)
151 //TODO #define mpg123_replace_reader_handle MPG123_LARGENAME(mpg123_replace_reader_handle)
152 //TODO #define mpg123_framepos MPG123_LARGENAME(mpg123_framepos)
153 //TODO
154 //TODO #endif /* largefile hackery */
155 //TODO
156 //TODO #endif /* MPG123_NO_CONFIGURE */
158 (** \defgroup mpg123_init mpg123 library and handle setup
160 * Functions to initialise and shutdown the mpg123 library and handles.
161 * The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)
162 * Tip: Use a RVA setting...
164 * @{
165 *)
167 (** Opaque structure for the libmpg123 decoder handle. *)
168 type
169 pmpg123_handle_struct = ^mpg123_handle_struct;
170 mpg123_handle_struct = record
171 end;
173 (** Opaque structure for the libmpg123 decoder handle.
174 * Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.
175 *)
176 type
177 pmpg123_handle = ^mpg123_handle;
178 mpg123_handle = pmpg123_handle_struct;
180 (** Function to initialise the mpg123 library.
181 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library.
183 * \return MPG123_OK if successful, otherwise an error number.
184 *)
185 function mpg123_init(): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
187 (** Function to close down the mpg123 library.
188 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. *)
189 procedure mpg123_exit(); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
191 (** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).
192 * and optional retrieval of an error code to feed to mpg123_plain_strerror().
193 * Optional means: Any of or both the parameters may be NULL.
195 * \param decoder optional choice of decoder variant (NULL for default)
196 * \param error optional address to store error codes
197 * \return Non-NULL pointer to fresh handle when successful.
198 *)
199 function mpg123_new(const decoder: pchar; error: pcint): pmpg123_handle; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
201 (** Delete handle, mh is either a valid mpg123 handle or NULL.
202 * \param mh handle
203 *)
204 procedure mpg123_delete(mh: pmpg123_handle); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
206 (** Enumeration of the parameters types that it is possible to set/get. *)
207 type
208 mpg123_parms = clong;
209 const
210 MPG123_VERBOSE = 0; (**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) *)
211 MPG123_FLAGS = 1; (**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) *)
212 MPG123_ADD_FLAGS = 2; (**< add some flags (integer) *)
213 MPG123_FORCE_RATE = 3; (**< when value > 0, force output rate to that value (integer) *)
214 MPG123_DOWN_SAMPLE = 4; (**< 0=native rate, 1=half rate, 2=quarter rate (integer) *)
215 MPG123_RVA = 5; (**< one of the RVA choices above (integer) *)
216 MPG123_DOWNSPEED = 6; (**< play a frame N times (integer) *)
217 MPG123_UPSPEED = 7; (**< play every Nth frame (integer) *)
218 MPG123_START_FRAME = 8; (**< start with this frame (skip frames before that, integer) *)
219 MPG123_DECODE_FRAMES = 9; (**< decode only this number of frames (integer) *)
220 MPG123_ICY_INTERVAL = 10; (**< stream contains ICY metadata with this interval (integer) *)
221 MPG123_OUTSCALE = 11; (**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) *)
222 MPG123_TIMEOUT = 12; (**< timeout for reading from a stream (not supported on win32, integer) *)
223 MPG123_REMOVE_FLAGS = 13; (**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) *)
224 MPG123_RESYNC_LIMIT = 14; (**< Try resync on frame parsing for that many bytes or until end of stream (<0 ... integer). This can enlarge the limit for skipping junk on beginning, too (but not reduce it). *)
225 MPG123_INDEX_SIZE = 15; (**< Set the frame index size (if supported). Values <0 mean that the index is allowed to grow dynamically in these steps (in positive direction, of course) -- Use this when you really want a full index with every individual frame. *)
226 MPG123_PREFRAMES = 16; (**< Decode/ignore that many frames in advance for layer 3. This is needed to fill bit reservoir after seeking, for example (but also at least one frame in advance is needed to have all "normal" data for layer 3). Give a positive integer value, please.*)
227 MPG123_FEEDPOOL = 17; (**< For feeder mode, keep that many buffers in a pool to avoid frequent malloc/free. The pool is allocated on mpg123_open_feed(). If you change this parameter afterwards, you can trigger growth and shrinkage during decoding. The default value could change any time. If you care about this, then set it. (integer) *)
228 MPG123_FEEDBUFFER = 18; (**< Minimal size of one internal feeder buffer, again, the default value is subject to change. (integer) *)
230 (** Flag bits for MPG123_FLAGS, use the usual binary or to combine. *)
231 type
232 mpg123_param_flags = clong;
233 const
234 MPG123_FORCE_MONO = $7; (**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. *)
235 MPG123_MONO_LEFT = $1; (**< 0001 Force playback of left channel only. *)
236 MPG123_MONO_RIGHT = $2; (**< 0010 Force playback of right channel only. *)
237 MPG123_MONO_MIX = $4; (**< 0100 Force playback of mixed mono. *)
238 MPG123_FORCE_STEREO = $8; (**< 1000 Force stereo output. *)
239 MPG123_FORCE_8BIT = $10; (**< 00010000 Force 8bit formats. *)
240 MPG123_QUIET = $20; (**< 00100000 Suppress any printouts (overrules verbose). *)
241 MPG123_GAPLESS = $40; (**< 01000000 Enable gapless decoding (default on if libmpg123 has support). *)
242 MPG123_NO_RESYNC = $80; (**< 10000000 Disable resync stream after error. *)
243 MPG123_SEEKBUFFER = $100; (**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). *)
244 MPG123_FUZZY = $200; (**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) *)
245 MPG123_FORCE_FLOAT = $400; (**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). *)
246 MPG123_PLAIN_ID3TEXT = $800; (**< 100000000000 Do not translate ID3 text data to UTF-8. ID3 strings will contain the raw text data, with the first byte containing the ID3 encoding code. *)
247 MPG123_IGNORE_STREAMLENGTH = $1000; (**< 1000000000000 Ignore any stream length information contained in the stream, which can be contained in a 'TLEN' frame of an ID3v2 tag or a Xing tag *)
248 MPG123_SKIP_ID3V2 = $2000; (**< 10 0000 0000 0000 Do not parse ID3v2 tags, just skip them. *)
249 MPG123_IGNORE_INFOFRAME = $4000; (**< 100 0000 0000 0000 Do not parse the LAME/Xing info frame, treat it as normal MPEG data. *)
250 MPG123_AUTO_RESAMPLE = $8000; (**< 1000 0000 0000 0000 Allow automatic internal resampling of any kind (default on if supported). Especially when going lowlevel with replacing output buffer, you might want to unset this flag. Setting MPG123_DOWNSAMPLE or MPG123_FORCE_RATE will override this. *)
251 MPG123_PICTURE = $10000; (**< 17th bit: Enable storage of pictures from tags (ID3v2 APIC). *)
252 MPG123_NO_PEEK_END = $20000; (**< 18th bit: Do not seek to the end of
253 * the stream in order to probe
254 * the stream length and search for the id3v1 field. This also means
255 * the file size is unknown unless set using mpg123_set_filesize() and
256 * the stream is assumed as non-seekable unless overridden.
257 *)
258 MPG123_FORCE_SEEKABLE = $40000; (**< 19th bit: Force the stream to be seekable. *)
261 (** choices for MPG123_RVA *)
262 type
263 mpg123_param_rva = clong;
264 const
265 MPG123_RVA_OFF = 0; (**< RVA disabled (default). *)
266 MPG123_RVA_MIX = 1; (**< Use mix/track/radio gain. *)
267 MPG123_RVA_ALBUM = 2; (**< Use album/audiophile gain *)
268 MPG123_RVA_MAX = MPG123_RVA_ALBUM; (**< The maximum RVA code, may increase in future. *)
270 (** Set a specific parameter, for a specific mpg123_handle, using a parameter
271 * type key chosen from the mpg123_parms enumeration, to the specified value.
272 * \param mh handle
273 * \param type parameter choice
274 * \param value integer value
275 * \param fvalue floating point value
276 * \return MPG123_OK on success
277 *)
278 function mpg123_param(mh: pmpg123_handle; _type: mpg123_parms; value: clong; fvalue: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
280 (** Get a specific parameter, for a specific mpg123_handle.
281 * See the mpg123_parms enumeration for a list of available parameters.
282 * \param mh handle
283 * \param type parameter choice
284 * \param value integer value return address
285 * \param fvalue floating point value return address
286 * \return MPG123_OK on success
287 *)
288 function mpg123_getparam(mh: pmpg123_handle; _type: mpg123_parms; val: pclong; fval: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
290 (** Feature set available for query with mpg123_feature. *)
291 type
292 mpg123_feature_set = clong;
293 const
294 MPG123_FEATURE_ABI_UTF8OPEN = 0; (**< mpg123 expects path names to be given in UTF-8 encoding instead of plain native. *)
295 MPG123_FEATURE_OUTPUT_8BIT = 1; (**< 8bit output *)
296 MPG123_FEATURE_OUTPUT_16BIT = 2; (**< 16bit output *)
297 MPG123_FEATURE_OUTPUT_32BIT = 3; (**< 32bit output *)
298 MPG123_FEATURE_INDEX = 4; (**< support for building a frame index for accurate seeking *)
299 MPG123_FEATURE_PARSE_ID3V2 = 5; (**< id3v2 parsing *)
300 MPG123_FEATURE_DECODE_LAYER1 = 6; (**< mpeg layer-1 decoder enabled *)
301 MPG123_FEATURE_DECODE_LAYER2 = 7; (**< mpeg layer-2 decoder enabled *)
302 MPG123_FEATURE_DECODE_LAYER3 = 8; (**< mpeg layer-3 decoder enabled *)
303 MPG123_FEATURE_DECODE_ACCURATE = 9; (**< accurate decoder rounding *)
304 MPG123_FEATURE_DECODE_DOWNSAMPLE = 10; (**< downsample (sample omit) *)
305 MPG123_FEATURE_DECODE_NTOM = 11; (**< flexible rate decoding *)
306 MPG123_FEATURE_PARSE_ICY = 12; (**< ICY support *)
307 MPG123_FEATURE_TIMEOUT_READ = 13; (**< Reader with timeout (network). *)
308 MPG123_FEATURE_EQUALIZER = 14; (**< tunable equalizer *)
310 (** Query libmpg123 features.
311 * \param key feature selection
312 * \return 1 for success, 0 for unimplemented functions
313 *)
314 function mpg123_feature(const key: mpg123_feature_set): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
316 (* @} *)
318 (** \defgroup mpg123_error mpg123 error handling
320 * Functions to get text version of the error numbers and an enumeration
321 * of the error codes returned by libmpg123.
323 * Most functions operating on a mpg123_handle simply return MPG123_OK (0)
324 * on success and MPG123_ERR (-1) on failure, setting the internal error
325 * variable of the handle to the specific error code. If there was not a valid
326 * (non-NULL) handle provided to a function operating on one, MPG123_BAD_HANDLE
327 * may be returned if this can not be confused with a valid positive return
328 * value.
329 * Meaning: A function expected to return positive integers on success will
330 * always indicate error or a special condition by returning a negative one.
332 * Decoding/seek functions may also return message codes MPG123_DONE,
333 * MPG123_NEW_FORMAT and MPG123_NEED_MORE (all negative, see below on how to
334 * react). Note that calls to those can be nested, so generally watch out
335 * for these codes after initial handle setup.
336 * Especially any function that needs information about the current stream
337 * to work will try to at least parse the beginning if that did not happen
338 * yet.
340 * On a function that is supposed to return MPG123_OK on success and
341 * MPG123_ERR on failure, make sure you check for != MPG123_OK, not
342 * == MPG123_ERR, as the error code could get more specific in future,
343 * or there is just a special message from a decoding routine as indicated
344 * above.
346 * @{
347 *)
349 (** Enumeration of the message and error codes and returned by libmpg123 functions. *)
350 type
351 mpg123_errors = clong;
352 const
353 MPG123_DONE = -12; (**< Message: Track ended. Stop decoding. *)
354 MPG123_NEW_FORMAT = -11; (**< Message: Output format will be different on next call. Note that some libmpg123 versions between 1.4.3 and 1.8.0 insist on you calling mpg123_getformat() after getting this message code. Newer verisons behave like advertised: You have the chance to call mpg123_getformat(), but you can also just continue decoding and get your data. *)
355 MPG123_NEED_MORE = -10; (**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). *)
356 MPG123_ERR = -1; (**< Generic Error *)
357 MPG123_OK = 0; (**< Success *)
358 MPG123_BAD_OUTFORMAT = 1; (**< Unable to set up output format! *)
359 MPG123_BAD_CHANNEL = 2; (**< Invalid channel number specified. *)
360 MPG123_BAD_RATE = 3; (**< Invalid sample rate specified. *)
361 MPG123_ERR_16TO8TABLE = 4; (**< Unable to allocate memory for 16 to 8 converter table! *)
362 MPG123_BAD_PARAM = 5; (**< Bad parameter id! *)
363 MPG123_BAD_BUFFER = 6; (**< Bad buffer given -- invalid pointer or too small size. *)
364 MPG123_OUT_OF_MEM = 7; (**< Out of memory -- some malloc() failed. *)
365 MPG123_NOT_INITIALIZED = 8; (**< You didn't initialize the library! *)
366 MPG123_BAD_DECODER = 9; (**< Invalid decoder choice. *)
367 MPG123_BAD_HANDLE = 10; (**< Invalid mpg123 handle. *)
368 MPG123_NO_BUFFERS = 11; (**< Unable to initialize frame buffers (out of memory?). *)
369 MPG123_BAD_RVA = 12; (**< Invalid RVA mode. *)
370 MPG123_NO_GAPLESS = 13; (**< This build doesn't support gapless decoding. *)
371 MPG123_NO_SPACE = 14; (**< Not enough buffer space. *)
372 MPG123_BAD_TYPES = 15; (**< Incompatible numeric data types. *)
373 MPG123_BAD_BAND = 16; (**< Bad equalizer band. *)
374 MPG123_ERR_NULL = 17; (**< Null pointer given where valid storage address needed. *)
375 MPG123_ERR_READER = 18; (**< Error reading the stream. *)
376 MPG123_NO_SEEK_FROM_END = 19; (**< Cannot seek from end (end is not known). *)
377 MPG123_BAD_WHENCE = 20; (**< Invalid 'whence' for seek function.*)
378 MPG123_NO_TIMEOUT = 21; (**< Build does not support stream timeouts. *)
379 MPG123_BAD_FILE = 22; (**< File access error. *)
380 MPG123_NO_SEEK = 23; (**< Seek not supported by stream. *)
381 MPG123_NO_READER = 24; (**< No stream opened. *)
382 MPG123_BAD_PARS = 25; (**< Bad parameter handle. *)
383 MPG123_BAD_INDEX_PAR = 26; (**< Bad parameters to mpg123_index() and mpg123_set_index() *)
384 MPG123_OUT_OF_SYNC = 27; (**< Lost track in bytestream and did not try to resync. *)
385 MPG123_RESYNC_FAIL = 28; (**< Resync failed to find valid MPEG data. *)
386 MPG123_NO_8BIT = 29; (**< No 8bit encoding possible. *)
387 MPG123_BAD_ALIGN = 30; (**< Stack aligmnent error *)
388 MPG123_NULL_BUFFER = 31; (**< NULL input buffer with non-zero size... *)
389 MPG123_NO_RELSEEK = 32; (**< Relative seek not possible (screwed up file offset) *)
390 MPG123_NULL_POINTER = 33; (**< You gave a null pointer somewhere where you shouldn't have. *)
391 MPG123_BAD_KEY = 34; (**< Bad key value given. *)
392 MPG123_NO_INDEX = 35; (**< No frame index in this build. *)
393 MPG123_INDEX_FAIL = 36; (**< Something with frame index went wrong. *)
394 MPG123_BAD_DECODER_SETUP = 37; (**< Something prevents a proper decoder setup *)
395 MPG123_MISSING_FEATURE = 38; (**< This feature has not been built into libmpg123. *)
396 MPG123_BAD_VALUE = 39; (**< A bad value has been given, somewhere. *)
397 MPG123_LSEEK_FAILED = 40; (**< Low-level seek failed. *)
398 MPG123_BAD_CUSTOM_IO = 41; (**< Custom I/O not prepared. *)
399 MPG123_LFS_OVERFLOW = 42; (**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. *)
400 MPG123_INT_OVERFLOW = 43; (**< Some integer overflow. *)
402 (** An enum over all sample types possibly known to mpg123.
403 * The values are designed as bit flags to allow bitmasking for encoding families.
405 * Note that (your build of) libmpg123 does not necessarily support all these.
406 * Usually, you can expect the 8bit encodings and signed 16 bit.
407 * Also 32bit float will be usual beginning with mpg123-1.7.0 .
408 * What you should bear in mind is that (SSE, etc) optimized routines may be absent
409 * for some formats. We do have SSE for 16, 32 bit and float, though.
410 * 24 bit integer is done via postprocessing of 32 bit output -- just cutting
411 * the last byte, no rounding, even. If you want better, do it yourself.
413 * All formats are in native byte order. If you need different endinaness, you
414 * can simply postprocess the output buffers (libmpg123 wouldn't do anything else).
415 * mpg123_encsize() can be helpful there.
416 *)
418 type
419 mpg123_enc_enum = clong;
420 const
421 MPG123_ENC_8 = $00f; (* 0000 0000 1111 Some 8 bit integer encoding. *)
422 MPG123_ENC_16 = $040; (* 0000 0100 0000 Some 16 bit integer encoding. *)
423 MPG123_ENC_24 = $4000; (* 0100 0000 0000 0000 Some 24 bit integer encoding. *)
424 MPG123_ENC_32 = $100; (* 0001 0000 0000 Some 32 bit integer encoding. *)
425 MPG123_ENC_SIGNED = $080; (* 0000 1000 0000 Some signed integer encoding. *)
426 MPG123_ENC_FLOAT = $e00; (* 1110 0000 0000 Some float encoding. *)
427 MPG123_ENC_SIGNED_16 = (MPG123_ENC_16 or MPG123_ENC_SIGNED or $10); (* 1101 0000 signed 16 bit *)
428 MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16 or $20); (* 0110 0000 unsigned 16 bit *)
429 MPG123_ENC_UNSIGNED_8 = $01; (* 0000 0001 unsigned 8 bit *)
430 MPG123_ENC_SIGNED_8 = (MPG123_ENC_SIGNED or $02); (* 1000 0010 signed 8 bit *)
431 MPG123_ENC_ULAW_8 = $04; (* 0000 0100 ulaw 8 bit *)
432 MPG123_ENC_ALAW_8 = $08; (* 0000 1000 alaw 8 bit *)
433 MPG123_ENC_SIGNED_32 = MPG123_ENC_32 or MPG123_ENC_SIGNED or $1000; (* 0001 0001 1000 0000 signed 32 bit *)
434 MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32 or $2000; (* 0010 0001 0000 0000 unsigned 32 bit *)
435 MPG123_ENC_SIGNED_24 = MPG123_ENC_24 or MPG123_ENC_SIGNED or $1000; (* 0101 0000 1000 0000 signed 24 bit *)
436 MPG123_ENC_UNSIGNED_24 = MPG123_ENC_24 or $2000; (* 0110 0000 0000 0000 unsigned 24 bit *)
437 MPG123_ENC_FLOAT_32 = $200; (* 0010 0000 0000 32bit float *)
438 MPG123_ENC_FLOAT_64 = $400; (* 0100 0000 0000 64bit float *)
439 MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16 or MPG123_ENC_UNSIGNED_16 or MPG123_ENC_UNSIGNED_8
440 or MPG123_ENC_SIGNED_8 or MPG123_ENC_ULAW_8 or MPG123_ENC_ALAW_8
441 or MPG123_ENC_SIGNED_32 or MPG123_ENC_UNSIGNED_32
442 or MPG123_ENC_SIGNED_24 or MPG123_ENC_UNSIGNED_24
443 or MPG123_ENC_FLOAT_32 or MPG123_ENC_FLOAT_64 ); (* Any encoding on the list. *)
445 (** Look up error strings given integer code.
446 * \param errcode integer error code
447 * \return string describing what that error error code means
448 *)
449 function mpg123_plain_strerror(errcode: cint): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
451 (** Give string describing what error has occured in the context of handle mh.
452 * When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via
453 * char *errmsg = mpg123_strerror(mh)
454 * This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE.
455 * \param mh handle
456 * \return error message
457 *)
458 function mpg123_strerror(mh: pmpg123_handle): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
460 (** Return the plain errcode intead of a string.
461 * \param mh handle
462 * \return error code recorded in handle or MPG123_BAD_HANDLE
463 *)
464 function mpg123_errcode(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
466 (*@}*)
468 (** \defgroup mpg123_decoder mpg123 decoder selection
470 * Functions to list and select the available decoders.
471 * Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).
473 * @{
474 *)
476 (** Get available decoder list.
477 * \return NULL-terminated array of generally available decoder names (plain 8bit ASCII)
478 *)
479 function mpg123_decoders(): ppchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
481 (** Get supported decoder list.
482 * \return NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII)
483 *)
484 function mpg123_supported_decoders(): ppchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
486 (** Set the active decoder.
487 * \param mh handle
488 * \param decoder_name name of decoder
489 * \return MPG123_OK on success
490 *)
491 function mpg123_decoder(mh: pmpg123_handle; const decoder_name: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
493 (** Get the currently active decoder name.
494 * The active decoder engine can vary depening on output constraints,
495 * mostly non-resampling, integer output is accelerated via 3DNow & Co. but for
496 * other modes a fallback engine kicks in.
497 * Note that this can return a decoder that is ony active in the hidden and not
498 * available as decoder choice from the outside.
499 * \param mh handle
500 * \return The decoder name or NULL on error.
501 *)
502 function mpg123_current_decoder(mh: pmpg123_handle): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
504 (*@}*)
506 (** \defgroup mpg123_output mpg123 output audio format
508 * Functions to get and select the format of the decoded audio.
510 * Before you dive in, please be warned that you might get confused by this. This seems to happen a lot, therefore I am trying to explain in advance.
512 * The mpg123 library decides what output format to use when encountering the first frame in a stream, or actually any frame that is still valid but differs from the frames before in the prompted output format. At such a deciding point, an internal table of allowed encodings, sampling rates and channel setups is consulted. According to this table, an output format is chosen and the decoding engine set up accordingly (including optimized routines for different output formats). This might seem unusual but it just follows from the non-existence of "MPEG audio files" with defined overall properties. There are streams, streams are concatenations of (semi) independent frames. We store streams on disk and call them "MPEG audio files", but that does not change their nature as the decoder is concerned (the LAME/Xing header for gapless decoding makes things interesting again).
514 * To get to the point: What you do with mpg123_format() and friends is to fill the internal table of allowed formats before it is used. That includes removing support for some formats or adding your forced sample rate (see MPG123_FORCE_RATE) that will be used with the crude internal resampler. Also keep in mind that the sample encoding is just a question of choice -- the MPEG frames do only indicate their native sampling rate and channel count. If you want to decode to integer or float samples, 8 or 16 bit ... that is your decision. In a "clean" world, libmpg123 would always decode to 32 bit float and let you handle any sample conversion. But there are optimized routines that work faster by directly decoding to the desired encoding / accuracy. We prefer efficiency over conceptual tidyness.
516 * People often start out thinking that mpg123_format() should change the actual decoding format on the fly. That is wrong. It only has effect on the next natural change of output format, when libmpg123 will consult its format table again. To make life easier, you might want to call mpg123_format_none() before any thing else and then just allow one desired encoding and a limited set of sample rates / channel choices that you actually intend to deal with. You can force libmpg123 to decode everything to 44100 KHz, stereo, 16 bit integer ... it will duplicate mono channels and even do resampling if needed (unless that feature is disabled in the build, same with some encodings). But I have to stress that the resampling of libmpg123 is very crude and doesn't even contain any kind of "proper" interpolation.
518 * In any case, watch out for MPG123_NEW_FORMAT as return message from decoding routines and call mpg123_getformat() to get the currently active output format.
520 * @{
521 *)
523 (** They can be combined into one number (3) to indicate mono and stereo... *)
524 type
525 mpg123_channelcount = clong;
526 const
527 MPG123_MONO = 1; (**< mono *)
528 MPG123_STEREO = 2; (**< stereo *)
530 (** An array of supported standard sample rates
531 * These are possible native sample rates of MPEG audio files.
532 * You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings.
533 * \param list Store a pointer to the sample rates array there.
534 * \param number Store the number of sample rates there. *)
535 procedure mpg123_rates(const list: ppclong; number: pcsize_t); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
537 (** An array of supported audio encodings.
538 * An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).
539 * \param list Store a pointer to the encodings array there.
540 * \param number Store the number of encodings there. *)
541 procedure mpg123_encodings(const list: ppcint; number: pcsize_t); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
543 (** Return the size (in bytes) of one mono sample of the named encoding.
544 * \param encoding The encoding value to analyze.
545 * \return positive size of encoding in bytes, 0 on invalid encoding. *)
546 function mpg123_encsize(encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
548 (** Configure a mpg123 handle to accept no output format at all,
549 * use before specifying supported formats with mpg123_format
550 * \param mh handle
551 * \return MPG123_OK on success
552 *)
553 function mpg123_format_none(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
555 (** Configure mpg123 handle to accept all formats
556 * (also any custom rate you may set) -- this is default.
557 * \param mh handle
558 * \return MPG123_OK on success
559 *)
560 function mpg123_format_all(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
562 (** Set the audio format support of a mpg123_handle in detail:
563 * \param mh handle
564 * \param rate The sample rate value (in Hertz).
565 * \param channels A combination of MPG123_STEREO and MPG123_MONO.
566 * \param encodings A combination of accepted encodings for rate and channels, p.ex MPG123_ENC_SIGNED16 | MPG123_ENC_ULAW_8 (or 0 for no support). Please note that some encodings may not be supported in the library build and thus will be ignored here.
567 * \return MPG123_OK on success, MPG123_ERR if there was an error. *)
568 function mpg123_format(mh: pmpg123_handle; rate: clong; channels: cint; encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
570 (** Check to see if a specific format at a specific rate is supported
571 * by mpg123_handle.
572 * \param mh handle
573 * \param rate sampling rate
574 * \param encoding encoding
575 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
576 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. *)
577 function mpg123_format_support(mh: pmpg123_handle; rate: clong; encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
579 (** Get the current output format written to the addresses given.
580 * If the stream is freshly loaded, this will try to parse enough
581 * of it to give you the format to come. This clears the flag that
582 * would otherwise make the first decoding call return
583 * MPG123_NEW_FORMAT.
584 * \param mh handle
585 * \param rate sampling rate return address
586 * \param channels channel count return address
587 * \param encoding encoding return address
588 * \return MPG123_OK on success
589 *)
590 function mpg123_getformat(mh: pmpg123_handle; rate: pclong; channels: pcint; encoding: pcint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
592 (** Get the current output format written to the addresses given.
593 * This differs from plain mpg123_getformat() in that you can choose
594 * _not_ to clear the flag that would trigger the next decoding call
595 * to return MPG123_NEW_FORMAT in case of a new format arriving.
596 * \param mh handle
597 * \param rate sampling rate return address
598 * \param channels channel count return address
599 * \param encoding encoding return address
600 * \param clear_flag if true, clear internal format flag
601 * \return MPG123_OK on success
602 *)
603 function mpg123_getformat2(mh: pmpg123_handle; rate: pclong; channels: pcint; encoding: pcint; clear_flag: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
605 (*@}*)
607 (** \defgroup mpg123_input mpg123 file input and decoding
609 * Functions for input bitstream and decoding operations.
610 * Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!).
611 * @{
612 *)
614 (* reading samples / triggering decoding, possible return values: *)
615 (** Enumeration of the error codes returned by libmpg123 functions. *)
617 (** Open and prepare to decode the specified file by filesystem path.
618 * This does not open HTTP urls; libmpg123 contains no networking code.
619 * If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().
620 * \param mh handle
621 * \param path filesystem path
622 * \return MPG123_OK on success
623 *)
624 function mpg123_open(mh: pmpg123_handle; const path: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
626 (** Use an already opened file descriptor as the bitstream input
627 * mpg123_close() will _not_ close the file descriptor.
628 * \param mh handle
629 * \param fd file descriptor
630 * \return MPG123_OK on success
631 *)
632 function mpg123_open_fd(mh: pmpg123_handle; fd: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
634 (** Use an opaque handle as bitstream input. This works only with the
635 * replaced I/O from mpg123_replace_reader_handle()!
636 * mpg123_close() will call the cleanup callback for your handle (if you gave one).
637 * \param mh handle
638 * \param iohandle your handle
639 * \return MPG123_OK on success
640 *)
641 function mpg123_open_handle(mh: pmpg123_handle; iohandle: pointer): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
643 (** Open a new bitstream and prepare for direct feeding
644 * This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.
645 * \param mh handle
646 * \return MPG123_OK on success
647 *)
648 function mpg123_open_feed(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
650 (** Closes the source, if libmpg123 opened it.
651 * \param mh handle
652 * \return MPG123_OK on success
653 *)
654 function mpg123_close(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
656 (** Read from stream and decode up to outmemsize bytes.
657 * \param mh handle
658 * \param outmemory address of output buffer to write to
659 * \param outmemsize maximum number of bytes to write
660 * \param done address to store the number of actually decoded bytes to
661 * \return MPG123_OK or error/message code
662 *)
663 function mpg123_read(mh: pmpg123_handle; outmemory: pcuchar; outmemsize: csize_t; done: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
665 (** Feed data for a stream that has been opened with mpg123_open_feed().
666 * It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.
667 * \param mh handle
668 * \param in input buffer
669 * \param size number of input bytes
670 * \return MPG123_OK or error/message code.
671 *)
672 function mpg123_feed(mh: pmpg123_handle; const _in: pcuchar; size: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
674 (** Decode MPEG Audio from inmemory to outmemory.
675 * This is very close to a drop-in replacement for old mpglib.
676 * When you give zero-sized output buffer the input will be parsed until
677 * decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)
678 * without taking decoded data.
679 * Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).
680 * You can actually always decide if you want those specialized functions in separate steps or one call this one here.
681 * \param mh handle
682 * \param inmemory input buffer
683 * \param inmemsize number of input bytes
684 * \param outmemory output buffer
685 * \param outmemsize maximum number of output bytes
686 * \param done address to store the number of actually decoded bytes to
687 * \return error/message code (watch out especially for MPG123_NEED_MORE)
688 *)
689 function mpg123_decode(mh: pmpg123_handle; const inmemory: pcuchar ; inmemsize: csize_t; outmemory: pcuchar; outmemsize: csize_t; done: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
691 (** Decode next MPEG frame to internal buffer
692 * or read a frame and return after setting a new format.
693 * \param mh handle
694 * \param num current frame offset gets stored there
695 * \param audio This pointer is set to the internal buffer to read the decoded audio from.
696 * \param bytes number of output bytes ready in the buffer
697 * \return MPG123_OK or error/message code
698 *)
699 function mpg123_decode_frame(mh: pmpg123_handle; num: poff_t; audio: ppcuchar; bytes: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
701 (** Decode current MPEG frame to internal buffer.
702 * Warning: This is experimental API that might change in future releases!
703 * Please watch mpg123 development closely when using it.
704 * \param mh handle
705 * \param num last frame offset gets stored there
706 * \param audio this pointer is set to the internal buffer to read the decoded audio from.
707 * \param bytes number of output bytes ready in the buffer
708 * \return MPG123_OK or error/message code
709 *)
710 function mpg123_framebyframe_decode(mh: pmpg123_handle; num: poff_t; audio: ppcuchar; bytes: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
712 (** Find, read and parse the next mp3 frame
713 * Warning: This is experimental API that might change in future releases!
714 * Please watch mpg123 development closely when using it.
715 * \param mh handle
716 * \return MPG123_OK or error/message code
717 *)
718 function mpg123_framebyframe_next(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
720 (** Get access to the raw input data for the last parsed frame.
721 * This gives you a direct look (and write access) to the frame body data.
722 * Together with the raw header, you can reconstruct the whole raw MPEG stream without junk and meta data, or play games by actually modifying the frame body data before decoding this frame (mpg123_framebyframe_decode()).
723 * A more sane use would be to use this for CRC checking (see mpg123_info() and MPG123_CRC), the first two bytes of the body make up the CRC16 checksum, if present.
724 * You can provide NULL for a parameter pointer when you are not interested in the value.
726 * \param mh handle
727 * \param header the 4-byte MPEG header
728 * \param bodydata pointer to the frame body stored in the handle (without the header)
729 * \param bodybytes size of frame body in bytes (without the header)
730 * \return MPG123_OK if there was a yet un-decoded frame to get the
731 * data from, MPG123_BAD_HANDLE or MPG123_ERR otherwise (without further
732 * explanation, the error state of the mpg123_handle is not modified by
733 * this function).
734 *)
735 function mpg123_framedata(mh: pmpg123_handle; header: pculong; bodydata: ppcuchar; bodybytes: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
737 (** Get the input position (byte offset in stream) of the last parsed frame.
738 * This can be used for external seek index building, for example.
739 * It just returns the internally stored offset, regardless of validity -- you ensure that a valid frame has been parsed before! *)
740 function mpg123_framepos(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
742 (*@}*)
744 (** \defgroup mpg123_seek mpg123 position and seeking
746 * Functions querying and manipulating position in the decoded audio bitstream.
747 * The position is measured in decoded audio samples, or MPEG frame offset for the specific functions.
748 * If gapless code is in effect, the positions are adjusted to compensate the skipped padding/delay - meaning, you should not care about that at all and just use the position defined for the samples you get out of the decoder;-)
749 * The general usage is modelled after stdlib's ftell() and fseek().
750 * Especially, the whence parameter for the seek functions has the same meaning as the one for fseek() and needs the same constants from stdlib.h:
751 * - SEEK_SET: set position to (or near to) specified offset
752 * - SEEK_CUR: change position by offset from now
753 * - SEEK_END: set position to offset from end
755 * Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise.
756 * Also, really sample-accurate seeking (meaning that you get the identical sample value after seeking compared to plain decoding up to the position) is only guaranteed when you do not mess with the position code by using MPG123_UPSPEED, MPG123_DOWNSPEED or MPG123_START_FRAME. The first two mainly should cause trouble with NtoM resampling, but in any case with these options in effect, you have to keep in mind that the sample offset is not the same as counting the samples you get from decoding since mpg123 counts the skipped samples, too (or the samples played twice only once)!
757 * Short: When you care about the sample position, don't mess with those parameters;-)
758 * Also, seeking is not guaranteed to work for all streams (underlying stream may not support it).
759 * And yet another caveat: If the stream is concatenated out of differing pieces (Frankenstein stream), seeking may suffer, too.
761 * @{
762 *)
764 (** Returns the current position in samples.
765 * On the next successful read, you'd get that sample.
766 * \param mh handle
767 * \return sample offset or MPG123_ERR (null handle)
768 *)
769 function mpg123_tell(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
771 (** Returns the frame number that the next read will give you data from.
772 * \param mh handle
773 * \return frame offset or MPG123_ERR (null handle)
774 *)
775 function mpg123_tellframe(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
777 (** Returns the current byte offset in the input stream.
778 * \param mh handle
779 * \return byte offset or MPG123_ERR (null handle)
780 *)
781 function mpg123_tell_stream(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
783 (** Seek to a desired sample offset.
784 * Usage is modelled afer the standard lseek().
785 * \param mh handle
786 * \param sampleoff offset in PCM samples
787 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
788 * \return The resulting offset >= 0 or error/message code
789 *)
790 function mpg123_seek(mh: pmpg123_handle; sampleoff: off_t; whence: cint): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
792 (** Seek to a desired sample offset in data feeding mode.
793 * This just prepares things to be right only if you ensure that the next chunk of input data will be from input_offset byte position.
794 * \param mh handle
795 * \param sampleoff offset in PCM samples
796 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
797 * \param input_offset The position it expects to be at the
798 * next time data is fed to mpg123_decode().
799 * \return The resulting offset >= 0 or error/message code *)
800 function mpg123_feedseek(mh: pmpg123_handle; sampleoff: off_t; whence: cint; input_offset: poff_t): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
802 (** Seek to a desired MPEG frame offset.
803 * Usage is modelled afer the standard lseek().
804 * \param mh handle
805 * \param frameoff offset in MPEG frames
806 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
807 * \return The resulting offset >= 0 or error/message code *)
808 function mpg123_seek_frame(mh: pmpg123_handle; frameoff: off_t; whence: cint): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
810 (** Return a MPEG frame offset corresponding to an offset in seconds.
811 * This assumes that the samples per frame do not change in the file/stream, which is a good assumption for any sane file/stream only.
812 * \return frame offset >= 0 or error/message code *)
813 function mpg123_timeframe(mh: pmpg123_handle; sec: cdouble): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
815 (** Give access to the frame index table that is managed for seeking.
816 * You are asked not to modify the values... Use mpg123_set_index to set the
817 * seek index
818 * \param mh handle
819 * \param offsets pointer to the index array
820 * \param step one index byte offset advances this many MPEG frames
821 * \param fill number of recorded index offsets; size of the array
822 * \return MPG123_OK on success
823 *)
824 function mpg123_index(mh: pmpg123_handle; offsets: ppoff_t; step: poff_t; fill: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
826 (** Set the frame index table
827 * Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets
828 * to NULL and fill to 0 will clear the index and free the allocated memory used by the index.
829 * \param mh handle
830 * \param offsets pointer to the index array
831 * \param step one index byte offset advances this many MPEG frames
832 * \param fill number of recorded index offsets; size of the array
833 * \return MPG123_OK on success
834 *)
835 function mpg123_set_index(mh: pmpg123_handle; offsets: poff_t; step: off_t; fill: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
837 (** An old crutch to keep old mpg123 binaries happy.
838 * WARNING: This function is there only to avoid runtime linking errors with
839 * standalone mpg123 before version 1.23.0 (if you strangely update the
840 * library but not the end-user program) and actually is broken
841 * for various cases (p.ex. 24 bit output). Do never use. It might eventually
842 * be purged from the library.
843 *)
844 function mpg123_position( mh: pmpg123_handle; frame_offset: off_t; buffered_bytes: off_t; current_frame: poff_t; frames_left: poff_t; current_seconds: pcdouble; seconds_left: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
846 (*@}*)
848 (** \defgroup mpg123_voleq mpg123 volume and equalizer
850 * @{
851 *)
853 (** another channel enumeration, for left/right choice *)
854 type
855 mpg123_channels = clong;
856 const
857 MPG123_LEFT = $1; (**< The Left Channel. *)
858 MPG123_RIGHT = $2; (**< The Right Channel. *)
859 MPG123_LR = $3; (**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT *)
861 (** Set the 32 Band Audio Equalizer settings.
862 * \param mh handle
863 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both.
864 * \param band The equaliser band to change (from 0 to 31)
865 * \param val The (linear) adjustment factor.
866 * \return MPG123_OK on success
867 *)
868 function mpg123_eq(mh: pmpg123_handle; channel: mpg123_channels; band: cint; val: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
870 (** Get the 32 Band Audio Equalizer settings.
871 * \param mh handle
872 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
873 * \param band The equaliser band to change (from 0 to 31)
874 * \return The (linear) adjustment factor (zero for pad parameters) *)
875 function mpg123_geteq(mh: pmpg123_handle; channel: mpg123_channels; band: cint): cdouble; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
877 (** Reset the 32 Band Audio Equalizer settings to flat
878 * \param mh handle
879 * \return MPG123_OK on success
880 *)
881 function mpg123_reset_eq(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
883 (** Set the absolute output volume including the RVA setting,
884 * vol<0 just applies (a possibly changed) RVA setting.
885 * \param mh handle
886 * \param vol volume value (linear factor)
887 * \return MPG123_OK on success
888 *)
889 function mpg123_volume(mh: pmpg123_handle; vol: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
891 (** Adjust output volume including the RVA setting by chosen amount
892 * \param mh handle
893 * \param change volume value (linear factor increment)
894 * \return MPG123_OK on success
895 *)
896 function mpg123_volume_change(mh: pmpg123_handle; change: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
898 (** Return current volume setting, the actual value due to RVA, and the RVA
899 * adjustment itself. It's all as double float value to abstract the sample
900 * format. The volume values are linear factors / amplitudes (not percent)
901 * and the RVA value is in decibels.
902 * \param mh handle
903 * \param base return address for base volume (linear factor)
904 * \param really return address for actual volume (linear factor)
905 * \param rva_db return address for RVA value (decibels)
906 * \return MPG123_OK on success
907 *)
908 function mpg123_getvolume(mh: pmpg123_handle; base: pcdouble; really: pcdouble; rva_db: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
910 (* TODO: Set some preamp in addition / to replace internal RVA handling? *)
912 (*@}*)
914 (** \defgroup mpg123_status mpg123 status and information
916 * @{
917 *)
919 (** Enumeration of the mode types of Variable Bitrate *)
920 type
921 mpg123_vbr_type = clong;
922 const
923 MPG123_CBR = 0; (**< Constant Bitrate Mode (default) *)
924 MPG123_VBR = 1; (**< Variable Bitrate Mode *)
925 MPG123_ABR = 2; (**< Average Bitrate Mode *)
927 (** Enumeration of the MPEG Versions *)
928 type
929 mpg123_version = clong;
930 const
931 MPG123_1_0 = 0; (**< MPEG Version 1.0 *)
932 MPG123_2_0 = 1; (**< MPEG Version 2.0 *)
933 MPG123_2_5 = 2; (**< MPEG Version 2.5 *)
936 (** Enumeration of the MPEG Audio mode.
937 * Only the mono mode has 1 channel, the others have 2 channels. *)
938 type
939 mpg123_mode = clong;
940 const
941 MPG123_M_STEREO = 0; (**< Standard Stereo. *)
942 MPG123_M_JOINT = 1; (**< Joint Stereo. *)
943 MPG123_M_DUAL = 2; (**< Dual Channel. *)
944 MPG123_M_MONO = 3; (**< Single Channel. *)
947 (** Enumeration of the MPEG Audio flag bits *)
948 type
949 mpg123_flags_type = clong;
950 const
951 MPG123_CRC = $1; (**< The bitstream is error protected using 16-bit CRC. *)
952 MPG123_COPYRIGHT = $2; (**< The bitstream is copyrighted. *)
953 MPG123_PRIVATE = $4; (**< The private bit has been set. *)
954 MPG123_ORIGINAL = $8; (**< The bitstream is an original, not a copy. *)
956 (** Data structure for storing information about a frame of MPEG Audio *)
957 type
958 pmpg123_frameinfo = ^mpg123_frameinfo;
959 mpg123_frameinfo = record
960 version: mpg123_version; (**< The MPEG version (1.0/2.0/2.5). *)
961 layer: cint; (**< The MPEG Audio Layer (MP1/MP2/MP3). *)
962 rate: clong; (**< The sampling rate in Hz. *)
963 mode: mpg123_mode; (**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). *)
964 mode_ext: cint; (**< The mode extension bit flag. *)
965 framesize: cint; (**< The size of the frame (in bytes, including header). *)
966 flags: mpg123_flags_type; (**< MPEG Audio flag bits. Just now I realize that it should be declared as int, not enum. It's a bitwise combination of the enum values. *)
967 emphasis: cint; (**< The emphasis type. *)
968 bitrate: cint; (**< Bitrate of the frame (kbps). *)
969 abr_rate: cint; (**< The target average bitrate. *)
970 vbr: mpg123_vbr_type; (**< The VBR mode. *)
971 end;
973 (** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure.
974 * \param mh handle
975 * \param mi address of existing frameinfo structure to write to
976 * \return MPG123_OK on success
977 *)
978 function mpg123_info(mh: pmpg123_handle; mi: pmpg123_frameinfo): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
980 (** Get the safe output buffer size for all cases
981 * (when you want to replace the internal buffer)
982 * \return safe buffer size
983 *)
984 function mpg123_safe_buffer(): csize_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
986 (** Make a full parsing scan of each frame in the file. ID3 tags are found. An
987 * accurate length value is stored. Seek index will be filled. A seek back to
988 * current position is performed. At all, this function refuses work when
989 * stream is not seekable.
990 * \param mh handle
991 * \return MPG123_OK on success
992 *)
993 function mpg123_scan(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
995 (** Return, if possible, the full (expected) length of current track in frames.
996 * \param mh handle
997 * \return length >= 0 or MPG123_ERR if there is no length guess possible.
998 *)
999 function mpg123_framelength(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1001 (** Return, if possible, the full (expected) length of current track in samples.
1002 * \param mh handle
1003 * \return length >= 0 or MPG123_ERR if there is no length guess possible.
1004 *)
1005 function mpg123_length(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1007 (** Override the value for file size in bytes.
1008 * Useful for getting sensible track length values in feed mode or for HTTP streams.
1009 * \param mh handle
1010 * \param size file size in bytes
1011 * \return MPG123_OK on success
1012 *)
1013 function mpg123_set_filesize(mh: pmpg123_handle; size: off_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1015 (** Get MPEG frame duration in seconds.
1016 * \param mh handle
1017 * \return frame duration in seconds, <0 on error
1018 *)
1019 function mpg123_tpf(mh: pmpg123_handle): cdouble; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1021 (** Get MPEG frame duration in samples.
1022 * \param mh handle
1023 * \return samples per frame for the most recently parsed frame; <0 on errors
1024 *)
1025 function mpg123_spf(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1027 (** Get and reset the clip count.
1028 * \param mh handle
1029 * \return count of clipped samples
1030 *)
1031 function mpg123_clip(mh: pmpg123_handle): clong; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1033 (** The key values for state information from mpg123_getstate(). *)
1034 type
1035 mpg123_state = clong;
1036 const
1037 MPG123_ACCURATE = 1; (**< Query if positons are currently accurate (integer value, 0 if false, 1 if true). *)
1038 MPG123_BUFFERFILL = 2; (**< Get fill of internal (feed) input buffer as integer byte count returned as long and as double. An error is returned on integer overflow while converting to (signed) long, but the returned floating point value shold still be fine. *)
1039 MPG123_FRANKENSTEIN = 3; (**< Stream consists of carelessly stitched together files. Seeking may yield unexpected results (also with MPG123_ACCURATE, it may be confused). *)
1040 MPG123_FRESH_DECODER = 4; (**< Decoder structure has been updated, possibly indicating changed stream (integer value, 0 if false, 1 if true). Flag is cleared after retrieval. *)
1042 (** Get various current decoder/stream state information.
1043 * \param mh handle
1044 * \param key the key to identify the information to give.
1045 * \param val the address to return (long) integer values to
1046 * \param fval the address to return floating point values to
1047 * \return MPG123_OK on success
1048 *)
1049 function mpg123_getstate(mh: pmpg123_handle; key: mpg123_state; val: pclong; fval: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1051 (*@}*)
1053 (** \defgroup mpg123_metadata mpg123 metadata handling
1055 * Functions to retrieve the metadata from MPEG Audio files and streams.
1056 * Also includes string handling functions.
1058 * @{
1059 *)
1061 (** Data structure for storing strings in a safer way than a standard C-String.
1062 * Can also hold a number of null-terminated strings. *)
1063 type
1064 pmpg123_string = ^mpg123_string;
1065 mpg123_string = record
1066 p: pchar; (**< pointer to the string data *)
1067 size: csize_t; (**< raw number of bytes allocated *)
1068 fill: csize_t; (**< number of used bytes (including closing zero byte) *)
1069 end;
1071 (** Create and allocate memory for a new mpg123_string
1072 * \param sb string handle (address of existing structure on your side)
1073 *)
1074 procedure mpg123_init_string(sb: pmpg123_string); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1076 (** Free-up mempory for an existing mpg123_string
1077 * \param sb string handle
1078 *)
1079 procedure mpg123_free_string(sb: pmpg123_string); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1081 (** Change the size of a mpg123_string
1082 * \param sb string handle
1083 * \param news new size in bytes
1084 * \return 0 on error, 1 on success
1085 *)
1086 function mpg123_resize_string(sb: pmpg123_string; news: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1088 (** Increase size of a mpg123_string if necessary (it may stay larger).
1089 * Note that the functions for adding and setting in current libmpg123
1090 * use this instead of mpg123_resize_string().
1091 * That way, you can preallocate memory and safely work afterwards with
1092 * pieces.
1093 * \param sb string handle
1094 * \param news new minimum size
1095 * \return 0 on error, 1 on success
1096 *)
1097 function mpg123_grow_string(sb: pmpg123_string; news: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1099 (** Copy the contents of one mpg123_string string to another.
1100 * Yes the order of arguments is reversed compated to memcpy().
1101 * \param from string handle
1102 * \param to string handle
1103 * \return 0 on error, 1 on success
1104 *)
1105 function mpg123_copy_string(from: pmpg123_string; _to: pmpg123_string ): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1107 (** Append a C-String to an mpg123_string
1108 * \param sb string handle
1109 * \param stuff to append
1110 * \return 0 on error, 1 on success
1111 *)
1112 function mpg123_add_string(sb: pmpg123_string; const stuff: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1114 (** Append a C-substring to an mpg123 string
1115 * \param sb string handle
1116 * \param stuff content to copy
1117 * \param from offset to copy from
1118 * \param count number of characters to copy (a null-byte is always appended)
1119 * \return 0 on error, 1 on success
1120 *)
1121 function mpg123_add_substring(sb: pmpg123_string; const stuff: pchar; from: csize_t; count: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1123 (** Set the content of a mpg123_string to a C-string
1124 * \param sb string handle
1125 * \param stuff content to copy
1126 * \return 0 on error, 1 on success
1127 *)
1128 function mpg123_set_string(sb: pmpg123_string; const stuff: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1130 (** Set the content of a mpg123_string to a C-substring
1131 * \param sb string handle
1132 * \param stuff the future content
1133 * \param from offset to copy from
1134 * \param count number of characters to copy (a null-byte is always appended)
1135 * \return 0 on error, 1 on success
1136 *)
1137 function mpg123_set_substring(sb: pmpg123_string; const stuff: pchar; from: csize_t; count: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1139 (** Count characters in a mpg123 string (non-null bytes or UTF-8 characters).
1140 * Even with the fill property, the character count is not obvious as there could be multiple trailing null bytes.
1141 * \param sb string handle
1142 * \param utf8 a flag to tell if the string is in utf8 encoding
1143 * \return character count
1144 *)
1145 function mpg123_strlen(sb: pmpg123_string; utf8: cint): csize_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1147 (** Remove trailing \\r and \\n, if present.
1148 * \param sb string handle
1149 * \return 0 on error, 1 on success
1150 *)
1151 function mpg123_chomp_string(sb: pmpg123_string): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1153 (** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. *)
1154 type
1155 mpg123_text_encoding = clong;
1156 const
1157 mpg123_text_unknown = 0; (**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. *)
1158 mpg123_text_utf8 = 1; (**< UTF-8 *)
1159 mpg123_text_latin1 = 2; (**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. *)
1160 mpg123_text_icy = 3; (**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. *)
1161 mpg123_text_cp1252 = 4; (**< Really CP-1252 without any guessing. *)
1162 mpg123_text_utf16 = 5; (**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
1163 * When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
1164 * you don't mess with the reserved code points. If you want to decode little endian data
1165 * without BOM you need to prepend 0xff 0xfe yourself. *)
1166 mpg123_text_utf16bom = 6; (**< Just an alias for UTF-16, ID3v2 has this as distinct code. *)
1167 mpg123_text_utf16be = 7; (**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
1168 * BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
1169 * One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
1170 * types (we expect a BOM before real data there), not so for utf16be!*)
1171 mpg123_text_max = 7; (**< Placeholder for the maximum encoding value. *)
1173 (** The encoding byte values from ID3v2. *)
1174 type
1175 mpg123_id3_enc = clong;
1176 const
1177 mpg123_id3_latin1 = 0; (**< Note: This sometimes can mean anything in practice... *)
1178 mpg123_id3_utf16bom = 1; (**< UTF16, UCS-2 ... it's all the same for practical purposes. *)
1179 mpg123_id3_utf16be = 2; (**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. *)
1180 mpg123_id3_utf8 = 3; (**< Our lovely overly ASCII-compatible 8 byte encoding for the world. *)
1181 mpg123_id3_enc_max = 3; (**< Placeholder to check valid range of encoding byte. *)
1183 (** Convert ID3 encoding byte to mpg123 encoding index.
1184 * \param id3_enc_byte the ID3 encoding code
1185 * \return the mpg123 encoding index
1186 *)
1187 function mpg123_enc_from_id3(id3_enc_byte: cuchar): mpg123_text_encoding; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1189 (** Store text data in string, after converting to UTF-8 from indicated encoding
1190 * A prominent error can be that you provided an unknown encoding value, or this build of libmpg123 lacks support for certain encodings (ID3 or ICY stuff missing).
1191 * Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
1192 * \param sb target string
1193 * \param enc mpg123 text encoding value
1194 * \param source source buffer with plain unsigned bytes (you might need to cast from signed char)
1195 * \param source_size number of bytes in the source buffer
1196 * \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
1197 *)
1198 function mpg123_store_utf8(sb: pmpg123_string; enc: mpg123_text_encoding; const source: pcuchar; source_size: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1200 (** Sub data structure for ID3v2, for storing various text fields (including comments).
1201 * This is for ID3v2 COMM, TXXX and all the other text fields.
1202 * Only COMM and TXXX have a description, only COMM and USLT have a language.
1203 * You should consult the ID3v2 specification for the use of the various text fields ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). *)
1204 type
1205 pmpg123_text = ^mpg123_text;
1206 mpg123_text = record
1207 lang: array[0..2] of char; (**< Three-letter language code (not terminated). *)
1208 id: array[0..3] of char; (**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). *)
1209 description: mpg123_string; (**< Empty for the generic comment... *)
1210 text: mpg123_string; (**< ... *)
1211 end;
1213 (** The picture type values from ID3v2. *)
1214 type
1215 mpg123_id3_pic_type = char;
1216 const
1217 mpg123_id3_pic_other = #0; (**< see ID3v2 docs *)
1218 mpg123_id3_pic_icon = #1; (**< see ID3v2 docs *)
1219 mpg123_id3_pic_other_icon = #2; (**< see ID3v2 docs *)
1220 mpg123_id3_pic_front_cover = #3; (**< see ID3v2 docs *)
1221 mpg123_id3_pic_back_cover = #4; (**< see ID3v2 docs *)
1222 mpg123_id3_pic_leaflet = #5; (**< see ID3v2 docs *)
1223 mpg123_id3_pic_media = #6; (**< see ID3v2 docs *)
1224 mpg123_id3_pic_lead = #7; (**< see ID3v2 docs *)
1225 mpg123_id3_pic_artist = #8; (**< see ID3v2 docs *)
1226 mpg123_id3_pic_conductor = #9; (**< see ID3v2 docs *)
1227 mpg123_id3_pic_orchestra = #10; (**< see ID3v2 docs *)
1228 mpg123_id3_pic_composer = #11; (**< see ID3v2 docs *)
1229 mpg123_id3_pic_lyricist = #12; (**< see ID3v2 docs *)
1230 mpg123_id3_pic_location = #13; (**< see ID3v2 docs *)
1231 mpg123_id3_pic_recording = #14; (**< see ID3v2 docs *)
1232 mpg123_id3_pic_performance = #15; (**< see ID3v2 docs *)
1233 mpg123_id3_pic_video = #16; (**< see ID3v2 docs *)
1234 mpg123_id3_pic_fish = #17; (**< see ID3v2 docs *)
1235 mpg123_id3_pic_illustration = #18; (**< see ID3v2 docs *)
1236 mpg123_id3_pic_artist_logo = #19; (**< see ID3v2 docs *)
1237 mpg123_id3_pic_publisher_logo = #20; (**< see ID3v2 docs *)
1239 (** Sub data structure for ID3v2, for storing picture data including comment.
1240 * This is for the ID3v2 APIC field. You should consult the ID3v2 specification
1241 * for the use of the APIC field ("frames" in ID3v2 documentation, I use "fields"
1242 * here to separate from MPEG frames). *)
1243 type
1244 pmpg123_picture_type = ^mpg123_picture_type;
1245 mpg123_picture_type = record
1246 pic_type: char; (**< mpg123_id3_pic_type value *)
1247 description: mpg123_string; (**< description string *)
1248 mime_type: mpg123_string; (**< MIME type *)
1249 size: csize_t; (**< size in bytes *)
1250 data: pcuchar; (**< pointer to the image data *)
1251 end;
1253 (** Data structure for storing IDV3v2 tags.
1254 * This structure is not a direct binary mapping with the file contents.
1255 * The ID3v2 text frames are allowed to contain multiple strings.
1256 * So check for null bytes until you reach the mpg123_string fill.
1257 * All text is encoded in UTF-8. *)
1258 type
1259 pmpg123_id3v2 = ^mpg123_id3v2;
1260 ppmpg123_id3v2 = ^pmpg123_id3v2;
1261 mpg123_id3v2 = record
1262 version: cuchar; (**< 3 or 4 for ID3v2.3 or ID3v2.4. *)
1263 title: pmpg123_string; (**< Title string (pointer into text_list). *)
1264 artist: pmpg123_string; (**< Artist string (pointer into text_list). *)
1265 album: pmpg123_string; (**< Album string (pointer into text_list). *)
1266 year: pmpg123_string; (**< The year as a string (pointer into text_list). *)
1267 genre: pmpg123_string; (**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. *)
1268 comment: pmpg123_string; (**< Pointer to last encountered comment text with empty description. *)
1269 (* Encountered ID3v2 fields are appended to these lists.
1270 There can be multiple occurences, the pointers above always point to the last encountered data. *)
1271 comment_list: pmpg123_text; (**< Array of comments. *)
1272 comments: csize_t; (**< Number of comments. *)
1273 text: pmpg123_text; (**< Array of ID3v2 text fields (including USLT) *)
1274 texts: csize_t; (**< Numer of text fields. *)
1275 extra: pmpg123_text; (**< The array of extra (TXXX) fields. *)
1276 extras: csize_t; (**< Number of extra text (TXXX) fields. *)
1277 picture: pmpg123_picture_type; (**< Array of ID3v2 pictures fields (APIC). *)
1278 pictures: csize_t; (**< Number of picture (APIC) fields. *)
1279 end;
1281 (** Data structure for ID3v1 tags (the last 128 bytes of a file).
1282 * Don't take anything for granted (like string termination)!
1283 * Also note the change ID3v1.1 did: comment[28] = 0; comment[29] = track_number
1284 * It is your task to support ID3v1 only or ID3v1.1 ...*)
1285 type
1286 pmpg123_id3v1 = ^mpg123_id3v1;
1287 ppmpg123_id3v1 = ^pmpg123_id3v1;
1288 mpg123_id3v1 = record
1289 tag: array[0..2] of char; (**< Always the string "TAG", the classic intro. *)
1290 title: array[0..29] of char; (**< Title string. *)
1291 artist: array[0..29] of char; (**< Artist string. *)
1292 album: array[0..29] of char; (**< Album string. *)
1293 year: array[0..3] of char; (**< Year string. *)
1294 comment: array[0..29] of char; (**< Comment string. *)
1295 genre: cuchar; (**< Genre index. *)
1296 end;
1298 const
1299 MPG123_ID3_CONST = $3; (**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. *)
1300 MPG123_NEW_ID3 = $1; (**< 0001 There is ID3 info that changed since last call to mpg123_id3. *)
1301 MPG123_ICY_CONST = $c; (**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*)
1302 MPG123_NEW_ICY = $4; (**< 0100 There is ICY info that changed since last call to mpg123_icy. *)
1304 (** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).
1305 * \param mh handle
1306 * \return combination of flags, 0 on error (same as "nothing new")
1307 *)
1308 function mpg123_meta_check(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF}; (* On error (no valid handle) just 0 is returned. *)
1310 (** Clean up meta data storage (ID3v2 and ICY), freeing memory.
1311 * \param mh handle
1312 *)
1313 procedure mpg123_meta_free(mh: pmpg123_handle); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1315 (** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.
1316 * v1 and/or v2 can be set to NULL when there is no corresponding data.
1317 * \return MPG123_OK on success
1318 *)
1319 function mpg123_id3(mh: pmpg123_handle; v1: ppmpg123_id3v1; v2: ppmpg123_id3v2): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1321 (** Point icy_meta to existing data structure wich may change on any next read/decode function call.
1322 * \param mh handle
1323 * \param icy_meta return address for ICY meta string (set to NULL if nothing there)
1324 * \return MPG123_OK on success
1325 *)
1326 function mpg123_icy(mh: pmpg123_handle; icy_meta: ppchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF}; (* same for ICY meta string *)
1328 (** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.
1329 * Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .
1330 * \param icy_text The input data in ICY encoding
1331 * \return pointer to newly allocated buffer with UTF-8 data (You free() it!) *)
1332 function mpg123_icy2utf8(const icy_text: pchar): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1334 (* @} *)
1336 (** \defgroup mpg123_advpar mpg123 advanced parameter API
1338 * Direct access to a parameter set without full handle around it.
1339 * Possible uses:
1340 * - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).
1341 * - Use one set of parameters for multiple handles.
1343 * The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()
1344 * family) directly return a fully qualified mpg123 error code, the ones
1345 * operating on full handles normally MPG123_OK or MPG123_ERR, storing the
1346 * specific error code itseld inside the handle.
1348 * @{
1349 *)
1351 (** Opaque structure for the libmpg123 decoder parameters. *)
1352 type
1353 pmpg123_pars_struct = ^mpg123_pars_struct;
1354 mpg123_pars_struct = record
1355 end;
1357 (** Opaque structure for the libmpg123 decoder parameters. *)
1358 type
1359 pmpg123_pars = ^mpg123_pars;
1360 mpg123_pars = pmpg123_pars_struct;
1362 (** Create a handle with preset parameters.
1363 * \param mp parameter handle
1364 * \param decoder decoder choice
1365 * \param error error code return address
1366 * \return mpg123 handle
1367 *)
1368 function mpg123_parnew(mp: pmpg123_pars; const decoder: pchar; error: pcint): pmpg123_handle; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1370 (** Allocate memory for and return a pointer to a new mpg123_pars
1371 * \param error error code return address
1372 * \return new parameter handle
1373 *)
1374 function mpg123_new_pars(error: pcint): pmpg123_pars; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1376 (** Delete and free up memory used by a mpg123_pars data structure
1377 * \param mp parameter handle
1378 *)
1379 procedure mpg123_delete_pars(mp: pmpg123_pars); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1381 (** Configure mpg123 parameters to accept no output format at all,
1382 * use before specifying supported formats with mpg123_format
1383 * \param mp parameter handle
1384 * \return MPG123_OK on success
1385 *)
1386 function mpg123_fmt_none(mp: pmpg123_pars): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1388 (** Configure mpg123 parameters to accept all formats
1389 * (also any custom rate you may set) -- this is default.
1390 * \param mp parameter handle
1391 * \return MPG123_OK on success
1392 *)
1393 function mpg123_fmt_all(mp: pmpg123_pars): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1395 (** Set the audio format support of a mpg123_pars in detail:
1396 * \param mp parameter handle
1397 * \param rate The sample rate value (in Hertz).
1398 * \param channels A combination of MPG123_STEREO and MPG123_MONO.
1399 * \param encodings A combination of accepted encodings for rate and channels,
1400 * p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no
1401 * support).
1402 * \return MPG123_OK on success
1403 *)
1404 function mpg123_fmt(mp: pmpg123_pars; rate: clong; channels: cint; encodings: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF}; (* 0 is good, -1 is error *)
1406 (** Check to see if a specific format at a specific rate is supported
1407 * by mpg123_pars.
1408 * \param mp parameter handle
1409 * \param rate sampling rate
1410 * \param encoding encoding
1411 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
1412 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. *)
1413 function mpg123_fmt_support(mp: pmpg123_pars; rate: clong; encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1415 (** Set a specific parameter, for a specific mpg123_pars, using a parameter
1416 * type key chosen from the mpg123_parms enumeration, to the specified value.
1417 * \param mp parameter handle
1418 * \param type parameter choice
1419 * \param value integer value
1420 * \param fvalue floating point value
1421 * \return MPG123_OK on success
1422 *)
1423 function mpg123_par(mp: pmpg123_pars; _type: mpg123_parms; value: clong; fvalue: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1425 (** Get a specific parameter, for a specific mpg123_pars.
1426 * See the mpg123_parms enumeration for a list of available parameters.
1427 * \param mp parameter handle
1428 * \param type parameter choice
1429 * \param value integer value return address
1430 * \param fvalue floating point value return address
1431 * \return MPG123_OK on success
1432 *)
1433 function mpg123_getpar(mp: pmpg123_pars; _type: mpg123_parms; val: pclong; fval: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1435 (* @} *)
1438 (** \defgroup mpg123_lowio mpg123 low level I/O
1439 * You may want to do tricky stuff with I/O that does not work with mpg123's default file access or you want to make it decode into your own pocket...
1441 * @{ *)
1443 (** Replace default internal buffer with user-supplied buffer.
1444 * Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio.
1445 * Note that the required buffer size could be bigger than expected from output
1446 * encoding if libmpg123 has to convert from primary decoder output (p.ex. 32 bit
1447 * storage for 24 bit output).
1448 * \param mh handle
1449 * \param data pointer to user buffer
1450 * \param size of buffer in bytes
1451 * \return MPG123_OK on success
1452 *)
1453 function mpg123_replace_buffer(mh: pmpg123_handle; data: pcuchar; size: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1455 (** The max size of one frame's decoded output with current settings.
1456 * Use that to determine an appropriate minimum buffer size for decoding one frame.
1457 * \param mh handle
1458 * \return maximum decoded data size in bytes
1459 *)
1460 function mpg123_outblock(mh: pmpg123_handle): csize_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1462 (** Replace low-level stream access functions; read and lseek as known in POSIX.
1463 * You can use this to make any fancy file opening/closing yourself,
1464 * using mpg123_open_fd() to set the file descriptor for your read/lseek
1465 * (doesn't need to be a "real" file descriptor...).
1466 * Setting a function to NULL means that the default internal read is
1467 * used (active from next mpg123_open call on).
1468 * Note: As it would be troublesome to mess with this while having a file open,
1469 * this implies mpg123_close().
1470 * \param mh handle
1471 * \param r_read callback for reading (behaviour like POSIX read)
1472 * \param r_lseek callback for seeking (like POSIX lseek)
1473 * \return MPG123_OK on success
1474 *)
1475 type
1476 mpg123_readproc = function(fd: pointer; buf: pointer; count: csize_t): csize_t; cdecl;
1477 mpg123_seekproc = function(fd: pointer; count: off_t; offset: cint): off_t; cdecl;
1479 function mpg123_replace_reader(mh: pmpg123_handle; r_read: mpg123_readproc; r_lseek: mpg123_seekproc): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1481 (** Replace I/O functions with your own ones operating on some kind of
1482 * handle instead of integer descriptors.
1483 * The handle is a void pointer, so you can pass any data you want...
1484 * mpg123_open_handle() is the call you make to use the I/O defined here.
1485 * There is no fallback to internal read/seek here.
1486 * Note: As it would be troublesome to mess with this while having a file open,
1487 * this mpg123_close() is implied here.
1488 * \param mh handle
1489 * \param r_read callback for reading (behaviour like POSIX read)
1490 * \param r_lseek callback for seeking (like POSIX lseek)
1491 * \param cleanup A callback to clean up an I/O handle on mpg123_close,
1492 * can be NULL for none (you take care of cleaning your handles).
1493 * \return MPG123_OK on success
1494 *)
1495 function mpg123_replace_reader_handle(mh: pmpg123_handle; r_read: mpg123_readproc; r_lseek: mpg123_seekproc; cleanup: pointer): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1497 (* @} *)
1499 implementation
1501 end.