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 *)
22 interface
24 uses
25 ctypes;
27 {$IFDEF FPC}
28 {$PACKRECORDS C}
29 {$ENDIF}
31 {$IF DEFINED(WINDOWS)}
32 {$IFDEF MPG123_WINDOZE_STATIC}
33 {$LINKLIB libmpg123.a}
34 {$ELSE}
35 {$DEFINE MPG123_DYNAMIC}
37 {$ENDIF}
38 {$ELSEIF DEFINED(UNIX)}
39 {$DEFINE MPG123_DYNAMIC}
41 {$ELSE}
42 {$ERROR libmpg123 not supported on this platform. Fix it!}
43 {$ENDIF}
45 type
50 (* off_t = cint; *)
56 const
57 (** A macro to check at compile time which set of API functions to expect.
58 * This should be incremented at least each time a new symbol is added
59 * to the header.
60 *)
65 //TODO /** Defines needed for MS Visual Studio(tm) DLL builds.
66 //TODO * Every public function must be prefixed with MPG123_EXPORT. When building
67 //TODO * the DLL ensure to define BUILD_MPG123_DLL. This makes the function accessible
68 //TODO * for clients and includes it in the import library which is created together
69 //TODO * with the DLL. When consuming the DLL ensure to define LINK_MPG123_DLL which
70 //TODO * imports the functions from the DLL.
71 //TODO */
72 //TODO #ifdef BUILD_MPG123_DLL
73 //TODO /* The dll exports. */
74 //TODO #define MPG123_EXPORT __declspec(dllexport)
75 //TODO #else
76 //TODO #ifdef LINK_MPG123_DLL
77 //TODO /* The exe imports. */
78 //TODO #define MPG123_EXPORT __declspec(dllimport)
79 //TODO #else
80 //TODO /* Nothing on normal/UNIX builds */
81 //TODO #define MPG123_EXPORT
82 //TODO #endif
83 //TODO #endif
84 //TODO
85 //TODO /* This is for Visual Studio, so this header works as distributed in the binary downloads */
86 //TODO #if defined(_MSC_VER) && !defined(MPG123_DEF_SSIZE_T)
87 //TODO #define MPG123_DEF_SSIZE_T
88 //TODO #include <stddef.h>
89 //TODO typedef ptrdiff_t ssize_t;
90 //TODO #endif
91 //TODO
92 //TODO #ifndef MPG123_NO_CONFIGURE /* Enable use of this file without configure. */
93 //TODO #include <stdlib.h>
94 //TODO #include <sys/types.h>
95 //TODO
96 //TODO /* Simplified large file handling.
97 //TODO I used to have a check here that prevents building for a library with conflicting large file setup
98 //TODO (application that uses 32 bit offsets with library that uses 64 bits).
99 //TODO While that was perfectly fine in an environment where there is one incarnation of the library,
100 //TODO it hurt GNU/Linux and Solaris systems with multilib where the distribution fails to provide the
101 //TODO correct header matching the 32 bit library (where large files need explicit support) or
102 //TODO the 64 bit library (where there is no distinction).
103 //TODO
104 //TODO New approach: When the app defines _FILE_OFFSET_BITS, it wants non-default large file support,
105 //TODO and thus functions with added suffix (mpg123_open_64).
106 //TODO Any mismatch will be caught at link time because of the _FILE_OFFSET_BITS setting used when
107 //TODO building libmpg123. Plus, there's dual mode large file support in mpg123 since 1.12 now.
108 //TODO Link failure is not the expected outcome of any half-sane usage anymore.
109 //TODO
110 //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.
111 //TODO */
112 //TODO
113 //TODO /*
114 //TODO Now, the renaming of large file aware functions.
115 //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.
116 //TODO */
117 //TODO #if (!defined MPG123_NO_LARGENAME) && ((defined _FILE_OFFSET_BITS) || (defined MPG123_LARGESUFFIX))
118 //TODO
119 //TODO /* Need some trickery to concatenate the value(s) of the given macro(s). */
120 //TODO #define MPG123_MACROCAT_REALLY(a, b) a ## b
121 //TODO #define MPG123_MACROCAT(a, b) MPG123_MACROCAT_REALLY(a, b)
122 //TODO #ifndef MPG123_LARGESUFFIX
123 //TODO #define MPG123_LARGESUFFIX MPG123_MACROCAT(_, _FILE_OFFSET_BITS)
124 //TODO #endif
125 //TODO #define MPG123_LARGENAME(func) MPG123_MACROCAT(func, MPG123_LARGESUFFIX)
126 //TODO
127 //TODO #define mpg123_open MPG123_LARGENAME(mpg123_open)
128 //TODO #define mpg123_open_fd MPG123_LARGENAME(mpg123_open_fd)
129 //TODO #define mpg123_open_handle MPG123_LARGENAME(mpg123_open_handle)
130 //TODO #define mpg123_framebyframe_decode MPG123_LARGENAME(mpg123_framebyframe_decode)
131 //TODO #define mpg123_decode_frame MPG123_LARGENAME(mpg123_decode_frame)
132 //TODO #define mpg123_tell MPG123_LARGENAME(mpg123_tell)
133 //TODO #define mpg123_tellframe MPG123_LARGENAME(mpg123_tellframe)
134 //TODO #define mpg123_tell_stream MPG123_LARGENAME(mpg123_tell_stream)
135 //TODO #define mpg123_seek MPG123_LARGENAME(mpg123_seek)
136 //TODO #define mpg123_feedseek MPG123_LARGENAME(mpg123_feedseek)
137 //TODO #define mpg123_seek_frame MPG123_LARGENAME(mpg123_seek_frame)
138 //TODO #define mpg123_timeframe MPG123_LARGENAME(mpg123_timeframe)
139 //TODO #define mpg123_index MPG123_LARGENAME(mpg123_index)
140 //TODO #define mpg123_set_index MPG123_LARGENAME(mpg123_set_index)
141 //TODO #define mpg123_position MPG123_LARGENAME(mpg123_position)
142 //TODO #define mpg123_length MPG123_LARGENAME(mpg123_length)
143 //TODO #define mpg123_framelength MPG123_LARGENAME(mpg123_framelength)
144 //TODO #define mpg123_set_filesize MPG123_LARGENAME(mpg123_set_filesize)
145 //TODO #define mpg123_replace_reader MPG123_LARGENAME(mpg123_replace_reader)
146 //TODO #define mpg123_replace_reader_handle MPG123_LARGENAME(mpg123_replace_reader_handle)
147 //TODO #define mpg123_framepos MPG123_LARGENAME(mpg123_framepos)
148 //TODO
149 //TODO #endif /* largefile hackery */
150 //TODO
151 //TODO #endif /* MPG123_NO_CONFIGURE */
153 (** \defgroup mpg123_init mpg123 library and handle setup
154 *
155 * Functions to initialise and shutdown the mpg123 library and handles.
156 * The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)
157 * Tip: Use a RVA setting...
158 *
159 * @{
160 *)
162 (** Opaque structure for the libmpg123 decoder handle. *)
163 type
168 (** Opaque structure for the libmpg123 decoder handle.
169 * Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.
170 *)
171 type
175 (** Function to initialise the mpg123 library.
176 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library.
177 *
178 * \return MPG123_OK if successful, otherwise an error number.
179 *)
182 (** Function to close down the mpg123 library.
183 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. *)
186 (** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).
187 * and optional retrieval of an error code to feed to mpg123_plain_strerror().
188 * Optional means: Any of or both the parameters may be NULL.
189 *
190 * \param decoder optional choice of decoder variant (NULL for default)
191 * \param error optional address to store error codes
192 * \return Non-NULL pointer to fresh handle when successful.
193 *)
194 function mpg123_new(const decoder: pchar; error: pcint): pmpg123_handle; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
196 (** Delete handle, mh is either a valid mpg123 handle or NULL.
197 * \param mh handle
198 *)
199 procedure mpg123_delete(mh: pmpg123_handle); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
201 (** Enumeration of the parameters types that it is possible to set/get. *)
202 type
204 const
205 MPG123_VERBOSE = 0; (**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) *)
216 MPG123_OUTSCALE = 11; (**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) *)
217 MPG123_TIMEOUT = 12; (**< timeout for reading from a stream (not supported on win32, integer) *)
219 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). *)
220 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. *)
221 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.*)
222 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) *)
223 MPG123_FEEDBUFFER = 18; (**< Minimal size of one internal feeder buffer, again, the default value is subject to change. (integer) *)
225 (** Flag bits for MPG123_FLAGS, use the usual binary or to combine. *)
226 type
228 const
229 MPG123_FORCE_MONO = $7; (**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. *)
236 MPG123_GAPLESS = $40; (**< 01000000 Enable gapless decoding (default on if libmpg123 has support). *)
238 MPG123_SEEKBUFFER = $100; (**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). *)
239 MPG123_FUZZY = $200; (**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) *)
240 MPG123_FORCE_FLOAT = $400; (**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). *)
241 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. *)
242 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 *)
244 MPG123_IGNORE_INFOFRAME = $4000; (**< 100 0000 0000 0000 Do not parse the LAME/Xing info frame, treat it as normal MPEG data. *)
245 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. *)
248 * the stream in order to probe
249 * the stream length and search for the id3v1 field. This also means
250 * the file size is unknown unless set using mpg123_set_filesize() and
251 * the stream is assumed as non-seekable unless overridden.
252 *)
256 (** choices for MPG123_RVA *)
257 type
259 const
265 (** Set a specific parameter, for a specific mpg123_handle, using a parameter
266 * type key chosen from the mpg123_parms enumeration, to the specified value.
267 * \param mh handle
268 * \param type parameter choice
269 * \param value integer value
270 * \param fvalue floating point value
271 * \return MPG123_OK on success
272 *)
273 function mpg123_param(mh: pmpg123_handle; _type: mpg123_parms; value: clong; fvalue: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
275 (** Get a specific parameter, for a specific mpg123_handle.
276 * See the mpg123_parms enumeration for a list of available parameters.
277 * \param mh handle
278 * \param type parameter choice
279 * \param value integer value return address
280 * \param fvalue floating point value return address
281 * \return MPG123_OK on success
282 *)
283 function mpg123_getparam(mh: pmpg123_handle; _type: mpg123_parms; val: pclong; fval: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
285 (** Feature set available for query with mpg123_feature. *)
286 type
288 const
289 MPG123_FEATURE_ABI_UTF8OPEN = 0; (**< mpg123 expects path names to be given in UTF-8 encoding instead of plain native. *)
305 (** Query libmpg123 features.
306 * \param key feature selection
307 * \return 1 for success, 0 for unimplemented functions
308 *)
309 function mpg123_feature(const key: mpg123_feature_set): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
311 (* @} *)
313 (** \defgroup mpg123_error mpg123 error handling
314 *
315 * Functions to get text version of the error numbers and an enumeration
316 * of the error codes returned by libmpg123.
317 *
318 * Most functions operating on a mpg123_handle simply return MPG123_OK (0)
319 * on success and MPG123_ERR (-1) on failure, setting the internal error
320 * variable of the handle to the specific error code. If there was not a valid
321 * (non-NULL) handle provided to a function operating on one, MPG123_BAD_HANDLE
322 * may be returned if this can not be confused with a valid positive return
323 * value.
324 * Meaning: A function expected to return positive integers on success will
325 * always indicate error or a special condition by returning a negative one.
326 *
327 * Decoding/seek functions may also return message codes MPG123_DONE,
328 * MPG123_NEW_FORMAT and MPG123_NEED_MORE (all negative, see below on how to
329 * react). Note that calls to those can be nested, so generally watch out
330 * for these codes after initial handle setup.
331 * Especially any function that needs information about the current stream
332 * to work will try to at least parse the beginning if that did not happen
333 * yet.
334 *
335 * On a function that is supposed to return MPG123_OK on success and
336 * MPG123_ERR on failure, make sure you check for != MPG123_OK, not
337 * == MPG123_ERR, as the error code could get more specific in future,
338 * or there is just a special message from a decoding routine as indicated
339 * above.
340 *
341 * @{
342 *)
344 (** Enumeration of the message and error codes and returned by libmpg123 functions. *)
345 type
347 const
349 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. *)
350 MPG123_NEED_MORE = -10; (**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). *)
394 MPG123_LFS_OVERFLOW = 42; (**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. *)
397 (** An enum over all sample types possibly known to mpg123.
398 * The values are designed as bit flags to allow bitmasking for encoding families.
399 *
400 * Note that (your build of) libmpg123 does not necessarily support all these.
401 * Usually, you can expect the 8bit encodings and signed 16 bit.
402 * Also 32bit float will be usual beginning with mpg123-1.7.0 .
403 * What you should bear in mind is that (SSE, etc) optimized routines may be absent
404 * for some formats. We do have SSE for 16, 32 bit and float, though.
405 * 24 bit integer is done via postprocessing of 32 bit output -- just cutting
406 * the last byte, no rounding, even. If you want better, do it yourself.
407 *
408 * All formats are in native byte order. If you need different endinaness, you
409 * can simply postprocess the output buffers (libmpg123 wouldn't do anything else).
410 * mpg123_encsize() can be helpful there.
411 *)
413 type
415 const
422 MPG123_ENC_SIGNED_16 = (MPG123_ENC_16 or MPG123_ENC_SIGNED or $10); (* 1101 0000 signed 16 bit *)
428 MPG123_ENC_SIGNED_32 = MPG123_ENC_32 or MPG123_ENC_SIGNED or $1000; (* 0001 0001 1000 0000 signed 32 bit *)
430 MPG123_ENC_SIGNED_24 = MPG123_ENC_24 or MPG123_ENC_SIGNED or $1000; (* 0101 0000 1000 0000 signed 24 bit *)
440 (** Look up error strings given integer code.
441 * \param errcode integer error code
442 * \return string describing what that error error code means
443 *)
444 function mpg123_plain_strerror(errcode: cint): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
446 (** Give string describing what error has occured in the context of handle mh.
447 * When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via
448 * char *errmsg = mpg123_strerror(mh)
449 * This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE.
450 * \param mh handle
451 * \return error message
452 *)
453 function mpg123_strerror(mh: pmpg123_handle): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
455 (** Return the plain errcode intead of a string.
456 * \param mh handle
457 * \return error code recorded in handle or MPG123_BAD_HANDLE
458 *)
459 function mpg123_errcode(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
461 (*@}*)
463 (** \defgroup mpg123_decoder mpg123 decoder selection
464 *
465 * Functions to list and select the available decoders.
466 * Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).
467 *
468 * @{
469 *)
471 (** Get available decoder list.
472 * \return NULL-terminated array of generally available decoder names (plain 8bit ASCII)
473 *)
476 (** Get supported decoder list.
477 * \return NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII)
478 *)
479 function mpg123_supported_decoders(): ppchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
481 (** Set the active decoder.
482 * \param mh handle
483 * \param decoder_name name of decoder
484 * \return MPG123_OK on success
485 *)
486 function mpg123_decoder(mh: pmpg123_handle; const decoder_name: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
488 (** Get the currently active decoder name.
489 * The active decoder engine can vary depening on output constraints,
490 * mostly non-resampling, integer output is accelerated via 3DNow & Co. but for
491 * other modes a fallback engine kicks in.
492 * Note that this can return a decoder that is ony active in the hidden and not
493 * available as decoder choice from the outside.
494 * \param mh handle
495 * \return The decoder name or NULL on error.
496 *)
497 function mpg123_current_decoder(mh: pmpg123_handle): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
499 (*@}*)
501 (** \defgroup mpg123_output mpg123 output audio format
502 *
503 * Functions to get and select the format of the decoded audio.
504 *
505 * 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.
506 *
507 * 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).
508 *
509 * 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.
510 *
511 * 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.
512 *
513 * 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.
514 *
515 * @{
516 *)
518 (** They can be combined into one number (3) to indicate mono and stereo... *)
519 type
521 const
525 (** An array of supported standard sample rates
526 * These are possible native sample rates of MPEG audio files.
527 * You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings.
528 * \param list Store a pointer to the sample rates array there.
529 * \param number Store the number of sample rates there. *)
530 procedure mpg123_rates(const list: ppclong; number: pcsize_t); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
532 (** An array of supported audio encodings.
533 * An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).
534 * \param list Store a pointer to the encodings array there.
535 * \param number Store the number of encodings there. *)
536 procedure mpg123_encodings(const list: ppcint; number: pcsize_t); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
538 (** Return the size (in bytes) of one mono sample of the named encoding.
539 * \param encoding The encoding value to analyze.
540 * \return positive size of encoding in bytes, 0 on invalid encoding. *)
541 function mpg123_encsize(encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
543 (** Configure a mpg123 handle to accept no output format at all,
544 * use before specifying supported formats with mpg123_format
545 * \param mh handle
546 * \return MPG123_OK on success
547 *)
548 function mpg123_format_none(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
550 (** Configure mpg123 handle to accept all formats
551 * (also any custom rate you may set) -- this is default.
552 * \param mh handle
553 * \return MPG123_OK on success
554 *)
555 function mpg123_format_all(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
557 (** Set the audio format support of a mpg123_handle in detail:
558 * \param mh handle
559 * \param rate The sample rate value (in Hertz).
560 * \param channels A combination of MPG123_STEREO and MPG123_MONO.
561 * \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.
562 * \return MPG123_OK on success, MPG123_ERR if there was an error. *)
563 function mpg123_format(mh: pmpg123_handle; rate: clong; channels: cint; encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
565 (** Check to see if a specific format at a specific rate is supported
566 * by mpg123_handle.
567 * \param mh handle
568 * \param rate sampling rate
569 * \param encoding encoding
570 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
571 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. *)
572 function mpg123_format_support(mh: pmpg123_handle; rate: clong; encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
574 (** Get the current output format written to the addresses given.
575 * If the stream is freshly loaded, this will try to parse enough
576 * of it to give you the format to come. This clears the flag that
577 * would otherwise make the first decoding call return
578 * MPG123_NEW_FORMAT.
579 * \param mh handle
580 * \param rate sampling rate return address
581 * \param channels channel count return address
582 * \param encoding encoding return address
583 * \return MPG123_OK on success
584 *)
585 function mpg123_getformat(mh: pmpg123_handle; rate: pclong; channels: pcint; encoding: pcint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
587 (** Get the current output format written to the addresses given.
588 * This differs from plain mpg123_getformat() in that you can choose
589 * _not_ to clear the flag that would trigger the next decoding call
590 * to return MPG123_NEW_FORMAT in case of a new format arriving.
591 * \param mh handle
592 * \param rate sampling rate return address
593 * \param channels channel count return address
594 * \param encoding encoding return address
595 * \param clear_flag if true, clear internal format flag
596 * \return MPG123_OK on success
597 *)
598 function mpg123_getformat2(mh: pmpg123_handle; rate: pclong; channels: pcint; encoding: pcint; clear_flag: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
600 (*@}*)
602 (** \defgroup mpg123_input mpg123 file input and decoding
603 *
604 * Functions for input bitstream and decoding operations.
605 * 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!).
606 * @{
607 *)
609 (* reading samples / triggering decoding, possible return values: *)
610 (** Enumeration of the error codes returned by libmpg123 functions. *)
612 (** Open and prepare to decode the specified file by filesystem path.
613 * This does not open HTTP urls; libmpg123 contains no networking code.
614 * If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().
615 * \param mh handle
616 * \param path filesystem path
617 * \return MPG123_OK on success
618 *)
619 function mpg123_open(mh: pmpg123_handle; const path: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
621 (** Use an already opened file descriptor as the bitstream input
622 * mpg123_close() will _not_ close the file descriptor.
623 * \param mh handle
624 * \param fd file descriptor
625 * \return MPG123_OK on success
626 *)
627 function mpg123_open_fd(mh: pmpg123_handle; fd: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
629 (** Use an opaque handle as bitstream input. This works only with the
630 * replaced I/O from mpg123_replace_reader_handle()!
631 * mpg123_close() will call the cleanup callback for your handle (if you gave one).
632 * \param mh handle
633 * \param iohandle your handle
634 * \return MPG123_OK on success
635 *)
636 function mpg123_open_handle(mh: pmpg123_handle; iohandle: pointer): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
638 (** Open a new bitstream and prepare for direct feeding
639 * This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.
640 * \param mh handle
641 * \return MPG123_OK on success
642 *)
643 function mpg123_open_feed(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
645 (** Closes the source, if libmpg123 opened it.
646 * \param mh handle
647 * \return MPG123_OK on success
648 *)
649 function mpg123_close(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
651 (** Read from stream and decode up to outmemsize bytes.
652 * \param mh handle
653 * \param outmemory address of output buffer to write to
654 * \param outmemsize maximum number of bytes to write
655 * \param done address to store the number of actually decoded bytes to
656 * \return MPG123_OK or error/message code
657 *)
658 function mpg123_read(mh: pmpg123_handle; outmemory: pcuchar; outmemsize: csize_t; done: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
660 (** Feed data for a stream that has been opened with mpg123_open_feed().
661 * It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.
662 * \param mh handle
663 * \param in input buffer
664 * \param size number of input bytes
665 * \return MPG123_OK or error/message code.
666 *)
667 function mpg123_feed(mh: pmpg123_handle; const _in: pcuchar; size: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
669 (** Decode MPEG Audio from inmemory to outmemory.
670 * This is very close to a drop-in replacement for old mpglib.
671 * When you give zero-sized output buffer the input will be parsed until
672 * decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)
673 * without taking decoded data.
674 * Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).
675 * You can actually always decide if you want those specialized functions in separate steps or one call this one here.
676 * \param mh handle
677 * \param inmemory input buffer
678 * \param inmemsize number of input bytes
679 * \param outmemory output buffer
680 * \param outmemsize maximum number of output bytes
681 * \param done address to store the number of actually decoded bytes to
682 * \return error/message code (watch out especially for MPG123_NEED_MORE)
683 *)
684 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};
686 (** Decode next MPEG frame to internal buffer
687 * or read a frame and return after setting a new format.
688 * \param mh handle
689 * \param num current frame offset gets stored there
690 * \param audio This pointer is set to the internal buffer to read the decoded audio from.
691 * \param bytes number of output bytes ready in the buffer
692 * \return MPG123_OK or error/message code
693 *)
694 function mpg123_decode_frame(mh: pmpg123_handle; num: poff_t; audio: ppcuchar; bytes: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
696 (** Decode current MPEG frame to internal buffer.
697 * Warning: This is experimental API that might change in future releases!
698 * Please watch mpg123 development closely when using it.
699 * \param mh handle
700 * \param num last frame offset gets stored there
701 * \param audio this pointer is set to the internal buffer to read the decoded audio from.
702 * \param bytes number of output bytes ready in the buffer
703 * \return MPG123_OK or error/message code
704 *)
705 function mpg123_framebyframe_decode(mh: pmpg123_handle; num: poff_t; audio: ppcuchar; bytes: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
707 (** Find, read and parse the next mp3 frame
708 * Warning: This is experimental API that might change in future releases!
709 * Please watch mpg123 development closely when using it.
710 * \param mh handle
711 * \return MPG123_OK or error/message code
712 *)
713 function mpg123_framebyframe_next(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
715 (** Get access to the raw input data for the last parsed frame.
716 * This gives you a direct look (and write access) to the frame body data.
717 * 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()).
718 * 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.
719 * You can provide NULL for a parameter pointer when you are not interested in the value.
720 *
721 * \param mh handle
722 * \param header the 4-byte MPEG header
723 * \param bodydata pointer to the frame body stored in the handle (without the header)
724 * \param bodybytes size of frame body in bytes (without the header)
725 * \return MPG123_OK if there was a yet un-decoded frame to get the
726 * data from, MPG123_BAD_HANDLE or MPG123_ERR otherwise (without further
727 * explanation, the error state of the mpg123_handle is not modified by
728 * this function).
729 *)
730 function mpg123_framedata(mh: pmpg123_handle; header: pculong; bodydata: ppcuchar; bodybytes: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
732 (** Get the input position (byte offset in stream) of the last parsed frame.
733 * This can be used for external seek index building, for example.
734 * It just returns the internally stored offset, regardless of validity -- you ensure that a valid frame has been parsed before! *)
735 function mpg123_framepos(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
737 (*@}*)
739 (** \defgroup mpg123_seek mpg123 position and seeking
740 *
741 * Functions querying and manipulating position in the decoded audio bitstream.
742 * The position is measured in decoded audio samples, or MPEG frame offset for the specific functions.
743 * 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;-)
744 * The general usage is modelled after stdlib's ftell() and fseek().
745 * 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:
746 * - SEEK_SET: set position to (or near to) specified offset
747 * - SEEK_CUR: change position by offset from now
748 * - SEEK_END: set position to offset from end
749 *
750 * Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise.
751 * 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)!
752 * Short: When you care about the sample position, don't mess with those parameters;-)
753 * Also, seeking is not guaranteed to work for all streams (underlying stream may not support it).
754 * And yet another caveat: If the stream is concatenated out of differing pieces (Frankenstein stream), seeking may suffer, too.
755 *
756 * @{
757 *)
759 (** Returns the current position in samples.
760 * On the next successful read, you'd get that sample.
761 * \param mh handle
762 * \return sample offset or MPG123_ERR (null handle)
763 *)
764 function mpg123_tell(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
766 (** Returns the frame number that the next read will give you data from.
767 * \param mh handle
768 * \return frame offset or MPG123_ERR (null handle)
769 *)
770 function mpg123_tellframe(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
772 (** Returns the current byte offset in the input stream.
773 * \param mh handle
774 * \return byte offset or MPG123_ERR (null handle)
775 *)
776 function mpg123_tell_stream(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
778 (** Seek to a desired sample offset.
779 * Usage is modelled afer the standard lseek().
780 * \param mh handle
781 * \param sampleoff offset in PCM samples
782 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
783 * \return The resulting offset >= 0 or error/message code
784 *)
785 function mpg123_seek(mh: pmpg123_handle; sampleoff: off_t; whence: cint): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
787 (** Seek to a desired sample offset in data feeding mode.
788 * 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.
789 * \param mh handle
790 * \param sampleoff offset in PCM samples
791 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
792 * \param input_offset The position it expects to be at the
793 * next time data is fed to mpg123_decode().
794 * \return The resulting offset >= 0 or error/message code *)
795 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};
797 (** Seek to a desired MPEG frame offset.
798 * Usage is modelled afer the standard lseek().
799 * \param mh handle
800 * \param frameoff offset in MPEG frames
801 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
802 * \return The resulting offset >= 0 or error/message code *)
803 function mpg123_seek_frame(mh: pmpg123_handle; frameoff: off_t; whence: cint): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
805 (** Return a MPEG frame offset corresponding to an offset in seconds.
806 * 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.
807 * \return frame offset >= 0 or error/message code *)
808 function mpg123_timeframe(mh: pmpg123_handle; sec: cdouble): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
810 (** Give access to the frame index table that is managed for seeking.
811 * You are asked not to modify the values... Use mpg123_set_index to set the
812 * seek index
813 * \param mh handle
814 * \param offsets pointer to the index array
815 * \param step one index byte offset advances this many MPEG frames
816 * \param fill number of recorded index offsets; size of the array
817 * \return MPG123_OK on success
818 *)
819 function mpg123_index(mh: pmpg123_handle; offsets: ppoff_t; step: poff_t; fill: pcsize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
821 (** Set the frame index table
822 * Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets
823 * to NULL and fill to 0 will clear the index and free the allocated memory used by the index.
824 * \param mh handle
825 * \param offsets pointer to the index array
826 * \param step one index byte offset advances this many MPEG frames
827 * \param fill number of recorded index offsets; size of the array
828 * \return MPG123_OK on success
829 *)
830 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};
832 (** An old crutch to keep old mpg123 binaries happy.
833 * WARNING: This function is there only to avoid runtime linking errors with
834 * standalone mpg123 before version 1.23.0 (if you strangely update the
835 * library but not the end-user program) and actually is broken
836 * for various cases (p.ex. 24 bit output). Do never use. It might eventually
837 * be purged from the library.
838 *)
839 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};
841 (*@}*)
843 (** \defgroup mpg123_voleq mpg123 volume and equalizer
844 *
845 * @{
846 *)
848 (** another channel enumeration, for left/right choice *)
849 type
851 const
856 (** Set the 32 Band Audio Equalizer settings.
857 * \param mh handle
858 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both.
859 * \param band The equaliser band to change (from 0 to 31)
860 * \param val The (linear) adjustment factor.
861 * \return MPG123_OK on success
862 *)
863 function mpg123_eq(mh: pmpg123_handle; channel: mpg123_channels; band: cint; val: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
865 (** Get the 32 Band Audio Equalizer settings.
866 * \param mh handle
867 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
868 * \param band The equaliser band to change (from 0 to 31)
869 * \return The (linear) adjustment factor (zero for pad parameters) *)
870 function mpg123_geteq(mh: pmpg123_handle; channel: mpg123_channels; band: cint): cdouble; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
872 (** Reset the 32 Band Audio Equalizer settings to flat
873 * \param mh handle
874 * \return MPG123_OK on success
875 *)
876 function mpg123_reset_eq(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
878 (** Set the absolute output volume including the RVA setting,
879 * vol<0 just applies (a possibly changed) RVA setting.
880 * \param mh handle
881 * \param vol volume value (linear factor)
882 * \return MPG123_OK on success
883 *)
884 function mpg123_volume(mh: pmpg123_handle; vol: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
886 (** Adjust output volume including the RVA setting by chosen amount
887 * \param mh handle
888 * \param change volume value (linear factor increment)
889 * \return MPG123_OK on success
890 *)
891 function mpg123_volume_change(mh: pmpg123_handle; change: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
893 (** Return current volume setting, the actual value due to RVA, and the RVA
894 * adjustment itself. It's all as double float value to abstract the sample
895 * format. The volume values are linear factors / amplitudes (not percent)
896 * and the RVA value is in decibels.
897 * \param mh handle
898 * \param base return address for base volume (linear factor)
899 * \param really return address for actual volume (linear factor)
900 * \param rva_db return address for RVA value (decibels)
901 * \return MPG123_OK on success
902 *)
903 function mpg123_getvolume(mh: pmpg123_handle; base: pcdouble; really: pcdouble; rva_db: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
905 (* TODO: Set some preamp in addition / to replace internal RVA handling? *)
907 (*@}*)
909 (** \defgroup mpg123_status mpg123 status and information
910 *
911 * @{
912 *)
914 (** Enumeration of the mode types of Variable Bitrate *)
915 type
917 const
922 (** Enumeration of the MPEG Versions *)
923 type
925 const
931 (** Enumeration of the MPEG Audio mode.
932 * Only the mono mode has 1 channel, the others have 2 channels. *)
933 type
935 const
942 (** Enumeration of the MPEG Audio flag bits *)
943 type
945 const
951 (** Data structure for storing information about a frame of MPEG Audio *)
952 type
961 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. *)
968 (** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure.
969 * \param mh handle
970 * \param mi address of existing frameinfo structure to write to
971 * \return MPG123_OK on success
972 *)
973 function mpg123_info(mh: pmpg123_handle; mi: pmpg123_frameinfo): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
975 (** Get the safe output buffer size for all cases
976 * (when you want to replace the internal buffer)
977 * \return safe buffer size
978 *)
979 function mpg123_safe_buffer(): csize_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
981 (** Make a full parsing scan of each frame in the file. ID3 tags are found. An
982 * accurate length value is stored. Seek index will be filled. A seek back to
983 * current position is performed. At all, this function refuses work when
984 * stream is not seekable.
985 * \param mh handle
986 * \return MPG123_OK on success
987 *)
988 function mpg123_scan(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
990 (** Return, if possible, the full (expected) length of current track in frames.
991 * \param mh handle
992 * \return length >= 0 or MPG123_ERR if there is no length guess possible.
993 *)
994 function mpg123_framelength(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
996 (** Return, if possible, the full (expected) length of current track in samples.
997 * \param mh handle
998 * \return length >= 0 or MPG123_ERR if there is no length guess possible.
999 *)
1000 function mpg123_length(mh: pmpg123_handle): off_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1002 (** Override the value for file size in bytes.
1003 * Useful for getting sensible track length values in feed mode or for HTTP streams.
1004 * \param mh handle
1005 * \param size file size in bytes
1006 * \return MPG123_OK on success
1007 *)
1008 function mpg123_set_filesize(mh: pmpg123_handle; size: off_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1010 (** Get MPEG frame duration in seconds.
1011 * \param mh handle
1012 * \return frame duration in seconds, <0 on error
1013 *)
1014 function mpg123_tpf(mh: pmpg123_handle): cdouble; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1016 (** Get MPEG frame duration in samples.
1017 * \param mh handle
1018 * \return samples per frame for the most recently parsed frame; <0 on errors
1019 *)
1020 function mpg123_spf(mh: pmpg123_handle): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1022 (** Get and reset the clip count.
1023 * \param mh handle
1024 * \return count of clipped samples
1025 *)
1026 function mpg123_clip(mh: pmpg123_handle): clong; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1028 (** The key values for state information from mpg123_getstate(). *)
1029 type
1031 const
1032 MPG123_ACCURATE = 1; (**< Query if positons are currently accurate (integer value, 0 if false, 1 if true). *)
1033 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. *)
1034 MPG123_FRANKENSTEIN = 3; (**< Stream consists of carelessly stitched together files. Seeking may yield unexpected results (also with MPG123_ACCURATE, it may be confused). *)
1035 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. *)
1037 (** Get various current decoder/stream state information.
1038 * \param mh handle
1039 * \param key the key to identify the information to give.
1040 * \param val the address to return (long) integer values to
1041 * \param fval the address to return floating point values to
1042 * \return MPG123_OK on success
1043 *)
1044 function mpg123_getstate(mh: pmpg123_handle; key: mpg123_state; val: pclong; fval: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1046 (*@}*)
1048 (** \defgroup mpg123_metadata mpg123 metadata handling
1049 *
1050 * Functions to retrieve the metadata from MPEG Audio files and streams.
1051 * Also includes string handling functions.
1052 *
1053 * @{
1054 *)
1056 (** Data structure for storing strings in a safer way than a standard C-String.
1057 * Can also hold a number of null-terminated strings. *)
1058 type
1066 (** Create and allocate memory for a new mpg123_string
1067 * \param sb string handle (address of existing structure on your side)
1068 *)
1069 procedure mpg123_init_string(sb: pmpg123_string); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1071 (** Free-up mempory for an existing mpg123_string
1072 * \param sb string handle
1073 *)
1074 procedure mpg123_free_string(sb: pmpg123_string); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1076 (** Change the size of a mpg123_string
1077 * \param sb string handle
1078 * \param news new size in bytes
1079 * \return 0 on error, 1 on success
1080 *)
1081 function mpg123_resize_string(sb: pmpg123_string; news: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1083 (** Increase size of a mpg123_string if necessary (it may stay larger).
1084 * Note that the functions for adding and setting in current libmpg123
1085 * use this instead of mpg123_resize_string().
1086 * That way, you can preallocate memory and safely work afterwards with
1087 * pieces.
1088 * \param sb string handle
1089 * \param news new minimum size
1090 * \return 0 on error, 1 on success
1091 *)
1092 function mpg123_grow_string(sb: pmpg123_string; news: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1094 (** Copy the contents of one mpg123_string string to another.
1095 * Yes the order of arguments is reversed compated to memcpy().
1096 * \param from string handle
1097 * \param to string handle
1098 * \return 0 on error, 1 on success
1099 *)
1100 function mpg123_copy_string(from: pmpg123_string; _to: pmpg123_string ): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1102 (** Append a C-String to an mpg123_string
1103 * \param sb string handle
1104 * \param stuff to append
1105 * \return 0 on error, 1 on success
1106 *)
1107 function mpg123_add_string(sb: pmpg123_string; const stuff: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1109 (** Append a C-substring to an mpg123 string
1110 * \param sb string handle
1111 * \param stuff content to copy
1112 * \param from offset to copy from
1113 * \param count number of characters to copy (a null-byte is always appended)
1114 * \return 0 on error, 1 on success
1115 *)
1116 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};
1118 (** Set the content of a mpg123_string to a C-string
1119 * \param sb string handle
1120 * \param stuff content to copy
1121 * \return 0 on error, 1 on success
1122 *)
1123 function mpg123_set_string(sb: pmpg123_string; const stuff: pchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1125 (** Set the content of a mpg123_string to a C-substring
1126 * \param sb string handle
1127 * \param stuff the future content
1128 * \param from offset to copy from
1129 * \param count number of characters to copy (a null-byte is always appended)
1130 * \return 0 on error, 1 on success
1131 *)
1132 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};
1134 (** Count characters in a mpg123 string (non-null bytes or UTF-8 characters).
1135 * Even with the fill property, the character count is not obvious as there could be multiple trailing null bytes.
1136 * \param sb string handle
1137 * \param utf8 a flag to tell if the string is in utf8 encoding
1138 * \return character count
1139 *)
1140 function mpg123_strlen(sb: pmpg123_string; utf8: cint): csize_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1142 (** Remove trailing \\r and \\n, if present.
1143 * \param sb string handle
1144 * \return 0 on error, 1 on success
1145 *)
1146 function mpg123_chomp_string(sb: pmpg123_string): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1148 (** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. *)
1149 type
1151 const
1152 mpg123_text_unknown = 0; (**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. *)
1154 mpg123_text_latin1 = 2; (**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. *)
1155 mpg123_text_icy = 3; (**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. *)
1157 mpg123_text_utf16 = 5; (**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
1158 * When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
1159 * you don't mess with the reserved code points. If you want to decode little endian data
1160 * without BOM you need to prepend 0xff 0xfe yourself. *)
1162 mpg123_text_utf16be = 7; (**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
1163 * BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
1164 * One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
1165 * types (we expect a BOM before real data there), not so for utf16be!*)
1168 (** The encoding byte values from ID3v2. *)
1169 type
1171 const
1178 (** Convert ID3 encoding byte to mpg123 encoding index.
1179 * \param id3_enc_byte the ID3 encoding code
1180 * \return the mpg123 encoding index
1181 *)
1182 function mpg123_enc_from_id3(id3_enc_byte: cuchar): mpg123_text_encoding; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1184 (** Store text data in string, after converting to UTF-8 from indicated encoding
1185 * 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).
1186 * Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
1187 * \param sb target string
1188 * \param enc mpg123 text encoding value
1189 * \param source source buffer with plain unsigned bytes (you might need to cast from signed char)
1190 * \param source_size number of bytes in the source buffer
1191 * \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
1192 *)
1193 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};
1195 (** Sub data structure for ID3v2, for storing various text fields (including comments).
1196 * This is for ID3v2 COMM, TXXX and all the other text fields.
1197 * Only COMM and TXXX have a description, only COMM and USLT have a language.
1198 * 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). *)
1199 type
1203 id: array[0..3] of char; (**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). *)
1208 (** The picture type values from ID3v2. *)
1209 type
1211 const
1234 (** Sub data structure for ID3v2, for storing picture data including comment.
1235 * This is for the ID3v2 APIC field. You should consult the ID3v2 specification
1236 * for the use of the APIC field ("frames" in ID3v2 documentation, I use "fields"
1237 * here to separate from MPEG frames). *)
1238 type
1248 (** Data structure for storing IDV3v2 tags.
1249 * This structure is not a direct binary mapping with the file contents.
1250 * The ID3v2 text frames are allowed to contain multiple strings.
1251 * So check for null bytes until you reach the mpg123_string fill.
1252 * All text is encoded in UTF-8. *)
1253 type
1262 genre: pmpg123_string; (**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. *)
1263 comment: pmpg123_string; (**< Pointer to last encountered comment text with empty description. *)
1264 (* Encountered ID3v2 fields are appended to these lists.
1265 There can be multiple occurences, the pointers above always point to the last encountered data. *)
1276 (** Data structure for ID3v1 tags (the last 128 bytes of a file).
1277 * Don't take anything for granted (like string termination)!
1278 * Also note the change ID3v1.1 did: comment[28] = 0; comment[29] = track_number
1279 * It is your task to support ID3v1 only or ID3v1.1 ...*)
1280 type
1293 const
1295 MPG123_NEW_ID3 = $1; (**< 0001 There is ID3 info that changed since last call to mpg123_id3. *)
1297 MPG123_NEW_ICY = $4; (**< 0100 There is ICY info that changed since last call to mpg123_icy. *)
1299 (** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).
1300 * \param mh handle
1301 * \return combination of flags, 0 on error (same as "nothing new")
1302 *)
1303 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. *)
1305 (** Clean up meta data storage (ID3v2 and ICY), freeing memory.
1306 * \param mh handle
1307 *)
1308 procedure mpg123_meta_free(mh: pmpg123_handle); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1310 (** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.
1311 * v1 and/or v2 can be set to NULL when there is no corresponding data.
1312 * \return MPG123_OK on success
1313 *)
1314 function mpg123_id3(mh: pmpg123_handle; v1: ppmpg123_id3v1; v2: ppmpg123_id3v2): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1316 (** Point icy_meta to existing data structure wich may change on any next read/decode function call.
1317 * \param mh handle
1318 * \param icy_meta return address for ICY meta string (set to NULL if nothing there)
1319 * \return MPG123_OK on success
1320 *)
1321 function mpg123_icy(mh: pmpg123_handle; icy_meta: ppchar): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF}; (* same for ICY meta string *)
1323 (** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.
1324 * Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .
1325 * \param icy_text The input data in ICY encoding
1326 * \return pointer to newly allocated buffer with UTF-8 data (You free() it!) *)
1327 function mpg123_icy2utf8(const icy_text: pchar): pchar; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1329 (* @} *)
1331 (** \defgroup mpg123_advpar mpg123 advanced parameter API
1332 *
1333 * Direct access to a parameter set without full handle around it.
1334 * Possible uses:
1335 * - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).
1336 * - Use one set of parameters for multiple handles.
1337 *
1338 * The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()
1339 * family) directly return a fully qualified mpg123 error code, the ones
1340 * operating on full handles normally MPG123_OK or MPG123_ERR, storing the
1341 * specific error code itseld inside the handle.
1342 *
1343 * @{
1344 *)
1346 (** Opaque structure for the libmpg123 decoder parameters. *)
1347 type
1352 (** Opaque structure for the libmpg123 decoder parameters. *)
1353 type
1357 (** Create a handle with preset parameters.
1358 * \param mp parameter handle
1359 * \param decoder decoder choice
1360 * \param error error code return address
1361 * \return mpg123 handle
1362 *)
1363 function mpg123_parnew(mp: pmpg123_pars; const decoder: pchar; error: pcint): pmpg123_handle; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1365 (** Allocate memory for and return a pointer to a new mpg123_pars
1366 * \param error error code return address
1367 * \return new parameter handle
1368 *)
1369 function mpg123_new_pars(error: pcint): pmpg123_pars; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1371 (** Delete and free up memory used by a mpg123_pars data structure
1372 * \param mp parameter handle
1373 *)
1374 procedure mpg123_delete_pars(mp: pmpg123_pars); cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1376 (** Configure mpg123 parameters to accept no output format at all,
1377 * use before specifying supported formats with mpg123_format
1378 * \param mp parameter handle
1379 * \return MPG123_OK on success
1380 *)
1381 function mpg123_fmt_none(mp: pmpg123_pars): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1383 (** Configure mpg123 parameters to accept all formats
1384 * (also any custom rate you may set) -- this is default.
1385 * \param mp parameter handle
1386 * \return MPG123_OK on success
1387 *)
1388 function mpg123_fmt_all(mp: pmpg123_pars): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1390 (** Set the audio format support of a mpg123_pars in detail:
1391 * \param mp parameter handle
1392 * \param rate The sample rate value (in Hertz).
1393 * \param channels A combination of MPG123_STEREO and MPG123_MONO.
1394 * \param encodings A combination of accepted encodings for rate and channels,
1395 * p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no
1396 * support).
1397 * \return MPG123_OK on success
1398 *)
1399 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 *)
1401 (** Check to see if a specific format at a specific rate is supported
1402 * by mpg123_pars.
1403 * \param mp parameter handle
1404 * \param rate sampling rate
1405 * \param encoding encoding
1406 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
1407 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. *)
1408 function mpg123_fmt_support(mp: pmpg123_pars; rate: clong; encoding: cint): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1410 (** Set a specific parameter, for a specific mpg123_pars, using a parameter
1411 * type key chosen from the mpg123_parms enumeration, to the specified value.
1412 * \param mp parameter handle
1413 * \param type parameter choice
1414 * \param value integer value
1415 * \param fvalue floating point value
1416 * \return MPG123_OK on success
1417 *)
1418 function mpg123_par(mp: pmpg123_pars; _type: mpg123_parms; value: clong; fvalue: cdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1420 (** Get a specific parameter, for a specific mpg123_pars.
1421 * See the mpg123_parms enumeration for a list of available parameters.
1422 * \param mp parameter handle
1423 * \param type parameter choice
1424 * \param value integer value return address
1425 * \param fvalue floating point value return address
1426 * \return MPG123_OK on success
1427 *)
1428 function mpg123_getpar(mp: pmpg123_pars; _type: mpg123_parms; val: pclong; fval: pcdouble): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1430 (* @} *)
1433 (** \defgroup mpg123_lowio mpg123 low level I/O
1434 * 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...
1435 *
1436 * @{ *)
1438 (** Replace default internal buffer with user-supplied buffer.
1439 * Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio.
1440 * Note that the required buffer size could be bigger than expected from output
1441 * encoding if libmpg123 has to convert from primary decoder output (p.ex. 32 bit
1442 * storage for 24 bit output).
1443 * \param mh handle
1444 * \param data pointer to user buffer
1445 * \param size of buffer in bytes
1446 * \return MPG123_OK on success
1447 *)
1448 function mpg123_replace_buffer(mh: pmpg123_handle; data: pcuchar; size: csize_t): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1450 (** The max size of one frame's decoded output with current settings.
1451 * Use that to determine an appropriate minimum buffer size for decoding one frame.
1452 * \param mh handle
1453 * \return maximum decoded data size in bytes
1454 *)
1455 function mpg123_outblock(mh: pmpg123_handle): csize_t; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1457 (** Replace low-level stream access functions; read and lseek as known in POSIX.
1458 * You can use this to make any fancy file opening/closing yourself,
1459 * using mpg123_open_fd() to set the file descriptor for your read/lseek
1460 * (doesn't need to be a "real" file descriptor...).
1461 * Setting a function to NULL means that the default internal read is
1462 * used (active from next mpg123_open call on).
1463 * Note: As it would be troublesome to mess with this while having a file open,
1464 * this implies mpg123_close().
1465 * \param mh handle
1466 * \param r_read callback for reading (behaviour like POSIX read)
1467 * \param r_lseek callback for seeking (like POSIX lseek)
1468 * \return MPG123_OK on success
1469 *)
1470 type
1474 function mpg123_replace_reader(mh: pmpg123_handle; r_read: mpg123_readproc; r_lseek: mpg123_seekproc): cint; cdecl; external {$IFDEF MPG123_DYNAMIC}LIB_MPG123{$ENDIF};
1476 (** Replace I/O functions with your own ones operating on some kind of
1477 * handle instead of integer descriptors.
1478 * The handle is a void pointer, so you can pass any data you want...
1479 * mpg123_open_handle() is the call you make to use the I/O defined here.
1480 * There is no fallback to internal read/seek here.
1481 * Note: As it would be troublesome to mess with this while having a file open,
1482 * this mpg123_close() is implied here.
1483 * \param mh handle
1484 * \param r_read callback for reading (behaviour like POSIX read)
1485 * \param r_lseek callback for seeking (like POSIX lseek)
1486 * \param cleanup A callback to clean up an I/O handle on mpg123_close,
1487 * can be NULL for none (you take care of cleaning your handles).
1488 * \return MPG123_OK on success
1489 *)
1490 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};
1492 (* @} *)
1494 implementation