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_mpeg2_get_scale_factors.cpp
25
26     Date: 09/21/2007
27
28------------------------------------------------------------------------------
29 REVISION HISTORY
30
31
32 Description:
33
34------------------------------------------------------------------------------
35 INPUT AND OUTPUT DEFINITIONS
36
37Input
38
39    mp3ScaleFactors *scalefac,
40    mp3SideInfo     *si,                    side information
41    int32           gr,                     granule
42    int32           ch,                     channel
43    mp3Header       *info,                  mp3 header information
44    uint32          *scalefac_IIP_buffer,   auxiliary scale data
45    tbits           *pMainData               bit stream Data
46
47 Returns
48
49    III_scalefac_t  *scalefac,              scale factor
50
51
52------------------------------------------------------------------------------
53 FUNCTION DESCRIPTION
54
55    get scale factor for mpe2 layer III LSF extension
56
57------------------------------------------------------------------------------
58 REQUIREMENTS
59
60
61------------------------------------------------------------------------------
62 REFERENCES
63
64 [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
65     ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
66
67------------------------------------------------------------------------------
68 PSEUDO-CODE
69
70------------------------------------------------------------------------------
71*/
72
73
74/*----------------------------------------------------------------------------
75; INCLUDES
76----------------------------------------------------------------------------*/
77
78#include "pvmp3_mpeg2_get_scale_factors.h"
79#include "pvmp3_mpeg2_get_scale_data.h"
80
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; LOCAL FUNCTION DEFINITIONS
96; Function Prototype declaration
97----------------------------------------------------------------------------*/
98
99/*----------------------------------------------------------------------------
100; LOCAL STORE/BUFFER/POINTER DEFINITIONS
101; Variable declaration - defined here and used outside this module
102----------------------------------------------------------------------------*/
103
104/*----------------------------------------------------------------------------
105; EXTERNAL FUNCTION REFERENCES
106; Declare functions defined elsewhere and referenced in this module
107----------------------------------------------------------------------------*/
108
109/*----------------------------------------------------------------------------
110; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
111; Declare variables used in this module but defined elsewhere
112----------------------------------------------------------------------------*/
113
114/*----------------------------------------------------------------------------
115; FUNCTION CODE
116----------------------------------------------------------------------------*/
117
118void pvmp3_mpeg2_get_scale_factors(mp3ScaleFactors *scalefac,
119                                   mp3SideInfo     *si,
120                                   int32           gr,
121                                   int32           ch,
122                                   mp3Header       *info,
123                                   uint32          *scalefac_IIP_buffer,
124                                   tmp3Bits        *pMainData)
125{
126
127    int32 sfb;
128    int32 k = 0;
129    int32 window;
130    uint32 *scalefac_buffer     = &scalefac_IIP_buffer[56];
131
132    granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
133
134    pvmp3_mpeg2_get_scale_data(si,
135                               gr,
136                               ch,
137                               info,
138                               (uint32 *)scalefac_buffer,
139                               (uint32 *)scalefac_IIP_buffer,
140                               pMainData);
141
142
143    if (gr_info->window_switching_flag && (gr_info->block_type == 2))
144    {
145        if (gr_info->mixed_block_flag)
146        {
147            for (sfb = 0; sfb < 6; sfb++)
148            {
149                scalefac->l[sfb] = scalefac_buffer[sfb];
150            }
151
152
153            k = 6;
154            for (sfb = 3; sfb < 12; sfb++)
155            {
156                for (window = 0; window < 3; window++)
157                {
158                    scalefac->s[window][sfb] = scalefac_buffer[k];
159                    k++;
160                }
161            }
162
163
164            /* adjust position of "illegal position" information in scalefac_IIP_buffer[] */
165            /* in mixed blocks mode for short sfb, move them 3 places up. efs 3002-07-04  */
166            for (sfb = 11; sfb >= 3; sfb--)
167            {
168                scalefac_IIP_buffer[3*sfb + 2] = scalefac_IIP_buffer[3*sfb - 1];
169                scalefac_IIP_buffer[3*sfb + 1] = scalefac_IIP_buffer[3*sfb - 2];
170                scalefac_IIP_buffer[3*sfb    ] = scalefac_IIP_buffer[3*sfb - 3];
171
172            }
173        }
174        else
175        {  /* SHORT*/
176            for (sfb = 0; sfb < 12; sfb++)
177            {
178                for (window = 0; window < 3; window++)
179                {
180                    scalefac->s[window][sfb] = scalefac_buffer[k];
181                    k++;
182                }
183            }
184        }
185
186        scalefac->s[0][12] = 0;
187        scalefac->s[1][12] = 0;
188        scalefac->s[2][12] = 0;
189
190    }
191    else
192    {   /* LONG types 0,1,3 */
193        for (sfb = 0; sfb < 21; sfb++)
194        {
195            scalefac->l[sfb] = scalefac_buffer[sfb];
196        }
197        scalefac->l[21] = 0;
198        scalefac->l[22] = 0;
199
200    }
201}
202
203