Subversion Repositories Games.Prince of Persia

Rev

Details | Last modification | View Log | RSS feed

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