summaryrefslogtreecommitdiff
path: root/contrib/libmpcdec/mpcdec
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libmpcdec/mpcdec')
-rw-r--r--contrib/libmpcdec/mpcdec/config_types.h50
-rw-r--r--contrib/libmpcdec/mpcdec/decoder.h124
-rw-r--r--contrib/libmpcdec/mpcdec/huffman.h58
-rw-r--r--contrib/libmpcdec/mpcdec/internal.h65
-rw-r--r--contrib/libmpcdec/mpcdec/math.h144
-rw-r--r--contrib/libmpcdec/mpcdec/mpcdec.h145
-rw-r--r--contrib/libmpcdec/mpcdec/reader.h82
-rw-r--r--contrib/libmpcdec/mpcdec/requant.h51
-rw-r--r--contrib/libmpcdec/mpcdec/streaminfo.h91
9 files changed, 810 insertions, 0 deletions
diff --git a/contrib/libmpcdec/mpcdec/config_types.h b/contrib/libmpcdec/mpcdec/config_types.h
new file mode 100644
index 000000000..98c6cf21b
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/config_types.h
@@ -0,0 +1,50 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __MUSEPACK_CONFIG_TYPES_H__
+#define __MUSEPACK_CONFIG_TYPES_H__
+
+#include <xine/os_types.h>
+
+typedef unsigned char mpc_bool_t;
+#define TRUE 1
+#define FALSE 0
+
+typedef int16_t mpc_int16_t;
+typedef uint16_t mpc_uint16_t;
+typedef int32_t mpc_int32_t;
+typedef uint32_t mpc_uint32_t;
+typedef int64_t mpc_int64_t;
+
+#endif // __MUSEPACK_CONFIG_TYPES_H__
diff --git a/contrib/libmpcdec/mpcdec/decoder.h b/contrib/libmpcdec/mpcdec/decoder.h
new file mode 100644
index 000000000..9a737453e
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/decoder.h
@@ -0,0 +1,124 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file decoder.h
+
+#ifndef _mpcdec_decoder_h_
+#define _mpcdec_decoder_h_
+
+#include "huffman.h"
+#include "math.h"
+#include "mpcdec.h"
+#include "reader.h"
+#include "streaminfo.h"
+
+#define MPC_SUPPORT_SV456
+
+#define SEEKING_TABLE_SIZE 256u
+// set it to SLOW_SEEKING_WINDOW to not use fast seeking
+#define FAST_SEEKING_WINDOW 32
+// set it to FAST_SEEKING_WINDOW to only use fast seeking
+#define SLOW_SEEKING_WINDOW 0x80000000
+
+enum {
+ MPC_V_MEM = 2304,
+ MPC_DECODER_MEMSIZE = 16384, // overall buffer size
+};
+
+typedef struct {
+ mpc_int32_t L [36];
+ mpc_int32_t R [36];
+} QuantTyp;
+
+typedef struct mpc_decoder_t {
+ mpc_reader *r;
+
+ /// @name internal state variables
+ //@{
+
+ mpc_uint32_t dword; /// currently decoded 32bit-word
+ mpc_uint32_t pos; /// bit-position within dword
+ mpc_uint32_t Speicher[MPC_DECODER_MEMSIZE]; /// read-buffer
+ mpc_uint32_t Zaehler; /// actual index within read-buffer
+
+ mpc_uint32_t samples_to_skip;
+
+ mpc_uint32_t DecodedFrames;
+ mpc_uint32_t OverallFrames;
+ mpc_int32_t SampleRate; // Sample frequency
+
+ mpc_uint32_t StreamVersion; // version of bitstream
+ mpc_int32_t Max_Band;
+ mpc_uint32_t MPCHeaderPos; // AB: needed to support ID3v2
+
+ mpc_uint32_t FrameWasValid;
+ mpc_uint32_t MS_used; // MS-coding used ?
+ mpc_uint32_t TrueGaplessPresent;
+
+ mpc_uint32_t WordsRead; // counts amount of decoded dwords
+
+ // randomizer state variables
+ mpc_uint32_t __r1;
+ mpc_uint32_t __r2;
+
+ // seeking
+ mpc_uint32_t seeking_table[SEEKING_TABLE_SIZE];
+ mpc_uint32_t seeking_pwr; // distance between 2 frames in seeking_table = 2^seeking_pwr
+ mpc_uint32_t seeking_table_frames; // last frame in seaking table
+ mpc_uint32_t seeking_window; // number of frames to look for scalefactors
+
+ mpc_int32_t SCF_Index_L [32] [3];
+ mpc_int32_t SCF_Index_R [32] [3]; // holds scalefactor-indices
+ QuantTyp Q [32]; // holds quantized samples
+ mpc_int32_t Res_L [32];
+ mpc_int32_t Res_R [32]; // holds the chosen quantizer for each subband
+ mpc_bool_t DSCF_Flag_L [32];
+ mpc_bool_t DSCF_Flag_R [32]; // differential SCF used?
+ mpc_int32_t SCFI_L [32];
+ mpc_int32_t SCFI_R [32]; // describes order of transmitted SCF
+ mpc_bool_t MS_Flag[32]; // MS used?
+#ifdef MPC_FIXED_POINT
+ unsigned char SCF_shift[256];
+#endif
+
+ MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960];
+ MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960];
+ MPC_SAMPLE_FORMAT Y_L[36][32];
+ MPC_SAMPLE_FORMAT Y_R[36][32];
+ MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention)
+ //@}
+
+} mpc_decoder;
+
+#endif // _mpc_decoder_h
diff --git a/contrib/libmpcdec/mpcdec/huffman.h b/contrib/libmpcdec/mpcdec/huffman.h
new file mode 100644
index 000000000..99d02ce71
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/huffman.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file huffman.h
+/// Data structures and functions for huffman coding.
+
+#ifndef _mpcdec_huffman_h_
+#define _mpcdec_huffman_h_
+
+#ifndef WIN32
+#include "mpcdec/config_types.h"
+#else
+#include "mpcdec/config_win32.h"
+#endif
+
+#include "decoder.h"
+
+struct mpc_decoder_t; // forward declare to break circular dependencies
+
+/// Huffman table entry.
+typedef struct huffman_type_t {
+ mpc_uint32_t Code;
+ mpc_uint16_t Length;
+ mpc_int16_t Value;
+} HuffmanTyp;
+
+#endif // _mpcdec_huffman_h_
diff --git a/contrib/libmpcdec/mpcdec/internal.h b/contrib/libmpcdec/mpcdec/internal.h
new file mode 100644
index 000000000..19642a240
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/internal.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file internal.h
+/// Definitions and structures used only internally by the libmpcdec.
+
+#ifndef _mpcdec_internal_h
+#define _mpcdec_internal_h
+
+
+enum {
+ MPC_DECODER_SYNTH_DELAY = 481
+};
+
+/// Big/little endian 32 bit byte swapping routine.
+static __inline
+mpc_uint32_t mpc_swap32(mpc_uint32_t val) {
+ return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) |
+ ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
+}
+
+/// Searches for a ID3v2-tag and reads the length (in bytes) of it.
+/// \param reader supplying raw stream data
+/// \return size of tag, in bytes
+/// \return -1 on errors of any kind
+mpc_int32_t JumpID3v2(mpc_reader* fp);
+
+/// helper functions used by multiple files
+mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c
+void mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, double scale_factor);
+void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData);
+
+#endif // _mpcdec_internal_h
+
diff --git a/contrib/libmpcdec/mpcdec/math.h b/contrib/libmpcdec/mpcdec/math.h
new file mode 100644
index 000000000..31d078896
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/math.h
@@ -0,0 +1,144 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file math.h
+/// Libmpcdec internal math routines.
+
+#ifndef _mpcdec_math_h_
+#define _mpcdec_math_h_
+
+//#define MPC_FIXED_POINT
+
+#define MPC_FIXED_POINT_SHIFT 16
+
+#ifdef MPC_FIXED_POINT
+
+
+#ifdef _WIN32_WCE
+
+#include <cmnintrin.h>
+
+#define MPC_HAVE_MULHIGH
+
+#endif
+
+
+#define MPC_FIXED_POINT_SCALE_SHIFT (MPC_FIXED_POINT_SHIFT + MPC_FIXED_POINT_FRACTPART)
+#define MPC_FIXED_POINT_SCALE (1 << (MPC_FIXED_POINT_SCALE_SHIFT - 1))
+
+
+//in fixedpoint mode, results in decode output buffer are in -MPC_FIXED_POINT_SCALE ... MPC_FIXED_POINT_SCALE range
+
+#define MPC_FIXED_POINT_FRACTPART 14
+typedef mpc_int32_t MPC_SAMPLE_FORMAT;
+
+typedef mpc_int64_t MPC_SAMPLE_FORMAT_MULTIPLY;
+
+#define MAKE_MPC_SAMPLE(X) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<MPC_FIXED_POINT_FRACTPART))
+#define MAKE_MPC_SAMPLE_EX(X,Y) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<(Y)))
+
+#define MPC_MULTIPLY_NOTRUNCATE(X,Y) \
+ (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> MPC_FIXED_POINT_FRACTPART)
+
+#define MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z) \
+ (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> (Z))
+
+#ifdef _DEBUG
+static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2)
+{
+ MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_NOTRUNCATE(item1,item2);
+ assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
+ return (MPC_SAMPLE_FORMAT)temp;
+}
+
+static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY_EX(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2,unsigned shift)
+{
+ MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_EX_NOTRUNCATE(item1,item2,shift);
+ assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
+ return (MPC_SAMPLE_FORMAT)temp;
+}
+
+#else
+
+#define MPC_MULTIPLY(X,Y) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_NOTRUNCATE(X,Y))
+#define MPC_MULTIPLY_EX(X,Y,Z) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z))
+
+#endif
+
+#ifdef MPC_HAVE_MULHIGH
+#define MPC_MULTIPLY_FRACT(X,Y) _MulHigh(X,Y)
+#else
+#define MPC_MULTIPLY_FRACT(X,Y) MPC_MULTIPLY_EX(X,Y,32)
+#endif
+
+#define MPC_MAKE_FRACT_CONST(X) (MPC_SAMPLE_FORMAT)((X) * (double)(((mpc_int64_t)1)<<32) )
+#define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
+#define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) ( MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1<<(Z)) )) << (Z) )
+#define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1<<(Z)) ))
+
+#define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
+#define MPC_SCALE_CONST(X,Y,Z) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z))
+#define MPC_SCALE_CONST_SHL(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)-(S))
+#define MPC_SCALE_CONST_SHR(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)+(S))
+#define MPC_SHR(X,Y) ((X)>>(Y))
+#define MPC_SHL(X,Y) ((X)<<(Y))
+
+#else
+
+//in floating-point mode, decoded samples are in -1...1 range
+
+typedef float MPC_SAMPLE_FORMAT;
+
+#define MAKE_MPC_SAMPLE(X) ((MPC_SAMPLE_FORMAT)(X))
+#define MAKE_MPC_SAMPLE_EX(X,Y) ((MPC_SAMPLE_FORMAT)(X))
+
+#define MPC_MULTIPLY_FRACT(X,Y) ((X)*(Y))
+#define MPC_MAKE_FRACT_CONST(X) (X)
+#define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
+#define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
+#define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
+
+#define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
+#define MPC_MULTIPLY(X,Y) ((X)*(Y))
+#define MPC_MULTIPLY_EX(X,Y,Z) ((X)*(Y))
+#define MPC_SCALE_CONST(X,Y,Z) ((X)*(Y))
+#define MPC_SCALE_CONST_SHL(X,Y,Z,S) ((X)*(Y))
+#define MPC_SCALE_CONST_SHR(X,Y,Z,S) ((X)*(Y))
+#define MPC_SHR(X,Y) (X)
+#define MPC_SHL(X,Y) (X)
+
+#endif
+
+#endif // _mpcdec_math_h_
+
diff --git a/contrib/libmpcdec/mpcdec/mpcdec.h b/contrib/libmpcdec/mpcdec/mpcdec.h
new file mode 100644
index 000000000..77418fbcc
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/mpcdec.h
@@ -0,0 +1,145 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file mpcdec.h
+/// Top level include file for libmpcdec.
+
+#ifndef _mpcdec_h_
+#define _mpcdec_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef WIN32
+#include "mpcdec/config_types.h"
+#else
+#include "mpcdec/config_win32.h"
+#endif
+
+#include "decoder.h"
+#include "math.h"
+#include "reader.h"
+#include "streaminfo.h"
+
+enum {
+ MPC_FRAME_LENGTH = (36 * 32), /// samples per mpc frame
+ MPC_DECODER_BUFFER_LENGTH = 4 * MPC_FRAME_LENGTH /// required buffer size for decoder
+};
+
+// error codes
+#define ERROR_CODE_OK 0
+#define ERROR_CODE_FILE -1
+#define ERROR_CODE_SV7BETA 1
+#define ERROR_CODE_CBR 2
+#define ERROR_CODE_IS 3
+#define ERROR_CODE_BLOCKSIZE 4
+#define ERROR_CODE_INVALIDSV 5
+
+/// Initializes a streaminfo structure.
+/// \param si streaminfo structure to initialize
+void mpc_streaminfo_init(mpc_streaminfo *si);
+
+/// Reads streaminfo header from the mpc stream supplied by r.
+/// \param si streaminfo pointer to which info will be written
+/// \param r stream reader to supply raw data
+/// \return error code
+mpc_int32_t mpc_streaminfo_read(mpc_streaminfo *si, mpc_reader *r);
+
+/// Gets length of stream si, in seconds.
+/// \return length of stream in seconds
+double mpc_streaminfo_get_length(mpc_streaminfo *si);
+
+/// Returns length of stream si, in samples.
+/// \return length of stream in samples
+mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si);
+
+/// Sets up decoder library.
+/// Call this first when preparing to decode an mpc stream.
+/// \param r reader that will supply raw data to the decoder
+void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r);
+
+/// Initializes mpc decoder with the supplied stream info parameters.
+/// Call this next after calling mpc_decoder_setup.
+/// \param si streaminfo structure indicating format of source stream
+/// \return TRUE if decoder was initalized successfully, FALSE otherwise
+mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si);
+
+/// Call this next after calling mpc_decoder_setup.
+/// \param si streaminfo structure indicating format of source stream
+/// \param fast_seeking boolean 0 = use fast seeking if safe, 1 = force fast seeking
+void mpc_decoder_set_seeking(mpc_decoder *d, mpc_streaminfo *si, mpc_bool_t fast_seeking);
+
+void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si);
+
+/// Sets decoder sample scaling factor. All decoded samples will be multiplied
+/// by this factor.
+/// \param scale_factor multiplicative scaling factor
+void mpc_decoder_scale_output(mpc_decoder *d, double scale_factor);
+
+/// Actually reads data from previously initialized stream. Call
+/// this iteratively to decode the mpc stream.
+/// \param buffer destination buffer for decoded samples
+/// \param vbr_update_acc \todo document me
+/// \param vbr_update_bits \todo document me
+/// \return -1 if an error is encountered
+/// \return 0 if the stream has been completely decoded successfully and there are no more samples
+/// \return > 0 to indicate the number of bytes that were actually read from the stream.
+mpc_uint32_t mpc_decoder_decode(
+ mpc_decoder *d,
+ MPC_SAMPLE_FORMAT *buffer,
+ mpc_uint32_t *vbr_update_acc,
+ mpc_uint32_t *vbr_update_bits);
+
+mpc_uint32_t mpc_decoder_decode_frame(
+ mpc_decoder *d,
+ mpc_uint32_t *in_buffer,
+ mpc_uint32_t in_len,
+ MPC_SAMPLE_FORMAT *out_buffer);
+
+/// Seeks to the specified sample in the source stream.
+mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample);
+
+/// Seeks to specified position in seconds in the source stream.
+mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif // _mpcdec_h_
diff --git a/contrib/libmpcdec/mpcdec/reader.h b/contrib/libmpcdec/mpcdec/reader.h
new file mode 100644
index 000000000..3d4f57edc
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/reader.h
@@ -0,0 +1,82 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file reader.h
+
+#ifndef _mpcdec_reader_h_
+#define _mpcdec_reader_h_
+
+/// \brief Stream reader interface structure.
+///
+/// This is the structure you must supply to the musepack decoding library
+/// to feed it with raw data. Implement the five member functions to provide
+/// a functional reader.
+typedef struct mpc_reader_t {
+ /// Reads size bytes of data into buffer at ptr.
+ mpc_int32_t (*read)(void *t, void *ptr, mpc_int32_t size);
+
+ /// Seeks to byte position offset.
+ mpc_bool_t (*seek)(void *t, mpc_int32_t offset);
+
+ /// Returns the current byte offset in the stream.
+ mpc_int32_t (*tell)(void *t);
+
+ /// Returns the total length of the source stream, in bytes.
+ mpc_int32_t (*get_size)(void *t);
+
+ /// True if the stream is a seekable stream.
+ mpc_bool_t (*canseek)(void *t);
+
+ /// Field that can be used to identify a particular instance of
+ /// reader or carry along data associated with that reader.
+ void *data;
+
+} mpc_reader;
+
+typedef struct mpc_reader_file_t {
+ mpc_reader reader;
+
+ FILE *file;
+ long file_size;
+ mpc_bool_t is_seekable;
+} mpc_reader_file;
+
+/// Initializes reader with default stdio file reader implementation. Use
+/// this if you're just reading from a plain file.
+///
+/// \param r reader struct to initalize
+/// \param input input stream to attach to the reader
+void mpc_reader_setup_file_reader(mpc_reader_file *r, FILE *input);
+
+#endif // _mpcdec_reader_h_
diff --git a/contrib/libmpcdec/mpcdec/requant.h b/contrib/libmpcdec/mpcdec/requant.h
new file mode 100644
index 000000000..a0aab981b
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/requant.h
@@ -0,0 +1,51 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file requant.h
+/// Requantization function definitions.
+
+#ifndef _mpcdec_requant_h
+#define _mpcdec_requant_h_
+
+#include "mpcdec.h"
+
+/* C O N S T A N T S */
+extern const mpc_uint32_t Res_bit [18]; // bits per sample for chosen quantizer
+extern const MPC_SAMPLE_FORMAT __Cc [1 + 18]; // coefficients for requantization
+extern const mpc_int32_t __Dc [1 + 18]; // offset for requantization
+
+#define Cc (__Cc + 1)
+#define Dc (__Dc + 1)
+
+#endif // _mpcdec_requant_h_
diff --git a/contrib/libmpcdec/mpcdec/streaminfo.h b/contrib/libmpcdec/mpcdec/streaminfo.h
new file mode 100644
index 000000000..7cf941c47
--- /dev/null
+++ b/contrib/libmpcdec/mpcdec/streaminfo.h
@@ -0,0 +1,91 @@
+/*
+ Copyright (c) 2005, The Musepack Development Team
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the The Musepack Development Team nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/// \file streaminfo.h
+
+#ifndef _mpcdec_streaminfo_h_
+#define _mpcdec_streaminfo_h_
+
+typedef mpc_int32_t mpc_streaminfo_off_t;
+
+/// \brief mpc stream properties structure
+///
+/// Structure containing all the properties of an mpc stream. Populated
+/// by the streaminfo_read function.
+typedef struct mpc_streaminfo {
+ /// @name core mpc stream properties
+ //@{
+ mpc_uint32_t sample_freq; ///< sample frequency of stream
+ mpc_uint32_t channels; ///< number of channels in stream
+ mpc_streaminfo_off_t header_position; ///< byte offset of position of header in stream
+ mpc_uint32_t stream_version; ///< streamversion of stream
+ mpc_uint32_t bitrate; ///< bitrate of stream file (in bps)
+ double average_bitrate; ///< average bitrate of stream (in bits/sec)
+ mpc_uint32_t frames; ///< number of frames in stream
+ mpc_int64_t pcm_samples;
+ mpc_uint32_t max_band; ///< maximum band-index used in stream (0...31)
+ mpc_uint32_t is; ///< intensity stereo (0: off, 1: on)
+ mpc_uint32_t ms; ///< mid/side stereo (0: off, 1: on)
+ mpc_uint32_t block_size; ///< only needed for SV4...SV6 -> not supported
+ mpc_uint32_t profile; ///< quality profile of stream
+ const char* profile_name; ///< name of profile used by stream
+ //@}
+
+ /// @name replaygain related fields
+ //@{
+ mpc_int16_t gain_title; ///< replaygain title value
+ mpc_int16_t gain_album; ///< replaygain album value
+ mpc_uint16_t peak_album; ///< peak album loudness level
+ mpc_uint16_t peak_title; ///< peak title loudness level
+ //@}
+
+ /// @name true gapless support data
+ //@{
+ mpc_uint32_t is_true_gapless; ///< true gapless? (0: no, 1: yes)
+ mpc_uint32_t last_frame_samples; ///< number of valid samples within last frame
+
+ mpc_uint32_t encoder_version; ///< version of encoder used
+ char encoder[256]; ///< encoder name
+
+ mpc_streaminfo_off_t tag_offset; ///< offset to file tags
+ mpc_streaminfo_off_t total_file_length; ///< total length of underlying file
+ //@}
+
+ /// @name fast seeking support
+ //@{
+ mpc_uint32_t fast_seek; ///< support fast seeking ? (0: no, 1: yes)
+ //@}
+} mpc_streaminfo;
+
+#endif // _mpcdec_streaminfo_h_