revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / diskimage / include / mpg123.h
blob03cf91973e63739f4ac9206f6a9909ac61a4d418
1 /*
2 libmpg123: MPEG Audio Decoder library (version 1.13.4)
4 copyright 1995-2010 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6 */
8 #ifndef MPG123_LIB_H
9 #define MPG123_LIB_H
11 /** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder */
13 /* A macro to check at compile time which set of API functions to expect.
14 This should be incremented at least each time a new symbol is added to the header. */
15 #define MPG123_API_VERSION 29
17 /* These aren't actually in use... seems to work without using libtool. */
18 #ifdef BUILD_MPG123_DLL
19 /* The dll exports. */
20 #define EXPORT __declspec(dllexport)
21 #else
22 #ifdef LINK_MPG123_DLL
23 /* The exe imports. */
24 #define EXPORT __declspec(dllimport)
25 #else
26 /* Nothing on normal/UNIX builds */
27 #define EXPORT
28 #endif
29 #endif
31 #ifndef MPG123_NO_CONFIGURE /* Enable use of this file without configure. */
32 #include <stdlib.h>
33 #include <sys/types.h>
35 /* Simplified large file handling.
36 I used to have a check here that prevents building for a library with conflicting large file setup
37 (application that uses 32 bit offsets with library that uses 64 bits).
38 While that was perfectly fine in an environment where there is one incarnation of the library,
39 it hurt GNU/Linux and Solaris systems with multilib where the distribution fails to provide the
40 correct header matching the 32 bit library (where large files need explicit support) or
41 the 64 bit library (where there is no distinction).
43 New approach: When the app defines _FILE_OFFSET_BITS, it wants non-default large file support,
44 and thus functions with added suffix (mpg123_open_64).
45 Any mismatch will be caught at link time because of the _FILE_OFFSET_BITS setting used when
46 building libmpg123. Plus, there's dual mode large file support in mpg123 since 1.12 now.
47 Link failure is not the expected outcome of any half-sane usage anymore.
49 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.
53 Now, the renaming of large file aware functions.
54 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.
56 #if (!defined MPG123_NO_LARGENAME) && ((defined _FILE_OFFSET_BITS) || (defined MPG123_LARGESUFFIX))
58 /* Need some trickery to concatenate the value(s) of the given macro(s). */
59 #define MPG123_MACROCAT_REALLY(a, b) a ## b
60 #define MPG123_MACROCAT(a, b) MPG123_MACROCAT_REALLY(a, b)
61 #ifndef MPG123_LARGESUFFIX
62 #define MPG123_LARGESUFFIX MPG123_MACROCAT(_, _FILE_OFFSET_BITS)
63 #endif
64 #define MPG123_LARGENAME(func) MPG123_MACROCAT(func, MPG123_LARGESUFFIX)
66 #define mpg123_open MPG123_LARGENAME(mpg123_open)
67 #define mpg123_open_fd MPG123_LARGENAME(mpg123_open_fd)
68 #define mpg123_open_handle MPG123_LARGENAME(mpg123_open_handle)
69 #define mpg123_framebyframe_decode MPG123_LARGENAME(mpg123_framebyframe_decode)
70 #define mpg123_decode_frame MPG123_LARGENAME(mpg123_decode_frame)
71 #define mpg123_tell MPG123_LARGENAME(mpg123_tell)
72 #define mpg123_tellframe MPG123_LARGENAME(mpg123_tellframe)
73 #define mpg123_tell_stream MPG123_LARGENAME(mpg123_tell_stream)
74 #define mpg123_seek MPG123_LARGENAME(mpg123_seek)
75 #define mpg123_feedseek MPG123_LARGENAME(mpg123_feedseek)
76 #define mpg123_seek_frame MPG123_LARGENAME(mpg123_seek_frame)
77 #define mpg123_timeframe MPG123_LARGENAME(mpg123_timeframe)
78 #define mpg123_index MPG123_LARGENAME(mpg123_index)
79 #define mpg123_set_index MPG123_LARGENAME(mpg123_set_index)
80 #define mpg123_position MPG123_LARGENAME(mpg123_position)
81 #define mpg123_length MPG123_LARGENAME(mpg123_length)
82 #define mpg123_set_filesize MPG123_LARGENAME(mpg123_set_filesize)
83 #define mpg123_replace_reader MPG123_LARGENAME(mpg123_replace_reader)
84 #define mpg123_replace_reader_handle MPG123_LARGENAME(mpg123_replace_reader_handle)
86 #endif /* largefile hackery */
88 #endif /* MPG123_NO_CONFIGURE */
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
94 /** \defgroup mpg123_init mpg123 library and handle setup
96 * Functions to initialise and shutdown the mpg123 library and handles.
97 * The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)
98 * Tip: Use a RVA setting...
100 * @{
103 /** Opaque structure for the libmpg123 decoder handle. */
104 struct mpg123_handle_struct;
106 /** Opaque structure for the libmpg123 decoder handle.
107 * Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.
109 typedef struct mpg123_handle_struct mpg123_handle;
111 /** Function to initialise the mpg123 library.
112 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library.
114 * \return MPG123_OK if successful, otherwise an error number.
116 EXPORT int mpg123_init(void);
118 /** Function to close down the mpg123 library.
119 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. */
120 EXPORT void mpg123_exit(void);
122 /** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).
123 * and optional retrieval of an error code to feed to mpg123_plain_strerror().
124 * Optional means: Any of or both the parameters may be NULL.
126 * \return Non-NULL pointer when successful.
128 EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error);
130 /** Delete handle, mh is either a valid mpg123 handle or NULL. */
131 EXPORT void mpg123_delete(mpg123_handle *mh);
133 /** Enumeration of the parameters types that it is possible to set/get. */
134 enum mpg123_parms
136 MPG123_VERBOSE, /**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) */
137 MPG123_FLAGS, /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) */
138 MPG123_ADD_FLAGS, /**< add some flags (integer) */
139 MPG123_FORCE_RATE, /**< when value > 0, force output rate to that value (integer) */
140 MPG123_DOWN_SAMPLE, /**< 0=native rate, 1=half rate, 2=quarter rate (integer) */
141 MPG123_RVA, /**< one of the RVA choices above (integer) */
142 MPG123_DOWNSPEED, /**< play a frame N times (integer) */
143 MPG123_UPSPEED, /**< play every Nth frame (integer) */
144 MPG123_START_FRAME, /**< start with this frame (skip frames before that, integer) */
145 MPG123_DECODE_FRAMES, /**< decode only this number of frames (integer) */
146 MPG123_ICY_INTERVAL, /**< stream contains ICY metadata with this interval (integer) */
147 MPG123_OUTSCALE, /**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) */
148 MPG123_TIMEOUT, /**< timeout for reading from a stream (not supported on win32, integer) */
149 MPG123_REMOVE_FLAGS, /**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) */
150 MPG123_RESYNC_LIMIT, /**< Try resync on frame parsing for that many bytes or until end of stream (<0 ... integer). */
151 MPG123_INDEX_SIZE /**< 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. */
152 ,MPG123_PREFRAMES /**< 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.*/
155 /** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */
156 enum mpg123_param_flags
158 MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */
159 ,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */
160 ,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */
161 ,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */
162 ,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */
163 ,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */
164 ,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */
165 ,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */
166 ,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */
167 ,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */
168 ,MPG123_FUZZY = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */
169 ,MPG123_FORCE_FLOAT = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */
170 ,MPG123_PLAIN_ID3TEXT = 0x800 /**< 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. */
171 ,MPG123_IGNORE_STREAMLENGTH = 0x1000 /**< 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 */
172 ,MPG123_SKIP_ID3V2 = 0x2000 /**< 10 0000 0000 0000 Do not parse ID3v2 tags, just skip them. */
175 /** choices for MPG123_RVA */
176 enum mpg123_param_rva
178 MPG123_RVA_OFF = 0 /**< RVA disabled (default). */
179 ,MPG123_RVA_MIX = 1 /**< Use mix/track/radio gain. */
180 ,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */
181 ,MPG123_RVA_MAX = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */
184 /* TODO: Assess the possibilities and troubles of changing parameters during playback. */
186 /** Set a specific parameter, for a specific mpg123_handle, using a parameter
187 * type key chosen from the mpg123_parms enumeration, to the specified value. */
188 EXPORT int mpg123_param(mpg123_handle *mh, enum mpg123_parms type, long value, double fvalue);
190 /** Get a specific parameter, for a specific mpg123_handle.
191 * See the mpg123_parms enumeration for a list of available parameters. */
192 EXPORT int mpg123_getparam(mpg123_handle *mh, enum mpg123_parms type, long *val, double *fval);
194 /** Feature set available for query with mpg123_feature. */
195 enum mpg123_feature_set
197 MPG123_FEATURE_ABI_UTF8OPEN = 0 /**< mpg123 expects path names to be given in UTF-8 encoding instead of plain native. */
198 ,MPG123_FEATURE_OUTPUT_8BIT /**< 8bit output */
199 ,MPG123_FEATURE_OUTPUT_16BIT /**< 16bit output */
200 ,MPG123_FEATURE_OUTPUT_32BIT /**< 32bit output */
201 ,MPG123_FEATURE_INDEX /**< support for building a frame index for accurate seeking */
202 ,MPG123_FEATURE_PARSE_ID3V2 /**< id3v2 parsing */
203 ,MPG123_FEATURE_DECODE_LAYER1 /**< mpeg layer-1 decoder enabled */
204 ,MPG123_FEATURE_DECODE_LAYER2 /**< mpeg layer-2 decoder enabled */
205 ,MPG123_FEATURE_DECODE_LAYER3 /**< mpeg layer-3 decoder enabled */
206 ,MPG123_FEATURE_DECODE_ACCURATE /**< accurate decoder rounding */
207 ,MPG123_FEATURE_DECODE_DOWNSAMPLE /**< downsample (sample omit) */
208 ,MPG123_FEATURE_DECODE_NTOM /**< flexible rate decoding */
209 ,MPG123_FEATURE_PARSE_ICY /**< ICY support */
210 ,MPG123_FEATURE_TIMEOUT_READ /**< Reader with timeout (network). */
213 /** Query libmpg123 feature, 1 for success, 0 for unimplemented functions. */
214 EXPORT int mpg123_feature(const enum mpg123_feature_set key);
216 /* @} */
219 /** \defgroup mpg123_error mpg123 error handling
221 * Functions to get text version of the error numbers and an enumeration
222 * of the error codes returned by libmpg123.
224 * Most functions operating on a mpg123_handle simply return MPG123_OK on success and MPG123_ERR on failure (setting the internal error variable of the handle to the specific error code).
225 * 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!).
226 * The positive range of return values is used for "useful" values when appropriate.
228 * @{
231 /** Enumeration of the message and error codes and returned by libmpg123 functions. */
232 enum mpg123_errors
234 MPG123_DONE=-12, /**< Message: Track ended. Stop decoding. */
235 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. */
236 MPG123_NEED_MORE=-10, /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */
237 MPG123_ERR=-1, /**< Generic Error */
238 MPG123_OK=0, /**< Success */
239 MPG123_BAD_OUTFORMAT, /**< Unable to set up output format! */
240 MPG123_BAD_CHANNEL, /**< Invalid channel number specified. */
241 MPG123_BAD_RATE, /**< Invalid sample rate specified. */
242 MPG123_ERR_16TO8TABLE, /**< Unable to allocate memory for 16 to 8 converter table! */
243 MPG123_BAD_PARAM, /**< Bad parameter id! */
244 MPG123_BAD_BUFFER, /**< Bad buffer given -- invalid pointer or too small size. */
245 MPG123_OUT_OF_MEM, /**< Out of memory -- some malloc() failed. */
246 MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */
247 MPG123_BAD_DECODER, /**< Invalid decoder choice. */
248 MPG123_BAD_HANDLE, /**< Invalid mpg123 handle. */
249 MPG123_NO_BUFFERS, /**< Unable to initialize frame buffers (out of memory?). */
250 MPG123_BAD_RVA, /**< Invalid RVA mode. */
251 MPG123_NO_GAPLESS, /**< This build doesn't support gapless decoding. */
252 MPG123_NO_SPACE, /**< Not enough buffer space. */
253 MPG123_BAD_TYPES, /**< Incompatible numeric data types. */
254 MPG123_BAD_BAND, /**< Bad equalizer band. */
255 MPG123_ERR_NULL, /**< Null pointer given where valid storage address needed. */
256 MPG123_ERR_READER, /**< Error reading the stream. */
257 MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */
258 MPG123_BAD_WHENCE, /**< Invalid 'whence' for seek function.*/
259 MPG123_NO_TIMEOUT, /**< Build does not support stream timeouts. */
260 MPG123_BAD_FILE, /**< File access error. */
261 MPG123_NO_SEEK, /**< Seek not supported by stream. */
262 MPG123_NO_READER, /**< No stream opened. */
263 MPG123_BAD_PARS, /**< Bad parameter handle. */
264 MPG123_BAD_INDEX_PAR, /**< Bad parameters to mpg123_index() and mpg123_set_index() */
265 MPG123_OUT_OF_SYNC, /**< Lost track in bytestream and did not try to resync. */
266 MPG123_RESYNC_FAIL, /**< Resync failed to find valid MPEG data. */
267 MPG123_NO_8BIT, /**< No 8bit encoding possible. */
268 MPG123_BAD_ALIGN, /**< Stack aligmnent error */
269 MPG123_NULL_BUFFER, /**< NULL input buffer with non-zero size... */
270 MPG123_NO_RELSEEK, /**< Relative seek not possible (screwed up file offset) */
271 MPG123_NULL_POINTER, /**< You gave a null pointer somewhere where you shouldn't have. */
272 MPG123_BAD_KEY, /**< Bad key value given. */
273 MPG123_NO_INDEX, /**< No frame index in this build. */
274 MPG123_INDEX_FAIL, /**< Something with frame index went wrong. */
275 MPG123_BAD_DECODER_SETUP, /**< Something prevents a proper decoder setup */
276 MPG123_MISSING_FEATURE /**< This feature has not been built into libmpg123. */
277 ,MPG123_BAD_VALUE /**< A bad value has been given, somewhere. */
278 ,MPG123_LSEEK_FAILED /**< Low-level seek failed. */
279 ,MPG123_BAD_CUSTOM_IO /**< Custom I/O not prepared. */
280 ,MPG123_LFS_OVERFLOW /**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. */
283 /** Return a string describing that error errcode means. */
284 EXPORT const char* mpg123_plain_strerror(int errcode);
286 /** Give string describing what error has occured in the context of handle mh.
287 * When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via
288 * char *errmsg = mpg123_strerror(mh)
289 * This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE. */
290 EXPORT const char* mpg123_strerror(mpg123_handle *mh);
292 /** Return the plain errcode intead of a string. */
293 EXPORT int mpg123_errcode(mpg123_handle *mh);
295 /*@}*/
298 /** \defgroup mpg123_decoder mpg123 decoder selection
300 * Functions to list and select the available decoders.
301 * Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).
303 * @{
306 /** Return a NULL-terminated array of generally available decoder names (plain 8bit ASCII). */
307 EXPORT const char **mpg123_decoders(void);
309 /** Return a NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII). */
310 EXPORT const char **mpg123_supported_decoders(void);
312 /** Set the chosen decoder to 'decoder_name' */
313 EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name);
315 /** Get the currently active decoder engine name.
316 The active decoder engine can vary depening on output constraints,
317 mostly non-resampling, integer output is accelerated via 3DNow & Co. but for other modes a fallback engine kicks in.
318 Note that this can return a decoder that is ony active in the hidden and not available as decoder choice from the outside.
319 \return The decoder name or NULL on error. */
320 EXPORT const char* mpg123_current_decoder(mpg123_handle *mh);
322 /*@}*/
325 /** \defgroup mpg123_output mpg123 output audio format
327 * Functions to get and select the format of the decoded audio.
329 * @{
332 /** An enum over all sample types possibly known to mpg123.
333 * The values are designed as bit flags to allow bitmasking for encoding families.
335 * Note that (your build of) libmpg123 does not necessarily support all these.
336 * Usually, you can expect the 8bit encodings and signed 16 bit.
337 * Also 32bit float will be usual beginning with mpg123-1.7.0 .
338 * What you should bear in mind is that (SSE, etc) optimized routines may be absent
339 * for some formats. We do have SSE for 16, 32 bit and float, though.
340 * 24 bit integer is done via postprocessing of 32 bit output -- just cutting
341 * the last byte, no rounding, even. If you want better, do it yourself.
343 * All formats are in native byte order. If you need different endinaness, you
344 * can simply postprocess the output buffers (libmpg123 wouldn't do anything else).
345 * mpg123_encsize() can be helpful there.
347 enum mpg123_enc_enum
349 MPG123_ENC_8 = 0x00f /**< 0000 0000 1111 Some 8 bit integer encoding. */
350 ,MPG123_ENC_16 = 0x040 /**< 0000 0100 0000 Some 16 bit integer encoding. */
351 ,MPG123_ENC_24 = 0x4000 /**< 0100 0000 0000 0000 Some 24 bit integer encoding. */
352 ,MPG123_ENC_32 = 0x100 /**< 0001 0000 0000 Some 32 bit integer encoding. */
353 ,MPG123_ENC_SIGNED = 0x080 /**< 0000 1000 0000 Some signed integer encoding. */
354 ,MPG123_ENC_FLOAT = 0xe00 /**< 1110 0000 0000 Some float encoding. */
355 ,MPG123_ENC_SIGNED_16 = (MPG123_ENC_16|MPG123_ENC_SIGNED|0x10) /**< 1101 0000 signed 16 bit */
356 ,MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16|0x20) /**< 0110 0000 unsigned 16 bit */
357 ,MPG123_ENC_UNSIGNED_8 = 0x01 /**< 0000 0001 unsigned 8 bit */
358 ,MPG123_ENC_SIGNED_8 = (MPG123_ENC_SIGNED|0x02) /**< 1000 0010 signed 8 bit */
359 ,MPG123_ENC_ULAW_8 = 0x04 /**< 0000 0100 ulaw 8 bit */
360 ,MPG123_ENC_ALAW_8 = 0x08 /**< 0000 1000 alaw 8 bit */
361 ,MPG123_ENC_SIGNED_32 = MPG123_ENC_32|MPG123_ENC_SIGNED|0x1000 /**< 0001 0001 1000 0000 signed 32 bit */
362 ,MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32|0x2000 /**< 0010 0001 0000 0000 unsigned 32 bit */
363 ,MPG123_ENC_SIGNED_24 = MPG123_ENC_24|MPG123_ENC_SIGNED|0x1000 /**< 0101 0000 1000 0000 signed 24 bit */
364 ,MPG123_ENC_UNSIGNED_24 = MPG123_ENC_24|0x2000 /**< 0110 0000 0000 0000 unsigned 24 bit */
365 ,MPG123_ENC_FLOAT_32 = 0x200 /**< 0010 0000 0000 32bit float */
366 ,MPG123_ENC_FLOAT_64 = 0x400 /**< 0100 0000 0000 64bit float */
367 ,MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16 | MPG123_ENC_UNSIGNED_16 | MPG123_ENC_UNSIGNED_8
368 | MPG123_ENC_SIGNED_8 | MPG123_ENC_ULAW_8 | MPG123_ENC_ALAW_8
369 | MPG123_ENC_SIGNED_32 | MPG123_ENC_UNSIGNED_32
370 | MPG123_ENC_SIGNED_24 | MPG123_ENC_UNSIGNED_24
371 | MPG123_ENC_FLOAT_32 | MPG123_ENC_FLOAT_64 ) /**< Any encoding on the list. */
374 /** They can be combined into one number (3) to indicate mono and stereo... */
375 enum mpg123_channelcount
377 MPG123_MONO = 1
378 ,MPG123_STEREO = 2
381 /** An array of supported standard sample rates
382 * These are possible native sample rates of MPEG audio files.
383 * You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings.
384 * \param list Store a pointer to the sample rates array there.
385 * \param number Store the number of sample rates there. */
386 EXPORT void mpg123_rates(const long **list, size_t *number);
388 /** An array of supported audio encodings.
389 * An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).
390 * \param list Store a pointer to the encodings array there.
391 * \param number Store the number of encodings there. */
392 EXPORT void mpg123_encodings(const int **list, size_t *number);
394 /** Return the size (in bytes) of one mono sample of the named encoding.
395 * \param encoding The encoding value to analyze.
396 * \return positive size of encoding in bytes, 0 on invalid encoding. */
397 EXPORT int mpg123_encsize(int encoding);
399 /** Configure a mpg123 handle to accept no output format at all,
400 * use before specifying supported formats with mpg123_format */
401 EXPORT int mpg123_format_none(mpg123_handle *mh);
403 /** Configure mpg123 handle to accept all formats
404 * (also any custom rate you may set) -- this is default. */
405 EXPORT int mpg123_format_all(mpg123_handle *mh);
407 /** Set the audio format support of a mpg123_handle in detail:
408 * \param mh audio decoder handle
409 * \param rate The sample rate value (in Hertz).
410 * \param channels A combination of MPG123_STEREO and MPG123_MONO.
411 * \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.
412 * \return MPG123_OK on success, MPG123_ERR if there was an error. */
413 EXPORT int mpg123_format(mpg123_handle *mh, long rate, int channels, int encodings);
415 /** Check to see if a specific format at a specific rate is supported
416 * by mpg123_handle.
417 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
418 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
419 EXPORT int mpg123_format_support(mpg123_handle *mh, long rate, int encoding);
421 /** Get the current output format written to the addresses givenr. */
422 EXPORT int mpg123_getformat(mpg123_handle *mh, long *rate, int *channels, int *encoding);
424 /*@}*/
427 /** \defgroup mpg123_input mpg123 file input and decoding
429 * Functions for input bitstream and decoding operations.
430 * 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!).
431 * @{
434 /* reading samples / triggering decoding, possible return values: */
435 /** Enumeration of the error codes returned by libmpg123 functions. */
437 /** Open and prepare to decode the specified file by filesystem path.
438 * This does not open HTTP urls; libmpg123 contains no networking code.
439 * If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().
441 EXPORT int mpg123_open(mpg123_handle *mh, const char *path);
443 /** Use an already opened file descriptor as the bitstream input
444 * mpg123_close() will _not_ close the file descriptor.
446 EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd);
448 /** Use an opaque handle as bitstream input. This works only with the
449 * replaced I/O from mpg123_replace_reader_handle()!
450 * mpg123_close() will call the cleanup callback for your handle (if you gave one).
452 EXPORT int mpg123_open_handle(mpg123_handle *mh, void *iohandle);
454 /** Open a new bitstream and prepare for direct feeding
455 * This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.
457 EXPORT int mpg123_open_feed(mpg123_handle *mh);
459 /** Closes the source, if libmpg123 opened it. */
460 EXPORT int mpg123_close(mpg123_handle *mh);
462 /** Read from stream and decode up to outmemsize bytes.
463 * \param outmemory address of output buffer to write to
464 * \param outmemsize maximum number of bytes to write
465 * \param done address to store the number of actually decoded bytes to
466 * \return error/message code (watch out for MPG123_DONE and friends!) */
467 EXPORT int mpg123_read(mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done);
469 /** Feed data for a stream that has been opened with mpg123_open_feed().
470 * It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.
471 * \param in input buffer
472 * \param size number of input bytes
473 * \return error/message code. */
474 EXPORT int mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size);
476 /** Decode MPEG Audio from inmemory to outmemory.
477 * This is very close to a drop-in replacement for old mpglib.
478 * When you give zero-sized output buffer the input will be parsed until
479 * decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)
480 * without taking decoded data.
481 * Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).
482 * You can actually always decide if you want those specialized functions in separate steps or one call this one here.
483 * \param inmemory input buffer
484 * \param inmemsize number of input bytes
485 * \param outmemory output buffer
486 * \param outmemsize maximum number of output bytes
487 * \param done address to store the number of actually decoded bytes to
488 * \return error/message code (watch out especially for MPG123_NEED_MORE)
490 EXPORT int mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize, unsigned char *outmemory, size_t outmemsize, size_t *done);
492 /** Decode next MPEG frame to internal buffer
493 * or read a frame and return after setting a new format.
494 * \param num current frame offset gets stored there
495 * \param audio This pointer is set to the internal buffer to read the decoded audio from.
496 * \param bytes number of output bytes ready in the buffer
498 EXPORT int mpg123_decode_frame(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes);
500 /** Decode current MPEG frame to internal buffer.
501 * Warning: This is experimental API that might change in future releases!
502 * Please watch mpg123 development closely when using it.
503 * \param num last frame offset gets stored there
504 * \param audio this pointer is set to the internal buffer to read the decoded audio from.
505 * \param bytes number of output bytes ready in the buffer
507 EXPORT int mpg123_framebyframe_decode(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes);
509 /** Find, read and parse the next mp3 frame
510 * Warning: This is experimental API that might change in future releases!
511 * Please watch mpg123 development closely when using it.
513 EXPORT int mpg123_framebyframe_next(mpg123_handle *mh);
515 /*@}*/
518 /** \defgroup mpg123_seek mpg123 position and seeking
520 * Functions querying and manipulating position in the decoded audio bitstream.
521 * The position is measured in decoded audio samples, or MPEG frame offset for the specific functions.
522 * 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;-)
523 * The general usage is modelled after stdlib's ftell() and fseek().
524 * 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:
525 * - SEEK_SET: set position to (or near to) specified offset
526 * - SEEK_CUR: change position by offset from now
527 * - SEEK_END: set position to offset from end
529 * Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise.
530 * 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)!
531 * Short: When you care about the sample position, don't mess with those parameters;-)
532 * Also, seeking is not guaranteed to work for all streams (underlying stream may not support it).
534 * @{
537 /** Returns the current position in samples.
538 * On the next read, you'd get that sample. */
539 EXPORT off_t mpg123_tell(mpg123_handle *mh);
541 /** Returns the frame number that the next read will give you data from. */
542 EXPORT off_t mpg123_tellframe(mpg123_handle *mh);
544 /** Returns the current byte offset in the input stream. */
545 EXPORT off_t mpg123_tell_stream(mpg123_handle *mh);
547 /** Seek to a desired sample offset.
548 * Set whence to SEEK_SET, SEEK_CUR or SEEK_END.
549 * \return The resulting offset >= 0 or error/message code */
550 EXPORT off_t mpg123_seek(mpg123_handle *mh, off_t sampleoff, int whence);
552 /** Seek to a desired sample offset in data feeding mode.
553 * 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.
554 * \param input_offset The position it expects to be at the
555 * next time data is fed to mpg123_decode().
556 * \return The resulting offset >= 0 or error/message code */
557 EXPORT off_t mpg123_feedseek(mpg123_handle *mh, off_t sampleoff, int whence, off_t *input_offset);
559 /** Seek to a desired MPEG frame index.
560 * Set whence to SEEK_SET, SEEK_CUR or SEEK_END.
561 * \return The resulting offset >= 0 or error/message code */
562 EXPORT off_t mpg123_seek_frame(mpg123_handle *mh, off_t frameoff, int whence);
564 /** Return a MPEG frame offset corresponding to an offset in seconds.
565 * 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.
566 * \return frame offset >= 0 or error/message code */
567 EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec);
569 /** Give access to the frame index table that is managed for seeking.
570 * You are asked not to modify the values... Use mpg123_set_index to set the
571 * seek index
572 * \param offsets pointer to the index array
573 * \param step one index byte offset advances this many MPEG frames
574 * \param fill number of recorded index offsets; size of the array */
575 EXPORT int mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill);
577 /** Set the frame index table
578 * Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets
579 * to NULL and fill to 0 will clear the index and free the allocated memory used by the index.
580 * \param offsets pointer to the index array
581 * \param step one index byte offset advances this many MPEG frames
582 * \param fill number of recorded index offsets; size of the array */
583 EXPORT int mpg123_set_index(mpg123_handle *mh, off_t *offsets, off_t step, size_t fill);
585 /** Get information about current and remaining frames/seconds.
586 * WARNING: This function is there because of special usage by standalone mpg123 and may be removed in the final version of libmpg123!
587 * You provide an offset (in frames) from now and a number of output bytes
588 * served by libmpg123 but not yet played. You get the projected current frame
589 * and seconds, as well as the remaining frames/seconds. This does _not_ care
590 * about skipped samples due to gapless playback. */
591 EXPORT int mpg123_position( mpg123_handle *mh, off_t frame_offset, off_t buffered_bytes, off_t *current_frame, off_t *frames_left, double *current_seconds, double *seconds_left);
593 /*@}*/
596 /** \defgroup mpg123_voleq mpg123 volume and equalizer
598 * @{
601 enum mpg123_channels
603 MPG123_LEFT=0x1 /**< The Left Channel. */
604 ,MPG123_RIGHT=0x2 /**< The Right Channel. */
605 ,MPG123_LR=0x3 /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */
608 /** Set the 32 Band Audio Equalizer settings.
609 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both.
610 * \param band The equaliser band to change (from 0 to 31)
611 * \param val The (linear) adjustment factor. */
612 EXPORT int mpg123_eq(mpg123_handle *mh, enum mpg123_channels channel, int band, double val);
614 /** Get the 32 Band Audio Equalizer settings.
615 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
616 * \param band The equaliser band to change (from 0 to 31)
617 * \return The (linear) adjustment factor. */
618 EXPORT double mpg123_geteq(mpg123_handle *mh, enum mpg123_channels channel, int band);
620 /** Reset the 32 Band Audio Equalizer settings to flat */
621 EXPORT int mpg123_reset_eq(mpg123_handle *mh);
623 /** Set the absolute output volume including the RVA setting,
624 * vol<0 just applies (a possibly changed) RVA setting. */
625 EXPORT int mpg123_volume(mpg123_handle *mh, double vol);
627 /** Adjust output volume including the RVA setting by chosen amount */
628 EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);
630 /** Return current volume setting, the actual value due to RVA, and the RVA
631 * adjustment itself. It's all as double float value to abstract the sample
632 * format. The volume values are linear factors / amplitudes (not percent)
633 * and the RVA value is in decibels. */
634 EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db);
636 /* TODO: Set some preamp in addition / to replace internal RVA handling? */
638 /*@}*/
641 /** \defgroup mpg123_status mpg123 status and information
643 * @{
646 /** Enumeration of the mode types of Variable Bitrate */
647 enum mpg123_vbr {
648 MPG123_CBR=0, /**< Constant Bitrate Mode (default) */
649 MPG123_VBR, /**< Variable Bitrate Mode */
650 MPG123_ABR /**< Average Bitrate Mode */
653 /** Enumeration of the MPEG Versions */
654 enum mpg123_version {
655 MPG123_1_0=0, /**< MPEG Version 1.0 */
656 MPG123_2_0, /**< MPEG Version 2.0 */
657 MPG123_2_5 /**< MPEG Version 2.5 */
661 /** Enumeration of the MPEG Audio mode.
662 * Only the mono mode has 1 channel, the others have 2 channels. */
663 enum mpg123_mode {
664 MPG123_M_STEREO=0, /**< Standard Stereo. */
665 MPG123_M_JOINT, /**< Joint Stereo. */
666 MPG123_M_DUAL, /**< Dual Channel. */
667 MPG123_M_MONO /**< Single Channel. */
671 /** Enumeration of the MPEG Audio flag bits */
672 enum mpg123_flags {
673 MPG123_CRC=0x1, /**< The bitstream is error protected using 16-bit CRC. */
674 MPG123_COPYRIGHT=0x2, /**< The bitstream is copyrighted. */
675 MPG123_PRIVATE=0x4, /**< The private bit has been set. */
676 MPG123_ORIGINAL=0x8 /**< The bitstream is an original, not a copy. */
679 /** Data structure for storing information about a frame of MPEG Audio */
680 struct mpg123_frameinfo
682 enum mpg123_version version; /**< The MPEG version (1.0/2.0/2.5). */
683 int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */
684 long rate; /**< The sampling rate in Hz. */
685 enum mpg123_mode mode; /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */
686 int mode_ext; /**< The mode extension bit flag. */
687 int framesize; /**< The size of the frame (in bytes). */
688 enum mpg123_flags flags; /**< 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. */
689 int emphasis; /**< The emphasis type. */
690 int bitrate; /**< Bitrate of the frame (kbps). */
691 int abr_rate; /**< The target average bitrate. */
692 enum mpg123_vbr vbr; /**< The VBR mode. */
695 /** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure. */
696 EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);
698 /** Get the safe output buffer size for all cases (when you want to replace the internal buffer) */
699 EXPORT size_t mpg123_safe_buffer(void);
701 /** Make a full parsing scan of each frame in the file. ID3 tags are found. An accurate length
702 * value is stored. Seek index will be filled. A seek back to current position
703 * is performed. At all, this function refuses work when stream is
704 * not seekable.
705 * \return MPG123_OK or MPG123_ERR.
707 EXPORT int mpg123_scan(mpg123_handle *mh);
709 /** Return, if possible, the full (expected) length of current track in samples.
710 * \return length >= 0 or MPG123_ERR if there is no length guess possible. */
711 EXPORT off_t mpg123_length(mpg123_handle *mh);
713 /** Override the value for file size in bytes.
714 * Useful for getting sensible track length values in feed mode or for HTTP streams.
715 * \return MPG123_OK or MPG123_ERR */
716 EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size);
718 /** Returns the time (seconds) per frame; <0 is error. */
719 EXPORT double mpg123_tpf(mpg123_handle *mh);
721 /** Get and reset the clip count. */
722 EXPORT long mpg123_clip(mpg123_handle *mh);
725 /** The key values for state information from mpg123_getstate(). */
726 enum mpg123_state
728 MPG123_ACCURATE = 1 /**< Query if positons are currently accurate (integer value, 0 if false, 1 if true) */
731 /** Get various current decoder/stream state information.
732 * \param key the key to identify the information to give.
733 * \param val the address to return (long) integer values to
734 * \param fval the address to return floating point values to
735 * \return MPG123_OK or MPG123_ERR for success
737 EXPORT int mpg123_getstate(mpg123_handle *mh, enum mpg123_state key, long *val, double *fval);
739 /*@}*/
742 /** \defgroup mpg123_metadata mpg123 metadata handling
744 * Functions to retrieve the metadata from MPEG Audio files and streams.
745 * Also includes string handling functions.
747 * @{
750 /** Data structure for storing strings in a safer way than a standard C-String.
751 * Can also hold a number of null-terminated strings. */
752 typedef struct
754 char* p; /**< pointer to the string data */
755 size_t size; /**< raw number of bytes allocated */
756 size_t fill; /**< number of used bytes (including closing zero byte) */
757 } mpg123_string;
759 /** Create and allocate memory for a new mpg123_string */
760 EXPORT void mpg123_init_string(mpg123_string* sb);
762 /** Free-up mempory for an existing mpg123_string */
763 EXPORT void mpg123_free_string(mpg123_string* sb);
765 /** Change the size of a mpg123_string
766 * \return 0 on error, 1 on success */
767 EXPORT int mpg123_resize_string(mpg123_string* sb, size_t news);
769 /** Increase size of a mpg123_string if necessary (it may stay larger).
770 * Note that the functions for adding and setting in current libmpg123 use this instead of mpg123_resize_string().
771 * That way, you can preallocate memory and safely work afterwards with pieces.
772 * \return 0 on error, 1 on success */
773 EXPORT int mpg123_grow_string(mpg123_string* sb, size_t news);
775 /** Copy the contents of one mpg123_string string to another.
776 * \return 0 on error, 1 on success */
777 EXPORT int mpg123_copy_string(mpg123_string* from, mpg123_string* to);
779 /** Append a C-String to an mpg123_string
780 * \return 0 on error, 1 on success */
781 EXPORT int mpg123_add_string(mpg123_string* sb, const char* stuff);
783 /** Append a C-substring to an mpg123 string
784 * \return 0 on error, 1 on success
785 * \param from offset to copy from
786 * \param count number of characters to copy (a null-byte is always appended) */
787 EXPORT int mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count);
789 /** Set the conents of a mpg123_string to a C-string
790 * \return 0 on error, 1 on success */
791 EXPORT int mpg123_set_string(mpg123_string* sb, const char* stuff);
793 /** Set the contents of a mpg123_string to a C-substring
794 * \return 0 on error, 1 on success
795 * \param from offset to copy from
796 * \param count number of characters to copy (a null-byte is always appended) */
797 EXPORT int mpg123_set_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count);
799 /** Count characters in a mpg123 string (non-null bytes or UTF-8 characters).
800 * \return character count
801 * \param sb the string
802 * \param utf8 a flag to tell if the string is in utf8 encoding
803 * Even with the fill property, the character count is not obvious as there could be multiple trailing null bytes.
805 EXPORT size_t mpg123_strlen(mpg123_string *sb, int utf8);
807 /** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. */
808 enum mpg123_text_encoding
810 mpg123_text_unknown = 0 /**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. */
811 ,mpg123_text_utf8 = 1 /**< UTF-8 */
812 ,mpg123_text_latin1 = 2 /**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. */
813 ,mpg123_text_icy = 3 /**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. */
814 ,mpg123_text_cp1252 = 4 /**< Really CP-1252 without any guessing. */
815 ,mpg123_text_utf16 = 5 /**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
816 * When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
817 * you don't mess with the reserved code points. If you want to decode little endian data
818 * without BOM you need to prepend 0xff 0xfe yourself. */
819 ,mpg123_text_utf16bom = 6 /**< Just an alias for UTF-16, ID3v2 has this as distinct code. */
820 ,mpg123_text_utf16be = 7 /**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
821 * BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
822 * One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
823 * types (we expect a BOM before real data there), not so for utf16be!*/
824 ,mpg123_text_max = 7 /**< Placeholder for the maximum encoding value. */
827 /** The encoding byte values from ID3v2. */
828 enum mpg123_id3_enc
830 mpg123_id3_latin1 = 0 /**< Note: This sometimes can mean anything in practice... */
831 ,mpg123_id3_utf16bom = 1 /**< UTF16, UCS-2 ... it's all the same for practical purposes. */
832 ,mpg123_id3_utf16be = 2 /**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. */
833 ,mpg123_id3_utf8 = 3 /**< Our lovely overly ASCII-compatible 8 byte encoding for the world. */
834 ,mpg123_id3_enc_max = 3 /**< Placeholder to check valid range of encoding byte. */
837 /** Convert ID3 encoding byte to mpg123 encoding index. */
838 EXPORT enum mpg123_text_encoding mpg123_enc_from_id3(unsigned char id3_enc_byte);
840 /** Store text data in string, after converting to UTF-8 from indicated encoding
841 * \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
842 * \param sb target string
843 * \param enc mpg123 text encoding value
844 * \param source source buffer with plain unsigned bytes (you might need to cast from char *)
845 * \param source_size number of bytes in the source buffer
847 * 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).
848 * Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
850 EXPORT int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size);
852 /** Sub data structure for ID3v2, for storing various text fields (including comments).
853 * This is for ID3v2 COMM, TXXX and all the other text fields.
854 * Only COMM and TXXX have a description, only COMM and USLT have a language.
855 * 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). */
856 typedef struct
858 char lang[3]; /**< Three-letter language code (not terminated). */
859 char id[4]; /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */
860 mpg123_string description; /**< Empty for the generic comment... */
861 mpg123_string text; /**< ... */
862 } mpg123_text;
864 /** Data structure for storing IDV3v2 tags.
865 * This structure is not a direct binary mapping with the file contents.
866 * The ID3v2 text frames are allowed to contain multiple strings.
867 * So check for null bytes until you reach the mpg123_string fill.
868 * All text is encoded in UTF-8. */
869 typedef struct
871 unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */
872 mpg123_string *title; /**< Title string (pointer into text_list). */
873 mpg123_string *artist; /**< Artist string (pointer into text_list). */
874 mpg123_string *album; /**< Album string (pointer into text_list). */
875 mpg123_string *year; /**< The year as a string (pointer into text_list). */
876 mpg123_string *genre; /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */
877 mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */
878 /* Encountered ID3v2 fields are appended to these lists.
879 There can be multiple occurences, the pointers above always point to the last encountered data. */
880 mpg123_text *comment_list; /**< Array of comments. */
881 size_t comments; /**< Number of comments. */
882 mpg123_text *text; /**< Array of ID3v2 text fields (including USLT) */
883 size_t texts; /**< Numer of text fields. */
884 mpg123_text *extra; /**< The array of extra (TXXX) fields. */
885 size_t extras; /**< Number of extra text (TXXX) fields. */
886 } mpg123_id3v2;
888 /** Data structure for ID3v1 tags (the last 128 bytes of a file).
889 * Don't take anything for granted (like string termination)!
890 * Also note the change ID3v1.1 did: comment[28] = 0; comment[19] = track_number
891 * It is your task to support ID3v1 only or ID3v1.1 ...*/
892 typedef struct
894 char tag[3]; /**< Always the string "TAG", the classic intro. */
895 char title[30]; /**< Title string. */
896 char artist[30]; /**< Artist string. */
897 char album[30]; /**< Album string. */
898 char year[4]; /**< Year string. */
899 char comment[30]; /**< Comment string. */
900 unsigned char genre; /**< Genre index. */
901 } mpg123_id3v1;
903 #define MPG123_ID3 0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */
904 #define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */
905 #define MPG123_ICY 0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/
906 #define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */
908 /** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).
909 The check function returns a combination of flags. */
910 EXPORT int mpg123_meta_check(mpg123_handle *mh); /* On error (no valid handle) just 0 is returned. */
912 /** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.
913 * v1 and/or v2 can be set to NULL when there is no corresponding data.
914 * \return Return value is MPG123_OK or MPG123_ERR, */
915 EXPORT int mpg123_id3(mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2);
917 /** Point icy_meta to existing data structure wich may change on any next read/decode function call.
918 * \return Return value is MPG123_OK or MPG123_ERR, */
919 EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta); /* same for ICY meta string */
921 /** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.
922 * Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .
923 * \param icy_text The input data in ICY encoding
924 * \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */
925 EXPORT char* mpg123_icy2utf8(const char* icy_text);
928 /* @} */
931 /** \defgroup mpg123_advpar mpg123 advanced parameter API
933 * Direct access to a parameter set without full handle around it.
934 * Possible uses:
935 * - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).
936 * - Use one set of parameters for multiple handles.
938 * The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()
939 * family) directly return a fully qualified mpg123 error code, the ones
940 * operating on full handles normally MPG123_OK or MPG123_ERR, storing the
941 * specific error code itseld inside the handle.
943 * @{
946 /** Opaque structure for the libmpg123 decoder parameters. */
947 struct mpg123_pars_struct;
949 /** Opaque structure for the libmpg123 decoder parameters. */
950 typedef struct mpg123_pars_struct mpg123_pars;
952 /** Create a handle with preset parameters. */
953 EXPORT mpg123_handle *mpg123_parnew(mpg123_pars *mp, const char* decoder, int *error);
955 /** Allocate memory for and return a pointer to a new mpg123_pars */
956 EXPORT mpg123_pars *mpg123_new_pars(int *error);
958 /** Delete and free up memory used by a mpg123_pars data structure */
959 EXPORT void mpg123_delete_pars(mpg123_pars* mp);
961 /** Configure mpg123 parameters to accept no output format at all,
962 * use before specifying supported formats with mpg123_format */
963 EXPORT int mpg123_fmt_none(mpg123_pars *mp);
965 /** Configure mpg123 parameters to accept all formats
966 * (also any custom rate you may set) -- this is default. */
967 EXPORT int mpg123_fmt_all(mpg123_pars *mp);
969 /** Set the audio format support of a mpg123_pars in detail:
970 \param rate The sample rate value (in Hertz).
971 \param channels A combination of MPG123_STEREO and MPG123_MONO.
972 \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).
973 \return 0 on success, -1 if there was an error. /
975 EXPORT int mpg123_fmt(mpg123_pars *mh, long rate, int channels, int encodings); /* 0 is good, -1 is error */
977 /** Check to see if a specific format at a specific rate is supported
978 * by mpg123_pars.
979 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
980 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
981 EXPORT int mpg123_fmt_support(mpg123_pars *mh, long rate, int encoding);
983 /** Set a specific parameter, for a specific mpg123_pars, using a parameter
984 * type key chosen from the mpg123_parms enumeration, to the specified value. */
985 EXPORT int mpg123_par(mpg123_pars *mp, enum mpg123_parms type, long value, double fvalue);
987 /** Get a specific parameter, for a specific mpg123_pars.
988 * See the mpg123_parms enumeration for a list of available parameters. */
989 EXPORT int mpg123_getpar(mpg123_pars *mp, enum mpg123_parms type, long *val, double *fval);
991 /* @} */
994 /** \defgroup mpg123_lowio mpg123 low level I/O
995 * 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...
997 * @{ */
999 /** Replace default internal buffer with user-supplied buffer.
1000 * Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio. */
1001 EXPORT int mpg123_replace_buffer(mpg123_handle *mh, unsigned char *data, size_t size);
1003 /** The max size of one frame's decoded output with current settings.
1004 * Use that to determine an appropriate minimum buffer size for decoding one frame. */
1005 EXPORT size_t mpg123_outblock(mpg123_handle *mh);
1007 /** Replace low-level stream access functions; read and lseek as known in POSIX.
1008 * You can use this to make any fancy file opening/closing yourself,
1009 * using mpg123_open_fd() to set the file descriptor for your read/lseek (doesn't need to be a "real" file descriptor...).
1010 * Setting a function to NULL means that the default internal read is
1011 * used (active from next mpg123_open call on).
1012 * Note: As it would be troublesome to mess with this while having a file open,
1013 * this implies mpg123_close(). */
1014 EXPORT int mpg123_replace_reader(mpg123_handle *mh, ssize_t (*r_read) (int, void *, size_t), off_t (*r_lseek)(int, off_t, int));
1016 /** Replace I/O functions with your own ones operating on some kind of handle instead of integer descriptors.
1017 * The handle is a void pointer, so you can pass any data you want...
1018 * mpg123_open_handle() is the call you make to use the I/O defined here.
1019 * There is no fallback to internal read/seek here.
1020 * Note: As it would be troublesome to mess with this while having a file open,
1021 * this mpg123_close() is implied here.
1022 * \param r_read The callback for reading (behaviour like posix read).
1023 * \param r_lseek The callback for seeking (like posix lseek).
1024 * \param cleanup A callback to clean up an I/O handle on mpg123_close, can be NULL for none (you take care of cleaning your handles). */
1025 EXPORT int mpg123_replace_reader_handle(mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), off_t (*r_lseek)(void *, off_t, int), void (*cleanup)(void*));
1027 /* @} */
1030 #ifdef __cplusplus
1032 #endif
1034 #endif