Further changes in mpc buffered seek. Remove magical number and replace it with a...
[kugel-rb.git] / apps / codecs / libmusepack / decoder.h
blob499cd53137b776ac1a2f49b32bef3ddb8cbc2a70
1 /*
2 Copyright (c) 2005, The Musepack Development Team
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
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.
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.
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.
35 /// \file decoder.h
37 #ifndef _mpcdec_decoder_h_
38 #define _mpcdec_decoder_h_
40 #include "huffman.h"
41 #include "math.h"
42 #include "musepack.h"
43 #include "reader.h"
44 #include "streaminfo.h"
46 //#define MPC_SUPPORT_SV456
47 #define SCF_HACK
49 enum {
50 MPC_V_MEM = 2304,
51 MPC_DECODER_MEMSIZE = 16384, // overall buffer size (words)
52 MPC_SEEK_BUFFER_SIZE = 8192, // seek buffer size (words)
55 typedef struct {
56 mpc_int16_t L [36];
57 mpc_int16_t R [36];
58 } QuantTyp;
60 typedef struct mpc_decoder_t {
61 mpc_reader *r;
63 /// @name internal state variables
64 //@{
66 mpc_uint32_t next;
67 mpc_uint32_t dword; /// currently decoded 32bit-word
68 mpc_uint32_t pos; /// bit-position within dword
69 mpc_uint32_t *Speicher; /// read-buffer
70 mpc_uint32_t Zaehler; /// actual index within read-buffer
71 mpc_uint32_t Ring;
73 mpc_uint32_t samples_to_skip;
74 mpc_uint32_t last_block_samples;
75 mpc_uint32_t FwdJumpInfo;
76 mpc_uint32_t ActDecodePos;
79 mpc_uint32_t DecodedFrames;
80 mpc_uint32_t OverallFrames;
81 mpc_int32_t SampleRate; // Sample frequency
83 mpc_uint32_t StreamVersion; // version of bitstream
84 mpc_int32_t Max_Band;
85 mpc_uint32_t MPCHeaderPos; // AB: needed to support ID3v2
87 mpc_uint32_t FrameWasValid;
88 mpc_uint32_t MS_used; // MS-coding used ?
89 mpc_uint32_t TrueGaplessPresent;
91 mpc_uint32_t WordsRead; // counts amount of decoded dwords
93 // randomizer state variables
94 mpc_uint32_t __r1;
95 mpc_uint32_t __r2;
97 mpc_int8_t SCF_Index_L [32] [3];
98 mpc_int8_t SCF_Index_R [32] [3]; // holds scalefactor-indices
99 QuantTyp Q [32]; // holds quantized samples
100 mpc_int8_t Res_L [32];
101 mpc_int8_t Res_R [32]; // holds the chosen quantizer for each subband
102 #ifdef MPC_SUPPORT_SV456
103 mpc_bool_t DSCF_Flag_L [32];
104 mpc_bool_t DSCF_Flag_R [32]; // differential SCF used?
105 #endif
106 mpc_int8_t SCFI_L [32];
107 mpc_int8_t SCFI_R [32]; // describes order of transmitted SCF
108 mpc_bool_t MS_Flag[32]; // MS used?
110 mpc_uint32_t SeekTableCounter; // used to sum up skip info, if SeekTable_Step != 1
111 mpc_uint32_t MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries)
112 mpc_uint32_t* SeekTable; // seek table itself
113 mpc_uint8_t SeekTable_Step; // 1<<SeekTable_Step = frames per table index
114 mpc_uint32_t SeekTable_Mask; // used to avoid modulo-operation in seek
116 #ifdef MPC_FIXED_POINT
117 mpc_uint8_t SCF_shift[256];
118 #endif
120 MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960];
121 MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960];
122 MPC_SAMPLE_FORMAT (*Y_L)[32];
123 MPC_SAMPLE_FORMAT (*Y_R)[32];
124 MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention)
125 //@}
127 } mpc_decoder;
129 #endif // _mpc_decoder_h