1 /*
2   Copyright (c) 2005-2009, The Musepack Development Team
3   All rights reserved.
4 
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions are
7   met:
8 
9   * Redistributions of source code must retain the above copyright
10   notice, this list of conditions and the following disclaimer.
11 
12   * Redistributions in binary form must reproduce the above
13   copyright notice, this list of conditions and the following
14   disclaimer in the documentation and/or other materials provided
15   with the distribution.
16 
17   * Neither the name of the The Musepack Development Team nor the
18   names of its contributors may be used to endorse or promote
19   products derived from this software without specific prior
20   written permission.
21 
22   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 /// \file decoder.h
35 #ifndef _MPCDEC_DECODER_H_
36 #define _MPCDEC_DECODER_H_
37 #ifdef WIN32
38 #pragma once
39 #endif
40 
41 #include "reader.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #define SEEKING_TABLE_SIZE  256u
48 // set it to SLOW_SEEKING_WINDOW to not use fast seeking
49 #define FAST_SEEKING_WINDOW 32
50 // set it to FAST_SEEKING_WINDOW to only use fast seeking
51 #define SLOW_SEEKING_WINDOW 0x80000000
52 
53 enum {
54     MPC_V_MEM           = 2304,
55     MPC_DECODER_MEMSIZE = 16384,  // overall buffer size
56 };
57 
58 struct mpc_decoder_t {
59     /// @name internal state variables
60     //@{
61 	mpc_uint32_t stream_version;     ///< Streamversion of stream
62 	mpc_int32_t max_band;           ///< Maximum band-index used in stream (0...31)
63 	mpc_uint32_t ms;                 ///< Mid/side stereo (0: off, 1: on)
64 	mpc_uint32_t channels;           ///< Number of channels in stream
65 
66 	mpc_uint64_t samples;            ///< Number of samples in stream
67 
68 	mpc_uint64_t decoded_samples;    ///< Number of samples decoded from file begining
69 	mpc_uint32_t samples_to_skip;    ///< Number samples to skip (used for seeking)
70 	mpc_int32_t last_max_band;       ///< number of bands used in the last frame
71 
72     // randomizer state variables
73     mpc_uint32_t  __r1;
74     mpc_uint32_t  __r2;
75 
76     mpc_int32_t   SCF_Index_L [32] [3];
77     mpc_int32_t   SCF_Index_R [32] [3];       // holds scalefactor-indices
78     mpc_quantizer Q [32];                     // holds quantized samples
79     mpc_int32_t   Res_L [32];
80     mpc_int32_t   Res_R [32];                 // holds the chosen quantizer for each subband
81     mpc_bool_t    DSCF_Flag_L [32];
82     mpc_bool_t    DSCF_Flag_R [32];           // differential SCF used?
83     mpc_int32_t   SCFI_L [32];
84     mpc_int32_t   SCFI_R [32];                // describes order of transmitted SCF
85     mpc_bool_t    MS_Flag[32];                // MS used?
86 #ifdef MPC_FIXED_POINT
87     mpc_uint8_t   SCF_shift[256];
88 #endif
89 
90     MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960];
91     MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960];
92     MPC_SAMPLE_FORMAT Y_L[36][32];
93     MPC_SAMPLE_FORMAT Y_R[36][32];
94     MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention)
95     //@}
96 };
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 #endif
102