Blame src/libmpg123/fmt123.h

Packit c32a2d
/*
Packit c32a2d
	libmpg123: MPEG Audio Decoder library
Packit c32a2d
Packit c32a2d
	separate header just for audio format definitions not tied to
Packit c32a2d
	library code
Packit c32a2d
Packit c32a2d
	copyright 1995-2015 by the mpg123 project
Packit c32a2d
	free software under the terms of the LGPL 2.1
Packit c32a2d
	see COPYING and AUTHORS files in distribution or http://mpg123.org
Packit c32a2d
*/
Packit c32a2d
Packit c32a2d
#ifndef MPG123_ENC_H
Packit c32a2d
#define MPG123_ENC_H
Packit c32a2d
Packit c32a2d
/** \file fmt123.h Audio format definitions. */
Packit c32a2d
Packit c32a2d
/** \defgroup mpg123_enc mpg123 PCM sample encodings
Packit c32a2d
 *  These are definitions for audio formats used by libmpg123 and
Packit c32a2d
 *  libout123.
Packit c32a2d
 *
Packit c32a2d
 * @{
Packit c32a2d
 */
Packit c32a2d
Packit c32a2d
/** An enum over all sample types possibly known to mpg123.
Packit c32a2d
 *  The values are designed as bit flags to allow bitmasking for encoding
Packit c32a2d
 *  families.
Packit c32a2d
 *  This is also why the enum is not used as type for actual encoding variables,
Packit c32a2d
 *  plain integers (at least 16 bit, 15 bit being used) cover the possible
Packit c32a2d
 *  combinations of these flags.
Packit c32a2d
 *
Packit c32a2d
 *  Note that (your build of) libmpg123 does not necessarily support all these.
Packit c32a2d
 *  Usually, you can expect the 8bit encodings and signed 16 bit.
Packit c32a2d
 *  Also 32bit float will be usual beginning with mpg123-1.7.0 .
Packit c32a2d
 *  What you should bear in mind is that (SSE, etc) optimized routines may be
Packit c32a2d
 *  absent for some formats. We do have SSE for 16, 32 bit and float, though.
Packit c32a2d
 *  24 bit integer is done via postprocessing of 32 bit output -- just cutting
Packit c32a2d
 *  the last byte, no rounding, even. If you want better, do it yourself.
Packit c32a2d
 *
Packit c32a2d
 *  All formats are in native byte order. If you need different endinaness, you
Packit c32a2d
 *  can simply postprocess the output buffers (libmpg123 wouldn't do anything
Packit c32a2d
 * else). The macro MPG123_SAMPLESIZE() can be helpful there.
Packit c32a2d
 */
Packit c32a2d
enum mpg123_enc_enum
Packit c32a2d
{
Packit c32a2d
/* 0000 0000 0000 1111 Some 8 bit  integer encoding. */
Packit c32a2d
	MPG123_ENC_8      = 0x00f
Packit c32a2d
/* 0000 0000 0100 0000 Some 16 bit integer encoding. */
Packit c32a2d
,	MPG123_ENC_16     = 0x040
Packit c32a2d
/* 0100 0000 0000 0000 Some 24 bit integer encoding. */
Packit c32a2d
,	MPG123_ENC_24     = 0x4000 
Packit c32a2d
/* 0000 0001 0000 0000 Some 32 bit integer encoding. */
Packit c32a2d
,	MPG123_ENC_32     = 0x100  
Packit c32a2d
/* 0000 0000 1000 0000 Some signed integer encoding. */
Packit c32a2d
,	MPG123_ENC_SIGNED = 0x080  
Packit c32a2d
/* 0000 1110 0000 0000 Some float encoding. */
Packit c32a2d
,	MPG123_ENC_FLOAT  = 0xe00  
Packit c32a2d
/* 0000 0000 1101 0000 signed 16 bit */
Packit c32a2d
,	MPG123_ENC_SIGNED_16   = (MPG123_ENC_16|MPG123_ENC_SIGNED|0x10)
Packit c32a2d
/* 0000 0000 0110 0000 unsigned 16 bit */
Packit c32a2d
,	MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16|0x20)
Packit c32a2d
/* 0000 0000 0000 0001 unsigned 8 bit */
Packit c32a2d
,	MPG123_ENC_UNSIGNED_8  = 0x01
Packit c32a2d
/* 0000 0000 1000 0010 signed 8 bit */
Packit c32a2d
,	MPG123_ENC_SIGNED_8    = (MPG123_ENC_SIGNED|0x02)
Packit c32a2d
/* 0000 0000 0000 0100 ulaw 8 bit */
Packit c32a2d
,	MPG123_ENC_ULAW_8      = 0x04
Packit c32a2d
/* 0000 0000 0000 1000 alaw 8 bit */
Packit c32a2d
,	MPG123_ENC_ALAW_8      = 0x08
Packit c32a2d
/* 0001 0001 1000 0000 signed 32 bit */
Packit c32a2d
,	MPG123_ENC_SIGNED_32   = MPG123_ENC_32|MPG123_ENC_SIGNED|0x1000
Packit c32a2d
/* 0010 0001 0000 0000 unsigned 32 bit */
Packit c32a2d
,	MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32|0x2000
Packit c32a2d
/* 0101 0000 1000 0000 signed 24 bit */
Packit c32a2d
,	MPG123_ENC_SIGNED_24   = MPG123_ENC_24|MPG123_ENC_SIGNED|0x1000
Packit c32a2d
/* 0110 0000 0000 0000 unsigned 24 bit */
Packit c32a2d
,	MPG123_ENC_UNSIGNED_24 = MPG123_ENC_24|0x2000
Packit c32a2d
/* 0000 0010 0000 0000 32bit float */
Packit c32a2d
,	MPG123_ENC_FLOAT_32    = 0x200
Packit c32a2d
/* 0000 0100 0000 0000 64bit float */
Packit c32a2d
,	MPG123_ENC_FLOAT_64    = 0x400
Packit c32a2d
/* Any possibly known encoding from the list above. */
Packit c32a2d
,	MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16  | MPG123_ENC_UNSIGNED_16
Packit c32a2d
	                 | MPG123_ENC_UNSIGNED_8 | MPG123_ENC_SIGNED_8
