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 Pathname: ./src/calc_gsfb_table.c
21
22------------------------------------------------------------------------------
23 REVISION HISTORY
24
25 Description:  Modified from original shareware code
26
27 Description: (1) Modified to bring in-line with PV standards
28              (2) Removed if(pFrameInfo->islong), only short windows will
29                  call this routine from getics.c
30
31 Description: Modified per review comments
32
33 Who:                       Date:
34 Description:
35
36------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
38
39 Inputs:
40    pFrameInfo  = pointer to structure that holds information for current
41                  frame. Data type FrameInfo
42
43    group[]     = array that contains the grouping information of short
44                  windows (stop index of windows in each group).
45                  Data type Int
46
47 Local Stores/Buffers/Pointers Needed:
48    None
49
50 Global Stores/Buffers/Pointers Needed:
51    None
52
53 Outputs:
54    None
55
56 Pointers and Buffers Modified:
57    pFrameInfo -> frame_sfb_top   contains the cumulative bandwidth of
58                                    scalefactor bands in each group
59
60 Local Stores Modified:
61    None
62
63 Global Stores Modified:
64    None
65
66------------------------------------------------------------------------------
67 FUNCTION DESCRIPTION
68
69 This function is only invoked when short windows are present. It calculates
70 the number of groups in one frame, and the scalefactor bandwidth of each
71 scalefactor band in each group.
72 All windows within one group share the same scalefactors and are interleaved
73 on a scalefactor band basis. Within each group, the actual length of one
74 scalefactor band equals to the number of windows times the number of
75 coefficients in a regular scalefactor band.
76
77------------------------------------------------------------------------------
78 REQUIREMENTS
79
80 This function shall replace the contents of pFrameInfo->frame_sfb_top
81 with the cumulative bandwidth of each scalefactor band in each group
82
83------------------------------------------------------------------------------
84 REFERENCES
85
86 (1) MPEG-2 NBC Audio Decoder
87   "This software module was originally developed by AT&T, Dolby
88   Laboratories, Fraunhofer Gesellschaft IIS in the course of development
89   of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and
90   3. This software module is an implementation of a part of one or more
91   MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
92   Audio standard. ISO/IEC  gives users of the MPEG-2 NBC/MPEG-4 Audio
93   standards free license to this software module or modifications thereof
94   for use in hardware or software products claiming conformance to the
95   MPEG-2 NBC/MPEG-4 Audio  standards. Those intending to use this software
96   module in hardware or software products are advised that this use may
97   infringe existing patents. The original developer of this software
98   module and his/her company, the subsequent editors and their companies,
99   and ISO/IEC have no liability for use of this software module or
100   modifications thereof in an implementation. Copyright is not released
101   for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original
102   developer retains full right to use the code for his/her own purpose,
103   assign or donate the code to a third party and to inhibit third party
104   from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.
105   This copyright notice must be included in all copies or derivative
106   works."
107   Copyright(c)1996.
108
109 (2) ISO/IEC 14496-3: 1999(E)
110    Subpart 4       p54.    4.5.2.3.2   decoding process
111
112------------------------------------------------------------------------------
113 PSEUDO-CODE
114
115    offset      = 0;
116    group_idx   = 0;
117
118    DO
119        pFrameInfo->group_len[group_idx] = group[group_idx] - offset;
120        offset = group[group_idx];
121        group_idx++;
122
123    WHILE (offset < NUM_SHORT_WINDOWS);
124
125
126    pFrameInfo->num_groups = group_idx;
127
128    pFrameSfbTop = pFrameInfo->frame_sfb_top;
129    offset = 0;
130
131    FOR (group_idx = 0; group_idx < pFrameInfo->num_groups; group_idx++)
132
133        len = pFrameInfo->group_len[group_idx];
134
135        FOR (sfb = 0; sfb < pFrameInfo->sfb_per_win[group_idx]; sfb++)
136
137            offset += pFrameInfo->sfb_width_128[sfb] * len;
138            *pFrameSfbTop++ = offset;
139
140        ENDFOR
141
142    ENDFOR
143
144------------------------------------------------------------------------------
145 RESOURCES USED
146   When the code is written for a specific target processor the
147     the resources used should be documented below.
148
149 STACK USAGE: [stack count for this module] + [variable to represent
150          stack usage for each subroutine called]
151
152     where: [stack usage variable] = stack usage for [subroutine
153         name] (see [filename].ext)
154
155 DATA MEMORY USED: x words
156
157 PROGRAM MEMORY USED: x words
158
159 CLOCK CYCLES: [cycle count equation for this module] + [variable
160           used to represent cycle count for each subroutine
161           called]
162
163     where: [cycle count variable] = cycle count for [subroutine
164        name] (see [filename].ext)
165
166------------------------------------------------------------------------------
167*/
168
169
170/*----------------------------------------------------------------------------
171; INCLUDES
172----------------------------------------------------------------------------*/
173#include    "pv_audio_type_defs.h"
174#include    "huffman.h"
175#include    "aac_mem_funcs.h"
176
177/*----------------------------------------------------------------------------
178; MACROS
179; Define module specific macros here
180----------------------------------------------------------------------------*/
181
182/*----------------------------------------------------------------------------
183; DEFINES
184; Include all pre-processor statements here. Include conditional
185; compile variables also.
186----------------------------------------------------------------------------*/
187
188/*----------------------------------------------------------------------------
189; LOCAL FUNCTION DEFINITIONS
190; Function Prototype declaration
191----------------------------------------------------------------------------*/
192
193/*----------------------------------------------------------------------------
194; LOCAL STORE/BUFFER/POINTER DEFINITIONS
195; Variable declaration - defined here and used outside this module
196----------------------------------------------------------------------------*/
197
198/*----------------------------------------------------------------------------
199; EXTERNAL FUNCTION REFERENCES
200; Declare functions defined elsewhere and referenced in this module
201----------------------------------------------------------------------------*/
202
203/*----------------------------------------------------------------------------
204; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
205; Declare variables used in this module but defined elsewhere
206----------------------------------------------------------------------------*/
207
208/*----------------------------------------------------------------------------
209; FUNCTION CODE
210----------------------------------------------------------------------------*/
211void  calc_gsfb_table(
212    FrameInfo   *pFrameInfo,
213    Int         group[])
214{
215
216    Int      group_idx;
217    Int      offset;
218    Int     *pFrameSfbTop;
219    Int     *pSfbWidth128;
220    Int      sfb;
221    Int      nsfb;
222    Int      len;
223    Int      ngroups;
224
225    /* clear out the default values set by infoinit */
226    /* */
227    pv_memset(pFrameInfo->frame_sfb_top,
228              0,
229              MAXBANDS*sizeof(pFrameInfo->frame_sfb_top[0]));
230    /* */
231    /* first calculate the group length*/
232    offset      = 0;
233    ngroups     = 0;
234    do
235    {
236        pFrameInfo->group_len[ngroups] = group[ngroups] - offset;
237        offset = group[ngroups];
238        ngroups++;
239
240    }
241    while (offset < NUM_SHORT_WINDOWS);
242
243
244    /* calculate the cumulative scalefactor bandwidth for one frame */
245    pFrameInfo->num_groups = ngroups;
246
247    pFrameSfbTop = pFrameInfo->frame_sfb_top;
248    offset = 0;
249
250
251    for (group_idx = 0; group_idx < ngroups; group_idx++)
252    {
253        len  = pFrameInfo->group_len[  group_idx];
254        nsfb = pFrameInfo->sfb_per_win[group_idx];
255
256        pSfbWidth128 = pFrameInfo->sfb_width_128;
257
258        for (sfb = nsfb; sfb > 0; sfb--)
259        {
260            offset += *pSfbWidth128++ * len;
261            *pFrameSfbTop++ = offset;
262        }
263    }
264
265
266} /* calc_gsfb_table */
267
268