/*1libmpg123: MPEG Audio Decoder library23separate header just for audio format definitions not tied to4library code56copyright 1995-2020 by the mpg123 project7free software under the terms of the LGPL 2.18see COPYING and AUTHORS files in distribution or http://mpg123.org9*/1011#ifndef MPG123_ENC_H12#define MPG123_ENC_H1314/** \file fmt123.h Audio format definitions. */1516/** \defgroup mpg123_enc mpg123 PCM sample encodings17* These are definitions for audio formats used by libmpg123 and18* libout123.19*20* @{21*/2223/** An enum over all sample types possibly known to mpg123.24* The values are designed as bit flags to allow bitmasking for encoding25* families.26* This is also why the enum is not used as type for actual encoding variables,27* plain integers (at least 16 bit, 15 bit being used) cover the possible28* combinations of these flags.29*30* Note that (your build of) libmpg123 does not necessarily support all these.31* Usually, you can expect the 8bit encodings and signed 16 bit.32* Also 32bit float will be usual beginning with mpg123-1.7.0 .33* What you should bear in mind is that (SSE, etc) optimized routines may be34* absent for some formats. We do have SSE for 16, 32 bit and float, though.35* 24 bit integer is done via postprocessing of 32 bit output -- just cutting36* the last byte, no rounding, even. If you want better, do it yourself.37*38* All formats are in native byte order. If you need different endinaness, you39* can simply postprocess the output buffers (libmpg123 wouldn't do anything40* else). The macro MPG123_SAMPLESIZE() can be helpful there.41*/42enum mpg123_enc_enum43{44/* 0000 0000 0000 1111 Some 8 bit integer encoding. */45MPG123_ENC_8 = 0x00f46/* 0000 0000 0100 0000 Some 16 bit integer encoding. */47, MPG123_ENC_16 = 0x04048/* 0100 0000 0000 0000 Some 24 bit integer encoding. */49, MPG123_ENC_24 = 0x400050/* 0000 0001 0000 0000 Some 32 bit integer encoding. */51, MPG123_ENC_32 = 0x10052/* 0000 0000 1000 0000 Some signed integer encoding. */53, MPG123_ENC_SIGNED = 0x08054/* 0000 1110 0000 0000 Some float encoding. */55, MPG123_ENC_FLOAT = 0xe0056/* 0000 0000 1101 0000 signed 16 bit */57, MPG123_ENC_SIGNED_16 = (MPG123_ENC_16|MPG123_ENC_SIGNED|0x10)58/* 0000 0000 0110 0000 unsigned 16 bit */59, MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16|0x20)60/* 0000 0000 0000 0001 unsigned 8 bit */61, MPG123_ENC_UNSIGNED_8 = 0x0162/* 0000 0000 1000 0010 signed 8 bit */63, MPG123_ENC_SIGNED_8 = (MPG123_ENC_SIGNED|0x02)64/* 0000 0000 0000 0100 ulaw 8 bit */65, MPG123_ENC_ULAW_8 = 0x0466/* 0000 0000 0000 1000 alaw 8 bit */67, MPG123_ENC_ALAW_8 = 0x0868/* 0001 0001 1000 0000 signed 32 bit */69, MPG123_ENC_SIGNED_32 = MPG123_ENC_32|MPG123_ENC_SIGNED|0x100070/* 0010 0001 0000 0000 unsigned 32 bit */71, MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32|0x200072/* 0101 0000 1000 0000 signed 24 bit */73, MPG123_ENC_SIGNED_24 = MPG123_ENC_24|MPG123_ENC_SIGNED|0x100074/* 0110 0000 0000 0000 unsigned 24 bit */75, MPG123_ENC_UNSIGNED_24 = MPG123_ENC_24|0x200076/* 0000 0010 0000 0000 32bit float */77, MPG123_ENC_FLOAT_32 = 0x20078/* 0000 0100 0000 0000 64bit float */79, MPG123_ENC_FLOAT_64 = 0x40080/* Any possibly known encoding from the list above. */81, MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16 | MPG123_ENC_UNSIGNED_1682| MPG123_ENC_UNSIGNED_8 | MPG123_ENC_SIGNED_883| MPG123_ENC_ULAW_8 | MPG123_ENC_ALAW_884| MPG123_ENC_SIGNED_32 | MPG123_ENC_UNSIGNED_3285| MPG123_ENC_SIGNED_24 | MPG123_ENC_UNSIGNED_2486| MPG123_ENC_FLOAT_32 | MPG123_ENC_FLOAT_64 )87};8889/** Get size of one PCM sample with given encoding.90* This is included both in libmpg123 and libout123. Both offer91* an API function to provide the macro results from library92* compile-time, not that of you application. This most likely93* does not matter as I do not expect any fresh PCM sample94* encoding to appear. But who knows? Perhaps the encoding type95* will be abused for funny things in future, not even plain PCM.96* And, by the way: Thomas really likes the ?: operator.97* \param enc the encoding (mpg123_enc_enum value)98* \return size of one sample in bytes99*/100#define MPG123_SAMPLESIZE(enc) ( \101(enc) < 1 \102? 0 \103: ( (enc) & MPG123_ENC_8 \104? 1 \105: ( (enc) & MPG123_ENC_16 \106? 2 \107: ( (enc) & MPG123_ENC_24 \108? 3 \109: ( ( (enc) & MPG123_ENC_32 \110|| (enc) == MPG123_ENC_FLOAT_32 ) \111? 4 \112: ( (enc) == MPG123_ENC_FLOAT_64 \113? 8 \114: 0 \115) ) ) ) ) )116117/** Representation of zero in differing encodings.118* This exists to define proper silence in various encodings without119* having to link to libsyn123 to do actual conversions at runtime.120* You have to handle big/little endian order yourself, though.121* This takes the shortcut that any signed encoding has a zero with122* all-zero bits. Unsigned linear encodings just have the highest bit set123* (2^(n-1) for n bits), while the nonlinear 8-bit ones are special.124* \param enc the encoding (mpg123_enc_enum value)125* \param siz bytes per sample (return value of MPG123_SAMPLESIZE(enc))126* \param off byte (octet) offset counted from LSB127* \return unsigned byte value for the designated octet128*/129#define MPG123_ZEROSAMPLE(enc, siz, off) ( \130(enc) == MPG123_ENC_ULAW_8 \131? (off == 0 ? 0xff : 0x00) \132: ( (enc) == MPG123_ENC_ALAW_8 \133? (off == 0 ? 0xd5 : 0x00) \134: ( (((enc) & (MPG123_ENC_SIGNED|MPG123_ENC_FLOAT)) || (siz) != ((off)+1)) \135? 0x00 \136: 0x80 \137) ) )138139/** Structure defining an audio format.140* Providing the members as individual function arguments to define a certain141* output format is easy enough. This struct makes is more comfortable to deal142* with a list of formats.143* Negative values for the members might be used to communicate use of default144* values.145*/146struct mpg123_fmt147{148long rate; /**< sampling rate in Hz */149int channels; /**< channel count */150/** encoding code, can be single value or bitwise or of members of151* mpg123_enc_enum */152int encoding;153};154155/** @} */156157#endif158159160