Packit c32a2d
	                 | MPG123_ENC_ULAW_8     | MPG123_ENC_ALAW_8
Packit c32a2d
	                 | MPG123_ENC_SIGNED_32  | MPG123_ENC_UNSIGNED_32
Packit c32a2d
	                 | MPG123_ENC_SIGNED_24  | MPG123_ENC_UNSIGNED_24
Packit c32a2d
	                 | MPG123_ENC_FLOAT_32   | MPG123_ENC_FLOAT_64    )
Packit c32a2d
};
Packit c32a2d
Packit c32a2d
/** Get size of one PCM sample with given encoding.
Packit c32a2d
 *  This is included both in libmpg123 and libout123. Both offer
Packit c32a2d
 *  an API function to provide the macro results from library
Packit c32a2d
 *  compile-time, not that of you application. This most likely
Packit c32a2d
 *  does not matter as I do not expect any fresh PCM sample
Packit c32a2d
 *  encoding to appear. But who knows? Perhaps the encoding type
Packit c32a2d
 *  will be abused for funny things in future, not even plain PCM.
Packit c32a2d
 *  And, by the way: Thomas really likes the ?: operator.
Packit c32a2d
 * \param enc the encoding (mpg123_enc_enum value)
Packit c32a2d
 * \return size of one sample in bytes
Packit c32a2d
 */
Packit c32a2d
#define MPG123_SAMPLESIZE(enc) ( \
Packit c32a2d
	(enc) & MPG123_ENC_8 \
Packit c32a2d
	?	1 \
Packit c32a2d
	:	( (enc) & MPG123_ENC_16 \
Packit c32a2d
		?	2 \
Packit c32a2d
		:	( (enc) & MPG123_ENC_24 \
Packit c32a2d
			?	3 \
Packit c32a2d
			:	( (  (enc) & MPG123_ENC_32 \
Packit c32a2d
				  || (enc) == MPG123_ENC_FLOAT_32 ) \
Packit c32a2d
				?	4 \
Packit c32a2d
				:	( (enc) == MPG123_ENC_FLOAT_64 \
Packit c32a2d
					?	8 \
Packit c32a2d
					:	0 \
Packit c32a2d
)	)	)	)	)
Packit c32a2d
Packit c32a2d
/** Structure defining an audio format.
Packit c32a2d
 *  Providing the members as individual function arguments to define a certain
Packit c32a2d
 *  output format is easy enough. This struct makes is more comfortable to deal
Packit c32a2d
 *  with a list of formats.
Packit c32a2d
 *  Negative values for the members might be used to communicate use of default
Packit c32a2d
 *  values.
Packit c32a2d
 */
Packit c32a2d
struct mpg123_fmt
Packit c32a2d
{
Packit c32a2d
	long rate;    /**< sampling rate in Hz  */
Packit c32a2d
	int channels; /**< channel count */
Packit c32a2d
	/** encoding code, can be single value or bitwise or of members of
Packit c32a2d
	 *  mpg123_enc_enum */
Packit c32a2d
	int encoding;
Packit c32a2d
};
Packit c32a2d
Packit c32a2d
/* @} */
Packit c32a2d
Packit c32a2d
#endif
Packit c32a2d