/*1libmpg123: MPEG Audio Decoder library (version 1.26.2)23copyright 1995-2015 by the mpg123 project4free software under the terms of the LGPL 2.15see COPYING and AUTHORS files in distribution or http://mpg123.org6*/78#ifndef MPG123_LIB_H9#define MPG123_LIB_H1011#include <fmt123.h>1213/** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder */1415/** A macro to check at compile time which set of API functions to expect.16* This should be incremented at least each time a new symbol is added17* to the header.18*/19#define MPG123_API_VERSION 452021#ifndef MPG123_EXPORT22/** Defines needed for MS Visual Studio(tm) DLL builds.23* Every public function must be prefixed with MPG123_EXPORT. When building24* the DLL ensure to define BUILD_MPG123_DLL. This makes the function accessible25* for clients and includes it in the import library which is created together26* with the DLL. When consuming the DLL ensure to define LINK_MPG123_DLL which27* imports the functions from the DLL.28*/29#ifdef BUILD_MPG123_DLL30/* The dll exports. */31#define MPG123_EXPORT __declspec(dllexport)32#else33#ifdef LINK_MPG123_DLL34/* The exe imports. */35#define MPG123_EXPORT __declspec(dllimport)36#else37/* Nothing on normal/UNIX builds */38#define MPG123_EXPORT39#endif40#endif41#endif4243/* This is for Visual Studio, so this header works as distributed in the binary downloads */44#if defined(_MSC_VER) && !defined(MPG123_DEF_SSIZE_T)45#define MPG123_DEF_SSIZE_T46#include <stddef.h>47typedef ptrdiff_t ssize_t;48#endif4950#ifndef MPG123_NO_CONFIGURE /* Enable use of this file without configure. */51#include <stdlib.h>52#include <sys/types.h>5354/* Simplified large file handling.55I used to have a check here that prevents building for a library with conflicting large file setup56(application that uses 32 bit offsets with library that uses 64 bits).57While that was perfectly fine in an environment where there is one incarnation of the library,58it hurt GNU/Linux and Solaris systems with multilib where the distribution fails to provide the59correct header matching the 32 bit library (where large files need explicit support) or60the 64 bit library (where there is no distinction).6162New approach: When the app defines _FILE_OFFSET_BITS, it wants non-default large file support,63and thus functions with added suffix (mpg123_open_64).64Any mismatch will be caught at link time because of the _FILE_OFFSET_BITS setting used when65building libmpg123. Plus, there's dual mode large file support in mpg123 since 1.12 now.66Link failure is not the expected outcome of any half-sane usage anymore.6768More 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.69*/7071/*72Now, the renaming of large file aware functions.73By 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.74*/75#if (!defined MPG123_NO_LARGENAME) && ((defined _FILE_OFFSET_BITS) || (defined MPG123_LARGESUFFIX))7677/* Need some trickery to concatenate the value(s) of the given macro(s). */78#define MPG123_MACROCAT_REALLY(a, b) a ## b79#define MPG123_MACROCAT(a, b) MPG123_MACROCAT_REALLY(a, b)80#ifndef MPG123_LARGESUFFIX81#define MPG123_LARGESUFFIX MPG123_MACROCAT(_, _FILE_OFFSET_BITS)82#endif83#define MPG123_LARGENAME(func) MPG123_MACROCAT(func, MPG123_LARGESUFFIX)8485#define mpg123_open_fixed MPG123_LARGENAME(mpg123_open_fixed)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)107108#endif /* largefile hackery */109110#endif /* MPG123_NO_CONFIGURE */111112#ifdef __cplusplus113extern "C" {114#endif115116/** \defgroup mpg123_init mpg123 library and handle setup117*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*/124125/** Opaque structure for the libmpg123 decoder handle. */126struct mpg123_handle_struct;127128/** 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*/131typedef struct mpg123_handle_struct mpg123_handle;132133/** Function to initialise the mpg123 library.134* This should be called once in a non-parallel context. It is not explicitly135* thread-safe, but repeated/concurrent calls still _should_ be safe as static136* tables are filled with the same values anyway.137*138* \return MPG123_OK if successful, otherwise an error number.139*/140MPG123_EXPORT int mpg123_init(void);141142/** Superfluous Function to close down the mpg123 library.143* This was created with the thought that there sometime will be cleanup code144* to be run after library use. This never materialized. You can forget about145* this function and it is only here for old programs that do call it.146*/147MPG123_EXPORT void mpg123_exit(void);148149/** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).150* and optional retrieval of an error code to feed to mpg123_plain_strerror().151* Optional means: Any of or both the parameters may be NULL.152*153* \param decoder optional choice of decoder variant (NULL for default)154* \param error optional address to store error codes155* \return Non-NULL pointer to fresh handle when successful.156*/157MPG123_EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error);158159/** Delete handle, mh is either a valid mpg123 handle or NULL.160* \param mh handle161*/162MPG123_EXPORT void mpg123_delete(mpg123_handle *mh);163164/** Free plain memory allocated within libmpg123.165* This is for library users that are not sure to use the same underlying166* memory allocator as libmpg123. It is just a wrapper over free() in167* the underlying C library.168*/169MPG123_EXPORT void mpg123_free(void *ptr);170171/** Enumeration of the parameters types that it is possible to set/get. */172enum mpg123_parms173{174MPG123_VERBOSE = 0, /**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) */175MPG123_FLAGS, /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) */176MPG123_ADD_FLAGS, /**< add some flags (integer) */177MPG123_FORCE_RATE, /**< when value > 0, force output rate to that value (integer) */178MPG123_DOWN_SAMPLE, /**< 0=native rate, 1=half rate, 2=quarter rate (integer) */179MPG123_RVA, /**< one of the RVA choices above (integer) */180MPG123_DOWNSPEED, /**< play a frame N times (integer) */181MPG123_UPSPEED, /**< play every Nth frame (integer) */182MPG123_START_FRAME, /**< start with this frame (skip frames before that, integer) */183MPG123_DECODE_FRAMES, /**< decode only this number of frames (integer) */184MPG123_ICY_INTERVAL, /**< Stream contains ICY metadata with this interval (integer).185Make sure to set this _before_ opening a stream.*/186MPG123_OUTSCALE, /**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) */187MPG123_TIMEOUT, /**< timeout for reading from a stream (not supported on win32, integer) */188MPG123_REMOVE_FLAGS, /**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) */189MPG123_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). */190MPG123_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. */191,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.*/192,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) */193,MPG123_FEEDBUFFER /**< Minimal size of one internal feeder buffer, again, the default value is subject to change. (integer) */194,MPG123_FREEFORMAT_SIZE /**< Tell the parser a free-format frame size to195* avoid read-ahead to get it. A value of -1 (default) means that the parser196* will determine it. The parameter value is applied during decoder setup197* for a freshly opened stream only.198*/199};200201/** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */202enum mpg123_param_flags203{204MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */205,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */206,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */207,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */208,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */209,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */210,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */211,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */212,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */213,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */214,MPG123_FUZZY = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */215,MPG123_FORCE_FLOAT = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */216,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. */217,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 */218,MPG123_SKIP_ID3V2 = 0x2000 /**< 10 0000 0000 0000 Do not parse ID3v2 tags, just skip them. */219,MPG123_IGNORE_INFOFRAME = 0x4000 /**< 100 0000 0000 0000 Do not parse the LAME/Xing info frame, treat it as normal MPEG data. */220,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. */221,MPG123_PICTURE = 0x10000 /**< 17th bit: Enable storage of pictures from tags (ID3v2 APIC). */222,MPG123_NO_PEEK_END = 0x20000 /**< 18th bit: Do not seek to the end of223* the stream in order to probe224* the stream length and search for the id3v1 field. This also means225* the file size is unknown unless set using mpg123_set_filesize() and226* the stream is assumed as non-seekable unless overridden.227*/228,MPG123_FORCE_SEEKABLE = 0x40000 /**< 19th bit: Force the stream to be seekable. */229,MPG123_STORE_RAW_ID3 = 0x80000 /**< store raw ID3 data (even if skipping) */230,MPG123_FORCE_ENDIAN = 0x100000 /**< Enforce endianess of output samples.231* This is not reflected in the format codes. If this flag is set along with232* MPG123_BIG_ENDIAN, MPG123_ENC_SIGNED16 means s16be, without233* MPG123_BIG_ENDIAN, it means s16le. Normal operation without234* MPG123_FORCE_ENDIAN produces output in native byte order.235*/236,MPG123_BIG_ENDIAN = 0x200000 /**< Choose big endian instead of little. */237,MPG123_NO_READAHEAD = 0x400000 /**< Disable read-ahead in parser. If238* you know you provide full frames to the feeder API, this enables239* decoder output from the first one on, instead of having to wait for240* the next frame to confirm that the stream is healthy. It also disables241* free format support unless you provide a frame size using242* MPG123_FREEFORMAT_SIZE.243*/244,MPG123_FLOAT_FALLBACK = 0x800000 /**< Consider floating point output encoding only after245* trying other (possibly downsampled) rates and encodings first. This is to246* support efficient playback where floating point output is only configured for247* an external resampler, bypassing that resampler when the desired rate can248* be produced directly. This is enabled by default to be closer to older versions249* of libmpg123 which did not enable float automatically at all. If disabled,250* float is considered after the 16 bit default and higher-bit integer encodings251* for any rate. */252,MPG123_NO_FRANKENSTEIN = 0x1000000 /**< Disable support for Frankenstein streams253* (different MPEG streams stiched together). Do not accept serious change of MPEG254* header inside a single stream. With this flag, the audio output format cannot255* change during decoding unless you open a new stream. This also stops decoding256* after an announced end of stream (Info header contained a number of frames257* and this number has been reached). This makes your MP3 files behave more like258* ordinary media files with defined structure, rather than stream dumps with259* some sugar. */260};261262/** choices for MPG123_RVA */263enum mpg123_param_rva264{265MPG123_RVA_OFF = 0 /**< RVA disabled (default). */266,MPG123_RVA_MIX = 1 /**< Use mix/track/radio gain. */267,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */268,MPG123_RVA_MAX = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */269};270271/** Set a specific parameter, for a specific mpg123_handle, using a parameter272* type key chosen from the mpg123_parms enumeration, to the specified value.273* \param mh handle274* \param type parameter choice275* \param value integer value276* \param fvalue floating point value277* \return MPG123_OK on success278*/279MPG123_EXPORT int mpg123_param( mpg123_handle *mh280, enum mpg123_parms type, long value, double fvalue );281282/** Get a specific parameter, for a specific mpg123_handle.283* See the mpg123_parms enumeration for a list of available parameters.284* \param mh handle285* \param type parameter choice286* \param value integer value return address287* \param fvalue floating point value return address288* \return MPG123_OK on success289*/290MPG123_EXPORT int mpg123_getparam( mpg123_handle *mh291, enum mpg123_parms type, long *value, double *fvalue );292293/** Feature set available for query with mpg123_feature. */294enum mpg123_feature_set295{296MPG123_FEATURE_ABI_UTF8OPEN = 0 /**< mpg123 expects path names to be given in UTF-8 encoding instead of plain native. */297,MPG123_FEATURE_OUTPUT_8BIT /**< 8bit output */298,MPG123_FEATURE_OUTPUT_16BIT /**< 16bit output */299,MPG123_FEATURE_OUTPUT_32BIT /**< 32bit output */300,MPG123_FEATURE_INDEX /**< support for building a frame index for accurate seeking */301,MPG123_FEATURE_PARSE_ID3V2 /**< id3v2 parsing */302,MPG123_FEATURE_DECODE_LAYER1 /**< mpeg layer-1 decoder enabled */303,MPG123_FEATURE_DECODE_LAYER2 /**< mpeg layer-2 decoder enabled */304,MPG123_FEATURE_DECODE_LAYER3 /**< mpeg layer-3 decoder enabled */305,MPG123_FEATURE_DECODE_ACCURATE /**< accurate decoder rounding */306,MPG123_FEATURE_DECODE_DOWNSAMPLE /**< downsample (sample omit) */307,MPG123_FEATURE_DECODE_NTOM /**< flexible rate decoding */308,MPG123_FEATURE_PARSE_ICY /**< ICY support */309,MPG123_FEATURE_TIMEOUT_READ /**< Reader with timeout (network). */310,MPG123_FEATURE_EQUALIZER /**< tunable equalizer */311,MPG123_FEATURE_MOREINFO /**< more info extraction (for frame analyzer) */312,MPG123_FEATURE_OUTPUT_FLOAT32 /**< 32 bit float output */313,MPG123_FEATURE_OUTPUT_FLOAT64 /**< 64 bit float output (usually never) */314};315316/** Query libmpg123 features.317* \param key feature selection318* \return 1 for success, 0 for unimplemented functions319*/320MPG123_EXPORT int mpg123_feature(const enum mpg123_feature_set key);321322/** Query libmpg123 features with better ABI compatibility323*324* This is the same as mpg123_feature(), but this time not using325* the enum as argument. Compilers don't have to agree on the size of326* enums and hence they are not safe in public API.327*328* \param key feature selection329* \return 1 for success, 0 for unimplemented functions330*/331MPG123_EXPORT int mpg123_feature2(int key);332333/* @} */334335336/** \defgroup mpg123_error mpg123 error handling337*338* Functions to get text version of the error numbers and an enumeration339* of the error codes returned by libmpg123.340*341* Most functions operating on a mpg123_handle simply return MPG123_OK (0)342* on success and MPG123_ERR (-1) on failure, setting the internal error343* variable of the handle to the specific error code. If there was not a valid344* (non-NULL) handle provided to a function operating on one, MPG123_BAD_HANDLE345* may be returned if this can not be confused with a valid positive return346* value.347* Meaning: A function expected to return positive integers on success will348* always indicate error or a special condition by returning a negative one.349*350* Decoding/seek functions may also return message codes MPG123_DONE,351* MPG123_NEW_FORMAT and MPG123_NEED_MORE (all negative, see below on how to352* react). Note that calls to those can be nested, so generally watch out353* for these codes after initial handle setup.354* Especially any function that needs information about the current stream355* to work will try to at least parse the beginning if that did not happen356* yet.357*358* On a function that is supposed to return MPG123_OK on success and359* MPG123_ERR on failure, make sure you check for != MPG123_OK, not360* == MPG123_ERR, as the error code could get more specific in future,361* or there is just a special message from a decoding routine as indicated362* above.363*364* @{365*/366367/** Enumeration of the message and error codes and returned by libmpg123 functions. */368enum mpg123_errors369{370MPG123_DONE=-12, /**< Message: Track ended. Stop decoding. */371MPG123_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. */372MPG123_NEED_MORE=-10, /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */373MPG123_ERR=-1, /**< Generic Error */374MPG123_OK=0, /**< Success */375MPG123_BAD_OUTFORMAT, /**< Unable to set up output format! */376MPG123_BAD_CHANNEL, /**< Invalid channel number specified. */377MPG123_BAD_RATE, /**< Invalid sample rate specified. */378MPG123_ERR_16TO8TABLE, /**< Unable to allocate memory for 16 to 8 converter table! */379MPG123_BAD_PARAM, /**< Bad parameter id! */380MPG123_BAD_BUFFER, /**< Bad buffer given -- invalid pointer or too small size. */381MPG123_OUT_OF_MEM, /**< Out of memory -- some malloc() failed. */382MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */383MPG123_BAD_DECODER, /**< Invalid decoder choice. */384MPG123_BAD_HANDLE, /**< Invalid mpg123 handle. */385MPG123_NO_BUFFERS, /**< Unable to initialize frame buffers (out of memory?). */386MPG123_BAD_RVA, /**< Invalid RVA mode. */387MPG123_NO_GAPLESS, /**< This build doesn't support gapless decoding. */388MPG123_NO_SPACE, /**< Not enough buffer space. */389MPG123_BAD_TYPES, /**< Incompatible numeric data types. */390MPG123_BAD_BAND, /**< Bad equalizer band. */391MPG123_ERR_NULL, /**< Null pointer given where valid storage address needed. */392MPG123_ERR_READER, /**< Error reading the stream. */393MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */394MPG123_BAD_WHENCE, /**< Invalid 'whence' for seek function.*/395MPG123_NO_TIMEOUT, /**< Build does not support stream timeouts. */396MPG123_BAD_FILE, /**< File access error. */397MPG123_NO_SEEK, /**< Seek not supported by stream. */398MPG123_NO_READER, /**< No stream opened. */399MPG123_BAD_PARS, /**< Bad parameter handle. */400MPG123_BAD_INDEX_PAR, /**< Bad parameters to mpg123_index() and mpg123_set_index() */401MPG123_OUT_OF_SYNC, /**< Lost track in bytestream and did not try to resync. */402MPG123_RESYNC_FAIL, /**< Resync failed to find valid MPEG data. */403MPG123_NO_8BIT, /**< No 8bit encoding possible. */404MPG123_BAD_ALIGN, /**< Stack aligmnent error */405MPG123_NULL_BUFFER, /**< NULL input buffer with non-zero size... */406MPG123_NO_RELSEEK, /**< Relative seek not possible (screwed up file offset) */407MPG123_NULL_POINTER, /**< You gave a null pointer somewhere where you shouldn't have. */408MPG123_BAD_KEY, /**< Bad key value given. */409MPG123_NO_INDEX, /**< No frame index in this build. */410MPG123_INDEX_FAIL, /**< Something with frame index went wrong. */411MPG123_BAD_DECODER_SETUP, /**< Something prevents a proper decoder setup */412MPG123_MISSING_FEATURE /**< This feature has not been built into libmpg123. */413,MPG123_BAD_VALUE /**< A bad value has been given, somewhere. */414,MPG123_LSEEK_FAILED /**< Low-level seek failed. */415,MPG123_BAD_CUSTOM_IO /**< Custom I/O not prepared. */416,MPG123_LFS_OVERFLOW /**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. */417,MPG123_INT_OVERFLOW /**< Some integer overflow. */418};419420/** Look up error strings given integer code.421* \param errcode integer error code422* \return string describing what that error error code means423*/424MPG123_EXPORT const char* mpg123_plain_strerror(int errcode);425426/** Give string describing what error has occured in the context of handle mh.427* When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via428* char *errmsg = mpg123_strerror(mh)429* This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE.430* \param mh handle431* \return error message432*/433MPG123_EXPORT const char* mpg123_strerror(mpg123_handle *mh);434435/** Return the plain errcode intead of a string.436* \param mh handle437* \return error code recorded in handle or MPG123_BAD_HANDLE438*/439MPG123_EXPORT int mpg123_errcode(mpg123_handle *mh);440441/*@}*/442443444/** \defgroup mpg123_decoder mpg123 decoder selection445*446* Functions to list and select the available decoders.447* Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).448*449* @{450*/451452/** Get available decoder list.453* \return NULL-terminated array of generally available decoder names (plain 8bit ASCII)454*/455MPG123_EXPORT const char **mpg123_decoders(void);456457/** Get supported decoder list.458* \return NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII)459*/460MPG123_EXPORT const char **mpg123_supported_decoders(void);461462/** Set the active decoder.463* \param mh handle464* \param decoder_name name of decoder465* \return MPG123_OK on success466*/467MPG123_EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name);468469/** Get the currently active decoder name.470* The active decoder engine can vary depening on output constraints,471* mostly non-resampling, integer output is accelerated via 3DNow & Co. but for472* other modes a fallback engine kicks in.473* Note that this can return a decoder that is only active in the hidden and not474* available as decoder choice from the outside.475* \param mh handle476* \return The decoder name or NULL on error.477*/478MPG123_EXPORT const char* mpg123_current_decoder(mpg123_handle *mh);479480/*@}*/481482483/** \defgroup mpg123_output mpg123 output audio format484*485* Functions to get and select the format of the decoded audio.486*487* Before you dive in, please be warned that you might get confused by this.488* This seems to happen a lot, therefore I am trying to explain in advance.489* If you do feel confused and just want to decode your normal MPEG audio files that490* don't alter properties in the middle, just use mpg123_open_fixed() with a fixed encoding491* and channel count and forget about a matrix of audio formats. If you want to get funky,492* read ahead ...493*494* 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).495*496* 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.497*498* 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.499*500* 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.501*502* @{503*/504505/** They can be combined into one number (3) to indicate mono and stereo... */506enum mpg123_channelcount507{508MPG123_MONO = 1 /**< mono */509,MPG123_STEREO = 2 /**< stereo */510};511512/** An array of supported standard sample rates513* These are possible native sample rates of MPEG audio files.514* You can still force mpg123 to resample to a different one, but by515* default you will only get audio in one of these samplings.516* This list is in ascending order.517* \param list Store a pointer to the sample rates array there.518* \param number Store the number of sample rates there. */519MPG123_EXPORT void mpg123_rates(const long **list, size_t *number);520521/** An array of supported audio encodings.522* An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).523* \param list Store a pointer to the encodings array there.524* \param number Store the number of encodings there. */525MPG123_EXPORT void mpg123_encodings(const int **list, size_t *number);526527/** Return the size (in bytes) of one mono sample of the named encoding.528* \param encoding The encoding value to analyze.529* \return positive size of encoding in bytes, 0 on invalid encoding. */530MPG123_EXPORT int mpg123_encsize(int encoding);531532/** Configure a mpg123 handle to accept no output format at all,533* use before specifying supported formats with mpg123_format534* \param mh handle535* \return MPG123_OK on success536*/537MPG123_EXPORT int mpg123_format_none(mpg123_handle *mh);538539/** Configure mpg123 handle to accept all formats540* (also any custom rate you may set) -- this is default.541* \param mh handle542* \return MPG123_OK on success543*/544MPG123_EXPORT int mpg123_format_all(mpg123_handle *mh);545546/** Set the audio format support of a mpg123_handle in detail:547* \param mh handle548* \param rate The sample rate value (in Hertz).549* \param channels A combination of MPG123_STEREO and MPG123_MONO.550* \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.551* \return MPG123_OK on success, MPG123_ERR if there was an error. */552MPG123_EXPORT int mpg123_format( mpg123_handle *mh553, long rate, int channels, int encodings );554555/** Set the audio format support of a mpg123_handle in detail:556* \param mh handle557* \param rate The sample rate value (in Hertz). Special value 0 means558* all rates (the reason for this variant of mpg123_format()).559* \param channels A combination of MPG123_STEREO and MPG123_MONO.560* \param encodings A combination of accepted encodings for rate and channels,561* p.ex MPG123_ENC_SIGNED16 | MPG123_ENC_ULAW_8 (or 0 for no support).562* Please note that some encodings may not be supported in the library build563* and thus will be ignored here.564* \return MPG123_OK on success, MPG123_ERR if there was an error. */565MPG123_EXPORT int mpg123_format2( mpg123_handle *mh566, long rate, int channels, int encodings );567568/** Check to see if a specific format at a specific rate is supported569* by mpg123_handle.570* \param mh handle571* \param rate sampling rate572* \param encoding encoding573* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,574* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */575MPG123_EXPORT int mpg123_format_support( mpg123_handle *mh576, long rate, int encoding );577578/** Get the current output format written to the addresses given.579* If the stream is freshly loaded, this will try to parse enough580* of it to give you the format to come. This clears the flag that581* would otherwise make the first decoding call return582* MPG123_NEW_FORMAT.583* \param mh handle584* \param rate sampling rate return address585* \param channels channel count return address586* \param encoding encoding return address587* \return MPG123_OK on success588*/589MPG123_EXPORT int mpg123_getformat( mpg123_handle *mh590, long *rate, int *channels, int *encoding );591592/** Get the current output format written to the addresses given.593* This differs from plain mpg123_getformat() in that you can choose594* _not_ to clear the flag that would trigger the next decoding call595* to return MPG123_NEW_FORMAT in case of a new format arriving.596* \param mh handle597* \param rate sampling rate return address598* \param channels channel count return address599* \param encoding encoding return address600* \param clear_flag if true, clear internal format flag601* \return MPG123_OK on success602*/603MPG123_EXPORT int mpg123_getformat2( mpg123_handle *mh604, long *rate, int *channels, int *encoding, int clear_flag );605606/*@}*/607608609/** \defgroup mpg123_input mpg123 file input and decoding610*611* Functions for input bitstream and decoding operations.612* 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!).613* @{614*/615616/** Open a simple MPEG file with fixed properties.617*618* This function shall simplify the common use case of a plain MPEG619* file on disk that you want to decode, with one fixed sample620* rate and channel count, and usually a length defined by a Lame/Info/Xing621* tag. It will:622*623* - set the MPG123_NO_FRANKENSTEIN flag624* - set up format support according to given parameters,625* - open the file,626* - query audio format,627* - fix the audio format support table to ensure the format stays the same,628* - call mpg123_scan() if there is no header frame to tell the track length.629*630* From that on, you can call mpg123_getformat() for querying the sample631* rate (and channel count in case you allowed both) and mpg123_length()632* to get a pretty safe number for the duration.633* Only the sample rate is left open as that indeed is a fixed property of634* MPEG files. You could set MPG123_FORCE_RATE beforehand, but that may trigger635* low-quality resampling in the decoder, only do so if in dire need.636* The library will convert mono files to stereo for you, and vice versa.637* If any constraint cannot be satisified (most likely because of a non-default638* build of libmpg123), you get MPG123_ERR returned and can query the detailed639* cause from the handle. Only on MPG123_OK there will an open file that you640* then close using mpg123_close(), or implicitly on mpg123_delete() or the next641* call to open another file.642*643* So, for your usual CD rip collection, you could use644*645* mpg123_open_fixed(mh, path, MPG123_STEREO, MPG123_ENC_SIGNED_16)646*647* and be happy calling mpg123_getformat() to verify 44100 Hz rate, then just648* playing away with mpg123_read(). The occasional mono file, or MP2 file,649* will also be decoded without you really noticing. Just the speed could be650* wrong if you do not care about sample rate at all.651* \param mh handle652* \param path filesystem path653* \param channels allowed channel count, either 1 (MPG123_MONO) or654* 2 (MPG123_STEREO), or bitwise or of them, but then you're halfway back to655* calling mpg123_format() again;-)656* \param encoding a definite encoding from enum mpg123_enc_enum657* or a bitmask like for mpg123_format(), defeating the purpose somewhat658*/659MPG123_EXPORT int mpg123_open_fixed(mpg123_handle *mh, const char *path660, int channels, int encoding);661662/** Open and prepare to decode the specified file by filesystem path.663* This does not open HTTP urls; libmpg123 contains no networking code.664* If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().665* \param mh handle666* \param path filesystem path667* \return MPG123_OK on success668*/669MPG123_EXPORT int mpg123_open(mpg123_handle *mh, const char *path);670671/** Use an already opened file descriptor as the bitstream input672* mpg123_close() will _not_ close the file descriptor.673* \param mh handle674* \param fd file descriptor675* \return MPG123_OK on success676*/677MPG123_EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd);678679/** Use an opaque handle as bitstream input. This works only with the680* replaced I/O from mpg123_replace_reader_handle()!681* mpg123_close() will call the cleanup callback for your handle (if you gave one).682* \param mh handle683* \param iohandle your handle684* \return MPG123_OK on success685*/686MPG123_EXPORT int mpg123_open_handle(mpg123_handle *mh, void *iohandle);687688/** Open a new bitstream and prepare for direct feeding689* This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.690* Also, you are expected to handle ICY metadata extraction yourself. This691* input method does not handle MPG123_ICY_INTERVAL. It does parse ID3 frames, though.692* \param mh handle693* \return MPG123_OK on success694*/695MPG123_EXPORT int mpg123_open_feed(mpg123_handle *mh);696697/** Closes the source, if libmpg123 opened it.698* \param mh handle699* \return MPG123_OK on success700*/701MPG123_EXPORT int mpg123_close(mpg123_handle *mh);702703/** Read from stream and decode up to outmemsize bytes.704*705* Note: The type of outmemory changed to a void pointer in mpg123 1.26.0706* (API version 45).707*708* \param mh handle709* \param outmemory address of output buffer to write to710* \param outmemsize maximum number of bytes to write711* \param done address to store the number of actually decoded bytes to712* \return MPG123_OK or error/message code713*/714MPG123_EXPORT int mpg123_read(mpg123_handle *mh715, void *outmemory, size_t outmemsize, size_t *done );716717/** Feed data for a stream that has been opened with mpg123_open_feed().718* It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.719* \param mh handle720* \param in input buffer721* \param size number of input bytes722* \return MPG123_OK or error/message code.723*/724MPG123_EXPORT int mpg123_feed( mpg123_handle *mh725, const unsigned char *in, size_t size );726727/** Decode MPEG Audio from inmemory to outmemory.728* This is very close to a drop-in replacement for old mpglib.729* When you give zero-sized output buffer the input will be parsed until730* decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)731* without taking decoded data.732* Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).733* You can actually always decide if you want those specialized functions in separate steps or one call this one here.734*735* Note: The type of outmemory changed to a void pointer in mpg123 1.26.0736* (API version 45).737*738* \param mh handle739* \param inmemory input buffer740* \param inmemsize number of input bytes741* \param outmemory output buffer742* \param outmemsize maximum number of output bytes743* \param done address to store the number of actually decoded bytes to744* \return error/message code (watch out especially for MPG123_NEED_MORE)745*/746MPG123_EXPORT int mpg123_decode( mpg123_handle *mh747, const unsigned char *inmemory, size_t inmemsize748, void *outmemory, size_t outmemsize, size_t *done );749750/** Decode next MPEG frame to internal buffer751* or read a frame and return after setting a new format.752* \param mh handle753* \param num current frame offset gets stored there754* \param audio This pointer is set to the internal buffer to read the decoded audio from.755* \param bytes number of output bytes ready in the buffer756* \return MPG123_OK or error/message code757*/758MPG123_EXPORT int mpg123_decode_frame( mpg123_handle *mh759, off_t *num, unsigned char **audio, size_t *bytes );760761/** Decode current MPEG frame to internal buffer.762* Warning: This is experimental API that might change in future releases!763* Please watch mpg123 development closely when using it.764* \param mh handle765* \param num last frame offset gets stored there766* \param audio this pointer is set to the internal buffer to read the decoded audio from.767* \param bytes number of output bytes ready in the buffer768* \return MPG123_OK or error/message code769*/770MPG123_EXPORT int mpg123_framebyframe_decode( mpg123_handle *mh771, off_t *num, unsigned char **audio, size_t *bytes );772773/** Find, read and parse the next mp3 frame774* Warning: This is experimental API that might change in future releases!775* Please watch mpg123 development closely when using it.776* \param mh handle777* \return MPG123_OK or error/message code778*/779MPG123_EXPORT int mpg123_framebyframe_next(mpg123_handle *mh);780781/** Get access to the raw input data for the last parsed frame.782* This gives you a direct look (and write access) to the frame body data.783* 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()).784* 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.785* You can provide NULL for a parameter pointer when you are not interested in the value.786*787* \param mh handle788* \param header the 4-byte MPEG header789* \param bodydata pointer to the frame body stored in the handle (without the header)790* \param bodybytes size of frame body in bytes (without the header)791* \return MPG123_OK if there was a yet un-decoded frame to get the792* data from, MPG123_BAD_HANDLE or MPG123_ERR otherwise (without further793* explanation, the error state of the mpg123_handle is not modified by794* this function).795*/796MPG123_EXPORT int mpg123_framedata( mpg123_handle *mh797, unsigned long *header, unsigned char **bodydata, size_t *bodybytes );798799/** Get the input position (byte offset in stream) of the last parsed frame.800* This can be used for external seek index building, for example.801* It just returns the internally stored offset, regardless of validity --802* you ensure that a valid frame has been parsed before!803* \param mh handle804* \return byte offset in stream805*/806MPG123_EXPORT off_t mpg123_framepos(mpg123_handle *mh);807808/*@}*/809810811/** \defgroup mpg123_seek mpg123 position and seeking812*813* Functions querying and manipulating position in the decoded audio bitstream.814* The position is measured in decoded audio samples, or MPEG frame offset for the specific functions.815* 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;-)816* The general usage is modelled after stdlib's ftell() and fseek().817* 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:818* - SEEK_SET: set position to (or near to) specified offset819* - SEEK_CUR: change position by offset from now820* - SEEK_END: set position to offset from end821*822* Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise.823* 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)!824* Short: When you care about the sample position, don't mess with those parameters;-)825* Also, seeking is not guaranteed to work for all streams (underlying stream may not support it).826* And yet another caveat: If the stream is concatenated out of differing pieces (Frankenstein stream), seeking may suffer, too.827*828* @{829*/830831/** Returns the current position in samples.832* On the next successful read, you'd get that sample.833* \param mh handle834* \return sample offset or MPG123_ERR (null handle)835*/836MPG123_EXPORT off_t mpg123_tell(mpg123_handle *mh);837838/** Returns the frame number that the next read will give you data from.839* \param mh handle840* \return frame offset or MPG123_ERR (null handle)841*/842MPG123_EXPORT off_t mpg123_tellframe(mpg123_handle *mh);843844/** Returns the current byte offset in the input stream.845* \param mh handle846* \return byte offset or MPG123_ERR (null handle)847*/848MPG123_EXPORT off_t mpg123_tell_stream(mpg123_handle *mh);849850/** Seek to a desired sample offset.851* Usage is modelled afer the standard lseek().852* \param mh handle853* \param sampleoff offset in PCM samples854* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END855* \return The resulting offset >= 0 or error/message code856*/857MPG123_EXPORT off_t mpg123_seek( mpg123_handle *mh858, off_t sampleoff, int whence );859860/** Seek to a desired sample offset in data feeding mode.861* 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.862* \param mh handle863* \param sampleoff offset in PCM samples864* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END865* \param input_offset The position it expects to be at the866* next time data is fed to mpg123_decode().867* \return The resulting offset >= 0 or error/message code */868MPG123_EXPORT off_t mpg123_feedseek( mpg123_handle *mh869, off_t sampleoff, int whence, off_t *input_offset );870871/** Seek to a desired MPEG frame offset.872* Usage is modelled afer the standard lseek().873* \param mh handle874* \param frameoff offset in MPEG frames875* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END876* \return The resulting offset >= 0 or error/message code */877MPG123_EXPORT off_t mpg123_seek_frame( mpg123_handle *mh878, off_t frameoff, int whence );879880/** Return a MPEG frame offset corresponding to an offset in seconds.881* 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.882* \return frame offset >= 0 or error/message code */883MPG123_EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec);884885/** Give access to the frame index table that is managed for seeking.886* You are asked not to modify the values... Use mpg123_set_index to set the887* seek index888* \param mh handle889* \param offsets pointer to the index array890* \param step one index byte offset advances this many MPEG frames891* \param fill number of recorded index offsets; size of the array892* \return MPG123_OK on success893*/894MPG123_EXPORT int mpg123_index( mpg123_handle *mh895, off_t **offsets, off_t *step, size_t *fill );896897/** Set the frame index table898* Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets899* to NULL and fill to 0 will clear the index and free the allocated memory used by the index.900* \param mh handle901* \param offsets pointer to the index array902* \param step one index byte offset advances this many MPEG frames903* \param fill number of recorded index offsets; size of the array904* \return MPG123_OK on success905*/906MPG123_EXPORT int mpg123_set_index( mpg123_handle *mh907, off_t *offsets, off_t step, size_t fill );908909/** An old crutch to keep old mpg123 binaries happy.910* WARNING: This function is there only to avoid runtime linking errors with911* standalone mpg123 before version 1.23.0 (if you strangely update the912* library but not the end-user program) and actually is broken913* for various cases (p.ex. 24 bit output). Do never use. It might eventually914* be purged from the library.915*/916MPG123_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);917918/*@}*/919920921/** \defgroup mpg123_voleq mpg123 volume and equalizer922*923* @{924*/925926/** another channel enumeration, for left/right choice */927enum mpg123_channels928{929MPG123_LEFT=0x1 /**< The Left Channel. */930,MPG123_RIGHT=0x2 /**< The Right Channel. */931,MPG123_LR=0x3 /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */932};933934/** Set the 32 Band Audio Equalizer settings.935* \param mh handle936* \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both.937* \param band The equaliser band to change (from 0 to 31)938* \param val The (linear) adjustment factor.939* \return MPG123_OK on success940*/941MPG123_EXPORT int mpg123_eq( mpg123_handle *mh942, enum mpg123_channels channel, int band, double val );943944/** Get the 32 Band Audio Equalizer settings.945* \param mh handle946* \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.947* \param band The equaliser band to change (from 0 to 31)948* \return The (linear) adjustment factor (zero for pad parameters) */949MPG123_EXPORT double mpg123_geteq(mpg123_handle *mh950, enum mpg123_channels channel, int band);951952/** Reset the 32 Band Audio Equalizer settings to flat953* \param mh handle954* \return MPG123_OK on success955*/956MPG123_EXPORT int mpg123_reset_eq(mpg123_handle *mh);957958/** Set the absolute output volume including the RVA setting,959* vol<0 just applies (a possibly changed) RVA setting.960* \param mh handle961* \param vol volume value (linear factor)962* \return MPG123_OK on success963*/964MPG123_EXPORT int mpg123_volume(mpg123_handle *mh, double vol);965966/** Adjust output volume including the RVA setting by chosen amount967* \param mh handle968* \param change volume value (linear factor increment)969* \return MPG123_OK on success970*/971MPG123_EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);972973/** Return current volume setting, the actual value due to RVA, and the RVA974* adjustment itself. It's all as double float value to abstract the sample975* format. The volume values are linear factors / amplitudes (not percent)976* and the RVA value is in decibels.977* \param mh handle978* \param base return address for base volume (linear factor)979* \param really return address for actual volume (linear factor)980* \param rva_db return address for RVA value (decibels)981* \return MPG123_OK on success982*/983MPG123_EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db);984985/* TODO: Set some preamp in addition / to replace internal RVA handling? */986987/*@}*/988989990/** \defgroup mpg123_status mpg123 status and information991*992* @{993*/994995/** Enumeration of the mode types of Variable Bitrate */996enum mpg123_vbr {997MPG123_CBR=0, /**< Constant Bitrate Mode (default) */998MPG123_VBR, /**< Variable Bitrate Mode */999MPG123_ABR /**< Average Bitrate Mode */1000};10011002/** Enumeration of the MPEG Versions */1003enum mpg123_version {1004MPG123_1_0=0, /**< MPEG Version 1.0 */1005MPG123_2_0, /**< MPEG Version 2.0 */1006MPG123_2_5 /**< MPEG Version 2.5 */1007};100810091010/** Enumeration of the MPEG Audio mode.1011* Only the mono mode has 1 channel, the others have 2 channels. */1012enum mpg123_mode {1013MPG123_M_STEREO=0, /**< Standard Stereo. */1014MPG123_M_JOINT, /**< Joint Stereo. */1015MPG123_M_DUAL, /**< Dual Channel. */1016MPG123_M_MONO /**< Single Channel. */1017};101810191020/** Enumeration of the MPEG Audio flag bits */1021enum mpg123_flags {1022MPG123_CRC=0x1, /**< The bitstream is error protected using 16-bit CRC. */1023MPG123_COPYRIGHT=0x2, /**< The bitstream is copyrighted. */1024MPG123_PRIVATE=0x4, /**< The private bit has been set. */1025MPG123_ORIGINAL=0x8 /**< The bitstream is an original, not a copy. */1026};10271028/** Data structure for storing information about a frame of MPEG Audio */1029struct mpg123_frameinfo1030{1031enum mpg123_version version; /**< The MPEG version (1.0/2.0/2.5). */1032int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */1033long rate; /**< The sampling rate in Hz. */1034enum mpg123_mode mode; /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */1035int mode_ext; /**< The mode extension bit flag. */1036int framesize; /**< The size of the frame (in bytes, including header). */1037enum 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. */1038int emphasis; /**< The emphasis type. */1039int bitrate; /**< Bitrate of the frame (kbps). */1040int abr_rate; /**< The target average bitrate. */1041enum mpg123_vbr vbr; /**< The VBR mode. */1042};10431044/** Data structure for even more detailed information out of the decoder,1045* for MPEG layer III only.1046* This was added to support the frame analyzer by the Lame project and1047* just follows what was used there before. You know what the fields mean1048* if you want use this structure. */1049struct mpg123_moreinfo1050{1051double xr[2][2][576];1052double sfb[2][2][22]; /* [2][2][SBMAX_l] */1053double sfb_s[2][2][3*13]; /* [2][2][3*SBMAX_s] */1054int qss[2][2];1055int big_values[2][2];1056int sub_gain[2][2][3];1057int scalefac_scale[2][2];1058int preflag[2][2];1059int blocktype[2][2];1060int mixed[2][2];1061int mainbits[2][2];1062int sfbits[2][2];1063int scfsi[2];1064int maindata;1065int padding;1066};10671068/** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure.1069* \param mh handle1070* \param mi address of existing frameinfo structure to write to1071* \return MPG123_OK on success1072*/1073MPG123_EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);10741075/** Trigger collection of additional decoder information while decoding.1076* \param mh handle1077* \param mi pointer to data storage (NULL to disable collection)1078* \return MPG123_OK if the collection was enabled/disabled as desired, MPG123_ERR1079* otherwise (e.g. if the feature is disabled)1080*/1081MPG123_EXPORT int mpg123_set_moreinfo( mpg123_handle *mh1082, struct mpg123_moreinfo *mi );10831084/** Get the safe output buffer size for all cases1085* (when you want to replace the internal buffer)1086* \return safe buffer size1087*/1088MPG123_EXPORT size_t mpg123_safe_buffer(void);10891090/** Make a full parsing scan of each frame in the file. ID3 tags are found. An1091* accurate length value is stored. Seek index will be filled. A seek back to1092* current position is performed. At all, this function refuses work when1093* stream is not seekable.1094* \param mh handle1095* \return MPG123_OK on success1096*/1097MPG123_EXPORT int mpg123_scan(mpg123_handle *mh);10981099/** Return, if possible, the full (expected) length of current track in1100* MPEG frames.1101* \param mh handle1102* \return length >= 0 or MPG123_ERR if there is no length guess possible.1103*/1104MPG123_EXPORT off_t mpg123_framelength(mpg123_handle *mh);11051106/** Return, if possible, the full (expected) length of current1107* track in samples (PCM frames).1108*1109* This relies either on an Info frame at the beginning or a previous1110* call to mpg123_scan() to get the real number of MPEG frames in a1111* file. It will guess based on file size if neither Info frame nor1112* scan data are present. In any case, there is no guarantee that the1113* decoder will not give you more data, for example in case the open1114* file gets appended to during decoding.1115* \param mh handle1116* \return length >= 0 or MPG123_ERR if there is no length guess possible.1117*/1118MPG123_EXPORT off_t mpg123_length(mpg123_handle *mh);11191120/** Override the value for file size in bytes.1121* Useful for getting sensible track length values in feed mode or for HTTP streams.1122* \param mh handle1123* \param size file size in bytes1124* \return MPG123_OK on success1125*/1126MPG123_EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size);11271128/** Get MPEG frame duration in seconds.1129* \param mh handle1130* \return frame duration in seconds, <0 on error1131*/1132MPG123_EXPORT double mpg123_tpf(mpg123_handle *mh);11331134/** Get MPEG frame duration in samples.1135* \param mh handle1136* \return samples per frame for the most recently parsed frame; <0 on errors1137*/1138MPG123_EXPORT int mpg123_spf(mpg123_handle *mh);11391140/** Get and reset the clip count.1141* \param mh handle1142* \return count of clipped samples1143*/1144MPG123_EXPORT long mpg123_clip(mpg123_handle *mh);114511461147/** The key values for state information from mpg123_getstate(). */1148enum mpg123_state1149{1150MPG123_ACCURATE = 1 /**< Query if positons are currently accurate (integer value, 0 if false, 1 if true). */1151,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. */1152,MPG123_FRANKENSTEIN /**< Stream consists of carelessly stitched together files. Seeking may yield unexpected results (also with MPG123_ACCURATE, it may be confused). */1153,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. */1154,MPG123_ENC_DELAY /** Encoder delay read from Info tag (layer III, -1 if unknown). */1155,MPG123_ENC_PADDING /** Encoder padding read from Info tag (layer III, -1 if unknown). */1156,MPG123_DEC_DELAY /** Decoder delay (for layer III only, -1 otherwise). */1157};11581159/** Get various current decoder/stream state information.1160* \param mh handle1161* \param key the key to identify the information to give.1162* \param val the address to return (long) integer values to1163* \param fval the address to return floating point values to1164* \return MPG123_OK on success1165*/1166MPG123_EXPORT int mpg123_getstate( mpg123_handle *mh1167, enum mpg123_state key, long *val, double *fval );11681169/*@}*/117011711172/** \defgroup mpg123_metadata mpg123 metadata handling1173*1174* Functions to retrieve the metadata from MPEG Audio files and streams.1175* Also includes string handling functions.1176*1177* @{1178*/11791180/** Data structure for storing strings in a safer way than a standard C-String.1181* Can also hold a number of null-terminated strings. */1182typedef struct1183{1184char* p; /**< pointer to the string data */1185size_t size; /**< raw number of bytes allocated */1186size_t fill; /**< number of used bytes (including closing zero byte) */1187} mpg123_string;11881189/** Allocate and intialize a new string.1190* \param val optional initial string value (can be NULL)1191*/1192MPG123_EXPORT mpg123_string* mpg123_new_string(const char* val);11931194/** Free memory of contents and the string structure itself.1195* \param sb string handle1196*/1197MPG123_EXPORT void mpg123_delete_string(mpg123_string* sb);11981199/** Initialize an existing mpg123_string structure to {NULL, 0, 0}.1200* If you hand in a NULL pointer here, your program should crash. The other1201* string functions are more forgiving, but this one here is too basic.1202* \param sb string handle (address of existing structure on your side)1203*/1204MPG123_EXPORT void mpg123_init_string(mpg123_string* sb);12051206/** Free-up memory of the contents of an mpg123_string (not the struct itself).1207* This also calls mpg123_init_string() and hence is safe to be called1208* repeatedly.1209* \param sb string handle1210*/1211MPG123_EXPORT void mpg123_free_string(mpg123_string* sb);12121213/** Change the size of a mpg123_string1214* \param sb string handle1215* \param news new size in bytes1216* \return 0 on error, 1 on success1217*/1218MPG123_EXPORT int mpg123_resize_string(mpg123_string* sb, size_t news);12191220/** Increase size of a mpg123_string if necessary (it may stay larger).1221* Note that the functions for adding and setting in current libmpg1231222* use this instead of mpg123_resize_string().1223* That way, you can preallocate memory and safely work afterwards with1224* pieces.1225* \param sb string handle1226* \param news new minimum size1227* \return 0 on error, 1 on success1228*/1229MPG123_EXPORT int mpg123_grow_string(mpg123_string* sb, size_t news);12301231/** Copy the contents of one mpg123_string string to another.1232* Yes the order of arguments is reversed compated to memcpy().1233* \param from string handle1234* \param to string handle1235* \return 0 on error, 1 on success1236*/1237MPG123_EXPORT int mpg123_copy_string(mpg123_string* from, mpg123_string* to);12381239/** Move the contents of one mpg123_string string to another.1240* This frees any memory associated with the target and moves over the1241* pointers from the source, leaving the source without content after1242* that. The only possible error is that you hand in NULL pointers.1243* If you handed in a valid source, its contents will be gone, even if1244* there was no target to move to. If you hand in a valid target, its1245* original contents will also always be gone, to be replaced with the1246* source's contents if there was some.1247* \param from source string handle1248* \param to target string handle1249* \return 0 on error, 1 on success1250*/1251MPG123_EXPORT int mpg123_move_string(mpg123_string* from, mpg123_string* to);12521253/** Append a C-String to an mpg123_string1254* \param sb string handle1255* \param stuff to append1256* \return 0 on error, 1 on success1257*/1258MPG123_EXPORT int mpg123_add_string(mpg123_string* sb, const char* stuff);12591260/** Append a C-substring to an mpg123 string1261* \param sb string handle1262* \param stuff content to copy1263* \param from offset to copy from1264* \param count number of characters to copy (a null-byte is always appended)1265* \return 0 on error, 1 on success1266*/1267MPG123_EXPORT int mpg123_add_substring( mpg123_string *sb1268, const char *stuff, size_t from, size_t count );12691270/** Set the content of a mpg123_string to a C-string1271* \param sb string handle1272* \param stuff content to copy1273* \return 0 on error, 1 on success1274*/1275MPG123_EXPORT int mpg123_set_string(mpg123_string* sb, const char* stuff);12761277/** Set the content of a mpg123_string to a C-substring1278* \param sb string handle1279* \param stuff the future content1280* \param from offset to copy from1281* \param count number of characters to copy (a null-byte is always appended)1282* \return 0 on error, 1 on success1283*/1284MPG123_EXPORT int mpg123_set_substring( mpg123_string *sb1285, const char *stuff, size_t from, size_t count );12861287/** Count characters in a mpg123 string (non-null bytes or Unicode points).1288* This function is of limited use, as it does just count code points1289* encoded in an UTF-8 string, only loosely related to the count of visible1290* characters. Get your full Unicode handling support elsewhere.1291* \param sb string handle1292* \param utf8 a flag to tell if the string is in utf8 encoding1293* \return character count1294*/1295MPG123_EXPORT size_t mpg123_strlen(mpg123_string *sb, int utf8);12961297/** Remove trailing \\r and \\n, if present.1298* \param sb string handle1299* \return 0 on error, 1 on success1300*/1301MPG123_EXPORT int mpg123_chomp_string(mpg123_string *sb);13021303/** Determine if two strings contain the same data.1304* This only returns 1 if both given handles are non-NULL and1305* if they are filled with the same bytes.1306* \param a first string handle1307* \param b second string handle1308* \return 0 for different strings, 1 for identical1309*/1310MPG123_EXPORT int mpg123_same_string(mpg123_string *a, mpg123_string *b);13111312/** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. */1313enum mpg123_text_encoding1314{1315mpg123_text_unknown = 0 /**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. */1316,mpg123_text_utf8 = 1 /**< UTF-8 */1317,mpg123_text_latin1 = 2 /**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. */1318,mpg123_text_icy = 3 /**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. */1319,mpg123_text_cp1252 = 4 /**< Really CP-1252 without any guessing. */1320,mpg123_text_utf16 = 5 /**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.1321* When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when1322* you don't mess with the reserved code points. If you want to decode little endian data1323* without BOM you need to prepend 0xff 0xfe yourself. */1324,mpg123_text_utf16bom = 6 /**< Just an alias for UTF-16, ID3v2 has this as distinct code. */1325,mpg123_text_utf16be = 7 /**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,1326* BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg1231327* One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF161328* types (we expect a BOM before real data there), not so for utf16be!*/1329,mpg123_text_max = 7 /**< Placeholder for the maximum encoding value. */1330};13311332/** The encoding byte values from ID3v2. */1333enum mpg123_id3_enc1334{1335mpg123_id3_latin1 = 0 /**< Note: This sometimes can mean anything in practice... */1336,mpg123_id3_utf16bom = 1 /**< UTF16, UCS-2 ... it's all the same for practical purposes. */1337,mpg123_id3_utf16be = 2 /**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. */1338,mpg123_id3_utf8 = 3 /**< Our lovely overly ASCII-compatible 8 byte encoding for the world. */1339,mpg123_id3_enc_max = 3 /**< Placeholder to check valid range of encoding byte. */1340};13411342/** Convert ID3 encoding byte to mpg123 encoding index.1343* \param id3_enc_byte the ID3 encoding code1344* \return the mpg123 encoding index1345*/13461347MPG123_EXPORT enum mpg123_text_encoding mpg123_enc_from_id3(unsigned char id3_enc_byte);13481349/** Store text data in string, after converting to UTF-8 from indicated encoding1350* 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).1351* Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).1352* \param sb target string1353* \param enc mpg123 text encoding value1354* \param source source buffer with plain unsigned bytes (you might need to cast from signed char)1355* \param source_size number of bytes in the source buffer1356* \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)1357*/1358MPG123_EXPORT int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size);13591360/** Sub data structure for ID3v2, for storing various text fields (including comments).1361* This is for ID3v2 COMM, TXXX and all the other text fields.1362* Only COMM, TXXX and USLT may have a description, only COMM and USLT1363* have a language.1364* You should consult the ID3v2 specification for the use of the various text fields1365* ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). */1366typedef struct1367{1368char lang[3]; /**< Three-letter language code (not terminated). */1369char id[4]; /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */1370mpg123_string description; /**< Empty for the generic comment... */1371mpg123_string text; /**< ... */1372} mpg123_text;13731374/** The picture type values from ID3v2. */1375enum mpg123_id3_pic_type1376{1377mpg123_id3_pic_other = 0 /**< see ID3v2 docs */1378,mpg123_id3_pic_icon = 1 /**< see ID3v2 docs */1379,mpg123_id3_pic_other_icon = 2 /**< see ID3v2 docs */1380,mpg123_id3_pic_front_cover = 3 /**< see ID3v2 docs */1381,mpg123_id3_pic_back_cover = 4 /**< see ID3v2 docs */1382,mpg123_id3_pic_leaflet = 5 /**< see ID3v2 docs */1383,mpg123_id3_pic_media = 6 /**< see ID3v2 docs */1384,mpg123_id3_pic_lead = 7 /**< see ID3v2 docs */1385,mpg123_id3_pic_artist = 8 /**< see ID3v2 docs */1386,mpg123_id3_pic_conductor = 9 /**< see ID3v2 docs */1387,mpg123_id3_pic_orchestra = 10 /**< see ID3v2 docs */1388,mpg123_id3_pic_composer = 11 /**< see ID3v2 docs */1389,mpg123_id3_pic_lyricist = 12 /**< see ID3v2 docs */1390,mpg123_id3_pic_location = 13 /**< see ID3v2 docs */1391,mpg123_id3_pic_recording = 14 /**< see ID3v2 docs */1392,mpg123_id3_pic_performance = 15 /**< see ID3v2 docs */1393,mpg123_id3_pic_video = 16 /**< see ID3v2 docs */1394,mpg123_id3_pic_fish = 17 /**< see ID3v2 docs */1395,mpg123_id3_pic_illustration = 18 /**< see ID3v2 docs */1396,mpg123_id3_pic_artist_logo = 19 /**< see ID3v2 docs */1397,mpg123_id3_pic_publisher_logo = 20 /**< see ID3v2 docs */1398};13991400/** Sub data structure for ID3v2, for storing picture data including comment.1401* This is for the ID3v2 APIC field. You should consult the ID3v2 specification1402* for the use of the APIC field ("frames" in ID3v2 documentation, I use "fields"1403* here to separate from MPEG frames). */1404typedef struct1405{1406char type; /**< mpg123_id3_pic_type value */1407mpg123_string description; /**< description string */1408mpg123_string mime_type; /**< MIME type */1409size_t size; /**< size in bytes */1410unsigned char* data; /**< pointer to the image data */1411} mpg123_picture;14121413/** Data structure for storing IDV3v2 tags.1414* This structure is not a direct binary mapping with the file contents.1415* The ID3v2 text frames are allowed to contain multiple strings.1416* So check for null bytes until you reach the mpg123_string fill.1417* All text is encoded in UTF-8. */1418typedef struct1419{1420unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */1421mpg123_string *title; /**< Title string (pointer into text_list). */1422mpg123_string *artist; /**< Artist string (pointer into text_list). */1423mpg123_string *album; /**< Album string (pointer into text_list). */1424mpg123_string *year; /**< The year as a string (pointer into text_list). */1425mpg123_string *genre; /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */1426mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */1427/* Encountered ID3v2 fields are appended to these lists.1428There can be multiple occurences, the pointers above always point to the last encountered data. */1429mpg123_text *comment_list; /**< Array of comments. */1430size_t comments; /**< Number of comments. */1431mpg123_text *text; /**< Array of ID3v2 text fields (including USLT) */1432size_t texts; /**< Numer of text fields. */1433mpg123_text *extra; /**< The array of extra (TXXX) fields. */1434size_t extras; /**< Number of extra text (TXXX) fields. */1435mpg123_picture *picture; /**< Array of ID3v2 pictures fields (APIC).1436Only populated if MPG123_PICTURE flag is set! */1437size_t pictures; /**< Number of picture (APIC) fields. */1438} mpg123_id3v2;14391440/** Data structure for ID3v1 tags (the last 128 bytes of a file).1441* Don't take anything for granted (like string termination)!1442* Also note the change ID3v1.1 did: comment[28] = 0; comment[29] = track_number1443* It is your task to support ID3v1 only or ID3v1.1 ...*/1444typedef struct1445{1446char tag[3]; /**< Always the string "TAG", the classic intro. */1447char title[30]; /**< Title string. */1448char artist[30]; /**< Artist string. */1449char album[30]; /**< Album string. */1450char year[4]; /**< Year string. */1451char comment[30]; /**< Comment string. */1452unsigned char genre; /**< Genre index. */1453} mpg123_id3v1;14541455#define MPG123_ID3 0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */1456#define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */1457#define MPG123_ICY 0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/1458#define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */14591460/** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).1461* \param mh handle1462* \return combination of flags, 0 on error (same as "nothing new")1463*/1464MPG123_EXPORT int mpg123_meta_check(mpg123_handle *mh);14651466/** Clean up meta data storage (ID3v2 and ICY), freeing memory.1467* \param mh handle1468*/1469MPG123_EXPORT void mpg123_meta_free(mpg123_handle *mh);14701471/** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.1472* v1 and/or v2 can be set to NULL when there is no corresponding data.1473* \return MPG123_OK on success1474*/1475MPG123_EXPORT int mpg123_id3( mpg123_handle *mh1476, mpg123_id3v1 **v1, mpg123_id3v2 **v2 );14771478/** Return pointers to and size of stored raw ID3 data if storage has1479* been configured with MPG123_RAW_ID3 and stream parsing passed the1480* metadata already. Null value with zero size is a possibility!1481* The storage can change at any next API call.1482* \param v1 address to store pointer to v1 tag1483* \param v1_size size of v1 data in bytes1484* \param v2 address to store pointer to v2 tag1485* \param v2_size size of v2 data in bytes1486* \return MPG123_OK or MPG123_ERR. Only on MPG123_OK the output1487* values are set.1488*/1489MPG123_EXPORT int mpg123_id3_raw( mpg123_handle *mh1490, unsigned char **v1, size_t *v1_size1491, unsigned char **v2, size_t *v2_size );14921493/** Point icy_meta to existing data structure wich may change on any next read/decode function call.1494* \param mh handle1495* \param icy_meta return address for ICY meta string (set to NULL if nothing there)1496* \return MPG123_OK on success1497*/1498MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta);14991500/** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.1501* Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .1502* \param icy_text The input data in ICY encoding1503* \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */1504MPG123_EXPORT char* mpg123_icy2utf8(const char* icy_text);150515061507/* @} */150815091510/** \defgroup mpg123_advpar mpg123 advanced parameter API1511*1512* Direct access to a parameter set without full handle around it.1513* Possible uses:1514* - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).1515* - Use one set of parameters for multiple handles.1516*1517* The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()1518* family) directly return a fully qualified mpg123 error code, the ones1519* operating on full handles normally MPG123_OK or MPG123_ERR, storing the1520* specific error code itseld inside the handle.1521*1522* @{1523*/15241525/** Opaque structure for the libmpg123 decoder parameters. */1526struct mpg123_pars_struct;15271528/** Opaque structure for the libmpg123 decoder parameters. */1529typedef struct mpg123_pars_struct mpg123_pars;15301531/** Create a handle with preset parameters.1532* \param mp parameter handle1533* \param decoder decoder choice1534* \param error error code return address1535* \return mpg123 handle1536*/1537MPG123_EXPORT mpg123_handle *mpg123_parnew( mpg123_pars *mp1538, const char* decoder, int *error );15391540/** Allocate memory for and return a pointer to a new mpg123_pars1541* \param error error code return address1542* \return new parameter handle1543*/1544MPG123_EXPORT mpg123_pars *mpg123_new_pars(int *error);15451546/** Delete and free up memory used by a mpg123_pars data structure1547* \param mp parameter handle1548*/1549MPG123_EXPORT void mpg123_delete_pars(mpg123_pars* mp);15501551/** Configure mpg123 parameters to accept no output format at all,1552* use before specifying supported formats with mpg123_format1553* \param mp parameter handle1554* \return MPG123_OK on success1555*/1556MPG123_EXPORT int mpg123_fmt_none(mpg123_pars *mp);15571558/** Configure mpg123 parameters to accept all formats1559* (also any custom rate you may set) -- this is default.1560* \param mp parameter handle1561* \return MPG123_OK on success1562*/1563MPG123_EXPORT int mpg123_fmt_all(mpg123_pars *mp);15641565/** Set the audio format support of a mpg123_pars in detail:1566* \param mp parameter handle1567* \param rate The sample rate value (in Hertz).1568* \param channels A combination of MPG123_STEREO and MPG123_MONO.1569* \param encodings A combination of accepted encodings for rate and channels,1570* p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no1571* support).1572* \return MPG123_OK on success1573*/1574MPG123_EXPORT int mpg123_fmt(mpg123_pars *mp1575, long rate, int channels, int encodings);15761577/** Set the audio format support of a mpg123_pars in detail:1578* \param mp parameter handle1579* \param rate The sample rate value (in Hertz). Special value 0 means1580* all rates (reason for this variant of mpg123_fmt).1581* \param channels A combination of MPG123_STEREO and MPG123_MONO.1582* \param encodings A combination of accepted encodings for rate and channels,1583* p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no1584* support).1585* \return MPG123_OK on success1586*/1587MPG123_EXPORT int mpg123_fmt2(mpg123_pars *mp1588, long rate, int channels, int encodings);15891590/** Check to see if a specific format at a specific rate is supported1591* by mpg123_pars.1592* \param mp parameter handle1593* \param rate sampling rate1594* \param encoding encoding1595* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,1596* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */1597MPG123_EXPORT int mpg123_fmt_support(mpg123_pars *mp, long rate, int encoding);15981599/** Set a specific parameter, for a specific mpg123_pars, using a parameter1600* type key chosen from the mpg123_parms enumeration, to the specified value.1601* \param mp parameter handle1602* \param type parameter choice1603* \param value integer value1604* \param fvalue floating point value1605* \return MPG123_OK on success1606*/1607MPG123_EXPORT int mpg123_par( mpg123_pars *mp1608, enum mpg123_parms type, long value, double fvalue );16091610/** Get a specific parameter, for a specific mpg123_pars.1611* See the mpg123_parms enumeration for a list of available parameters.1612* \param mp parameter handle1613* \param type parameter choice1614* \param value integer value return address1615* \param fvalue floating point value return address1616* \return MPG123_OK on success1617*/1618MPG123_EXPORT int mpg123_getpar( mpg123_pars *mp1619, enum mpg123_parms type, long *value, double *fvalue);16201621/* @} */162216231624/** \defgroup mpg123_lowio mpg123 low level I/O1625* 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...1626*1627* @{ */16281629/** Replace default internal buffer with user-supplied buffer.1630* Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio.1631* Note that the required buffer size could be bigger than expected from output1632* encoding if libmpg123 has to convert from primary decoder output (p.ex. 32 bit1633* storage for 24 bit output).1634*1635* Note: The type of data changed to a void pointer in mpg123 1.26.01636* (API version 45).1637*1638* \param mh handle1639* \param data pointer to user buffer1640* \param size of buffer in bytes1641* \return MPG123_OK on success1642*/1643MPG123_EXPORT int mpg123_replace_buffer(mpg123_handle *mh1644, void *data, size_t size);16451646/** The max size of one frame's decoded output with current settings.1647* Use that to determine an appropriate minimum buffer size for decoding one frame.1648* \param mh handle1649* \return maximum decoded data size in bytes1650*/1651MPG123_EXPORT size_t mpg123_outblock(mpg123_handle *mh);16521653/** Replace low-level stream access functions; read and lseek as known in POSIX.1654* You can use this to make any fancy file opening/closing yourself,1655* using mpg123_open_fd() to set the file descriptor for your read/lseek1656* (doesn't need to be a "real" file descriptor...).1657* Setting a function to NULL means that the default internal read is1658* used (active from next mpg123_open call on).1659* Note: As it would be troublesome to mess with this while having a file open,1660* this implies mpg123_close().1661* \param mh handle1662* \param r_read callback for reading (behaviour like POSIX read)1663* \param r_lseek callback for seeking (like POSIX lseek)1664* \return MPG123_OK on success1665*/1666MPG123_EXPORT int mpg123_replace_reader( mpg123_handle *mh1667, ssize_t (*r_read) (int, void *, size_t)1668, off_t (*r_lseek)(int, off_t, int)1669);16701671/** Replace I/O functions with your own ones operating on some kind of1672* handle instead of integer descriptors.1673* The handle is a void pointer, so you can pass any data you want...1674* mpg123_open_handle() is the call you make to use the I/O defined here.1675* There is no fallback to internal read/seek here.1676* Note: As it would be troublesome to mess with this while having a file open,1677* this mpg123_close() is implied here.1678* \param mh handle1679* \param r_read callback for reading (behaviour like POSIX read)1680* \param r_lseek callback for seeking (like POSIX lseek)1681* \param cleanup A callback to clean up an I/O handle on mpg123_close,1682* can be NULL for none (you take care of cleaning your handles).1683* \return MPG123_OK on success1684*/1685MPG123_EXPORT int mpg123_replace_reader_handle( mpg123_handle *mh1686, ssize_t (*r_read) (void *, void *, size_t)1687, off_t (*r_lseek)(void *, off_t, int)1688, void (*cleanup)(void*) );16891690/* @} */16911692#ifdef __cplusplus1693}1694#endif16951696#endif169716981699