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_get_main_data_size.cpp
25
26     Date: 09/21/2007
27
28------------------------------------------------------------------------------
29 REVISION HISTORY
30
31
32 Description:
33
34------------------------------------------------------------------------------
35 INPUT AND OUTPUT DEFINITIONS
36
37 Input
38    mp3Header *info,         pointer to mp3 header info structure
39    tmp3dec_file  *pVars
40                             contains information that needs to persist
41                             between calls to this function, or is too big to
42                             be placed on the stack, even though the data is
43                             only needed during execution of this function
44
45  Returns
46
47    main data frame size
48
49------------------------------------------------------------------------------
50 FUNCTION DESCRIPTION
51
52    get main data frame size
53
54------------------------------------------------------------------------------
55 REQUIREMENTS
56
57
58------------------------------------------------------------------------------
59 REFERENCES
60
61 [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
62     ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
63
64------------------------------------------------------------------------------
65 PSEUDO-CODE
66
67------------------------------------------------------------------------------
68*/
69
70
71/*----------------------------------------------------------------------------
72; INCLUDES
73----------------------------------------------------------------------------*/
74
75#include "pvmp3_tables.h"
76#include "pvmp3_get_main_data_size.h"
77#include "pv_mp3dec_fxd_op.h"
78
79
80/*----------------------------------------------------------------------------
81; MACROS
82; Define module specific macros here
83----------------------------------------------------------------------------*/
84
85
86/*----------------------------------------------------------------------------
87; DEFINES
88; Include all pre-processor statements here. Include conditional
89; compile variables also.
90----------------------------------------------------------------------------*/
91
92/*----------------------------------------------------------------------------
93; LOCAL FUNCTION DEFINITIONS
94; Function Prototype declaration
95----------------------------------------------------------------------------*/
96
97/*----------------------------------------------------------------------------
98; LOCAL STORE/BUFFER/POINTER DEFINITIONS
99; Variable declaration - defined here and used outside this module
100----------------------------------------------------------------------------*/
101
102/*----------------------------------------------------------------------------
103; EXTERNAL FUNCTION REFERENCES
104; Declare functions defined elsewhere and referenced in this module
105----------------------------------------------------------------------------*/
106
107/*----------------------------------------------------------------------------
108; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
109; Declare variables used in this module but defined elsewhere
110----------------------------------------------------------------------------*/
111
112/*----------------------------------------------------------------------------
113; FUNCTION CODE
114----------------------------------------------------------------------------*/
115
116int32 pvmp3_get_main_data_size(mp3Header *info,
117                               tmp3dec_file  *pVars)
118{
119
120
121    int32 numBytes = fxp_mul32_Q28(mp3_bitrate[info->version_x][info->bitrate_index] << 20,
122                                   inv_sfreq[info->sampling_frequency]);
123
124
125    numBytes >>= (20 - info->version_x);
126
127    /*
128     *  Remove the size of the side information from the main data total
129     */
130    if (info->version_x == MPEG_1)
131    {
132        pVars->predicted_frame_size = numBytes;
133        if (info->mode == MPG_MD_MONO)
134        {
135            numBytes -= 17;
136        }
137        else
138        {
139            numBytes -= 32;
140        }
141    }
142    else
143    {
144        numBytes >>= 1;
145        pVars->predicted_frame_size = numBytes;
146
147        if (info->mode == MPG_MD_MONO)
148        {
149            numBytes -= 9;
150        }
151        else
152        {
153            numBytes -= 17;
154        }
155    }
156
157    if (info->padding)
158    {
159        numBytes++;
160        pVars->predicted_frame_size++;
161    }
162
163    if (info->error_protection)
164    {
165        numBytes -= 6;
166    }
167    else
168    {
169        numBytes -= 4;
170    }
171
172
173    if (numBytes < 0)
174    {
175        numBytes = 0;
176    }
177
178    return(numBytes);
179}
180
181