1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /*
19 ------------------------------------------------------------------------------
20
21 PacketVideo Corp.
22 MP3 Decoder Library
23
24 Filename: pvmp3_reorder.cpp
25
26
27 Date: 09/21/2007
28
29 ------------------------------------------------------------------------------
30 REVISION HISTORY
31
32
33 Description:
34
35 ------------------------------------------------------------------------------
36 INPUT AND OUTPUT DEFINITIONS
37
38 Inputs:
39
40 int32 xr[ ], rescaled data
41 struct gr_info_s *gr_info, granule structure
42 mp3Header *info, mp3 header info
43 int32 Scratch_mem[198] for temporary usage
44
45 Outputs:
46
47 int32 xr[ ], reordered data
48
49 ------------------------------------------------------------------------------
50 FUNCTION DESCRIPTION
51
52 If short blocks are used (block_type[gr][ch]=='10'), the rescaled data
53 xr[scf_band][window][freq_line] shall be reordered in polyphase subband
54 order, xr[subband][window][freq_line], prior to the IMDCT operation.
55
56 ------------------------------------------------------------------------------
57 REQUIREMENTS
58
59
60 ------------------------------------------------------------------------------
61 REFERENCES
62 [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
63 ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
64
65
66 ------------------------------------------------------------------------------
67 PSEUDO-CODE
68
69 ------------------------------------------------------------------------------
70 */
71
72
73 /*----------------------------------------------------------------------------
74 ; INCLUDES
75 ----------------------------------------------------------------------------*/
76 #include "pv_mp3dec_fxd_op.h"
77 #include "pvmp3_dec_defs.h"
78 #include "pvmp3_reorder.h"
79 #include "pvmp3_tables.h"
80 #include "mp3_mem_funcs.h"
81
82 /*----------------------------------------------------------------------------
83 ; MACROS
84 ; Define module specific macros here
85 ----------------------------------------------------------------------------*/
86
87
88 /*----------------------------------------------------------------------------
89 ; DEFINES
90 ; Include all pre-processor statements here. Include conditional
91 ; compile variables also.
92 ----------------------------------------------------------------------------*/
93
94
95 /*----------------------------------------------------------------------------
96 ; LOCAL FUNCTION DEFINITIONS
97 ; Function Prototype declaration
98 ----------------------------------------------------------------------------*/
99
100 /*----------------------------------------------------------------------------
101 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
102 ; Variable declaration - defined here and used outside this module
103 ----------------------------------------------------------------------------*/
104
105 /*----------------------------------------------------------------------------
106 ; EXTERNAL FUNCTION REFERENCES
107 ; Declare functions defined elsewhere and referenced in this module
108 ----------------------------------------------------------------------------*/
109
110 /*----------------------------------------------------------------------------
111 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
112 ; Declare variables used in this module but defined elsewhere
113 ----------------------------------------------------------------------------*/
114
115 /*----------------------------------------------------------------------------
116 ; FUNCTION CODE
117 ----------------------------------------------------------------------------*/
118
pvmp3_reorder(int32 xr[SUBBANDS_NUMBER * FILTERBANK_BANDS],granuleInfo * gr_info,int32 * used_freq_lines,mp3Header * info,int32 Scratch_mem[198])119 void pvmp3_reorder(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
120 granuleInfo *gr_info,
121 int32 *used_freq_lines,
122 mp3Header *info,
123 int32 Scratch_mem[198])
124 {
125 int32 sfreq = info->version_x + (info->version_x << 1);
126 sfreq += info->sampling_frequency;
127
128 if (gr_info->window_switching_flag && (gr_info->block_type == 2))
129 {
130 int32 sfb_lines;
131 int32 freq;
132 int32 src_line;
133 int32 sfb;
134 if (gr_info->mixed_block_flag)
135 {
136 /* REORDERING FOR REST SWITCHED SHORT */
137 sfb = 3; /* no reorder for low 2 subbands */
138 src_line = 36;
139 }
140 else
141 { /* pure short */
142 sfb = 0;
143 src_line = 0;
144 }
145 int16 ct = src_line;
146
147 for (; sfb < 13; sfb++)
148 {
149 if (*used_freq_lines > 3*mp3_sfBandIndex[sfreq].s[sfb+1])
150 {
151 sfb_lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
152
153 for (freq = 0; freq < 3*sfb_lines; freq += 3)
154 {
155 int32 tmp1 = xr[src_line];
156 int32 tmp2 = xr[src_line+(sfb_lines)];
157 int32 tmp3 = xr[src_line+(sfb_lines<<1)];
158 src_line++;
159 Scratch_mem[freq ] = tmp1;
160 Scratch_mem[freq+1] = tmp2;
161 Scratch_mem[freq+2] = tmp3;
162 }
163 src_line += (sfb_lines << 1);
164
165 pv_memcpy(&xr[ct], Scratch_mem, sfb_lines*3*sizeof(int32));
166 ct += sfb_lines + (sfb_lines << 1);
167
168 }
169 else
170 {
171
172 sfb_lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
173
174 for (freq = 0; freq < 3*sfb_lines; freq += 3)
175 {
176 int32 tmp1 = xr[src_line];
177 int32 tmp2 = xr[src_line+(sfb_lines)];
178 int32 tmp3 = xr[src_line+(sfb_lines<<1)];
179 src_line++;
180 Scratch_mem[freq ] = tmp1;
181 Scratch_mem[freq+1] = tmp2;
182 Scratch_mem[freq+2] = tmp3;
183 }
184
185 pv_memcpy(&xr[ct], Scratch_mem, sfb_lines*3*sizeof(int32));
186
187 *used_freq_lines = mp3_sfBandIndex[sfreq].s[sfb+1] * 3;
188
189 sfb = 13; /* force out of the for-loop */
190 }
191 }
192 }
193 }
194
195
196
197
198