summaryrefslogtreecommitdiffstats
path: root/libAACenc/src/qc_data.h
blob: bbcffde4202b904984a377af642927a3025a047e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/******************************** MPEG Audio Encoder **************************

                     (C) Copyright Fraunhofer IIS (1999)
                               All Rights Reserved

    Please be advised that this software and/or program delivery is
    Confidential Information of Fraunhofer and subject to and covered by the

    Fraunhofer IIS Software Evaluation Agreement
    between Google Inc. and  Fraunhofer
    effective and in full force since March 1, 2012.

    You may use this software and/or program only under the terms and
    conditions described in the above mentioned Fraunhofer IIS Software
    Evaluation Agreement. Any other and/or further use requires a separate agreement.


   This software and/or program is protected by copyright law and international
   treaties. Any reproduction or distribution of this software and/or program,
   or any portion of it, may result in severe civil and criminal penalties, and
   will be prosecuted to the maximum extent possible under law.

   $Id$
   Initial author:       M. Werner
   contents/description: Quantizing & coding data

******************************************************************************/
#ifndef _QC_DATA_H
#define _QC_DATA_H


#include "psy_const.h"
#include "dyn_bits.h"
#include "adj_thr_data.h"
#include "line_pe.h"
#include "FDK_audio.h"
#include "interface.h"


typedef enum {
  QCDATA_BR_MODE_INVALID = -1,
  QCDATA_BR_MODE_CBR     =  0,
  QCDATA_BR_MODE_VBR_1   =  1, /* 32 kbps/channel */
  QCDATA_BR_MODE_VBR_2   =  2, /* 40 kbps/channel */
  QCDATA_BR_MODE_VBR_3   =  3, /* 48 kbps/channel */
  QCDATA_BR_MODE_VBR_4   =  4, /* 64 kbps/channel */
  QCDATA_BR_MODE_VBR_5   =  5, /* 96 kbps/channel */
  QCDATA_BR_MODE_FF      =  6,  /* Fixed frame mode. */
  QCDATA_BR_MODE_SFR     =  7  /* Superframe mode. */


} QCDATA_BR_MODE;

typedef struct {
  MP4_ELEMENT_ID elType;
  INT instanceTag;
  INT nChannelsInEl;
  INT ChannelIndex[2];
  FIXP_DBL relativeBits;
} ELEMENT_INFO;

typedef struct {
  CHANNEL_MODE encMode;
  INT nChannels;
  INT nChannelsEff;
  INT nElements;
  ELEMENT_INFO elInfo[(6)];
//  INT elDSE;                   /* DSE element signalling */
} CHANNEL_MAPPING;

typedef struct {
  INT paddingRest;
} PADDING;


/* Quantizing & coding stage */

struct QC_INIT{
  CHANNEL_MAPPING* channelMapping;
  INT sceCpe;      /* not used yet                         */
  INT maxBits;     /* maximum number of bits in reservoir  */
  INT averageBits; /* average number of bits we should use */
  INT bitRes;
  INT staticBits;  /* Bits per frame consumed by transport layers. */
  QCDATA_BR_MODE bitrateMode;
  INT meanPe;
  INT chBitrate;
  INT invQuant;
  INT maxIterations; /* Maximum number of allowed iterations before FDKaacEnc_crashRecovery() is applied. */
  FIXP_DBL maxBitFac;
  INT bitrate;
  INT nSubFrames; /* helper variable */
  INT minBits;    /* minimal number of bits in one frame*/

  PADDING padding;
};

typedef struct
{
  FIXP_DBL      mdctSpectrum[(1024)];

  SHORT         quantSpec[(1024)];

  UINT          maxValueInSfb[MAX_GROUPED_SFB];
  INT           scf[MAX_GROUPED_SFB];
  INT           globalGain;
  SECTION_DATA  sectionData;

  FIXP_DBL      sfbFormFactorLdData[MAX_GROUPED_SFB];

  FIXP_DBL      sfbThresholdLdData[MAX_GROUPED_SFB];
  FIXP_DBL      sfbMinSnrLdData[MAX_GROUPED_SFB];
  FIXP_DBL      sfbEnergyLdData[MAX_GROUPED_SFB];
  FIXP_DBL      sfbEnergy[MAX_GROUPED_SFB];
  FIXP_DBL      sfbWeightedEnergyLdData[MAX_GROUPED_SFB];

  FIXP_DBL      sfbEnFacLd[MAX_GROUPED_SFB];

  FIXP_DBL      sfbSpreadEnergy[MAX_GROUPED_SFB];

} QC_OUT_CHANNEL;


typedef struct
{
  EXT_PAYLOAD_TYPE  type;  /* type of the extension payload */
  INT    nPayloadBits;     /* size of the payload */
  UCHAR *pPayload;         /* pointer to payload */

} QC_OUT_EXTENSION;


typedef struct
{
  INT          staticBitsUsed; /* for verification purposes */
  INT          dynBitsUsed;    /* for verification purposes */

  INT          extBitsUsed;    /* bit consumption of extended fill elements */
  INT          nExtensions;    /* number of extension payloads for this element */
  QC_OUT_EXTENSION extension[(1)];  /* reffering extension payload */

  INT          grantedDynBits;

  INT          grantedPe;
  INT          grantedPeCorr;

  PE_DATA      peData;

  QC_OUT_CHANNEL *qcOutChannel[(2)];


} QC_OUT_ELEMENT;

typedef struct
{
  QC_OUT_ELEMENT    *qcElement[(6)];
  QC_OUT_CHANNEL    *pQcOutChannels[(6)];
  QC_OUT_EXTENSION   extension[(2+2)];  /* global extension payload */
  INT          nExtensions;       /* number of extension payloads for this AU */
  INT          maxDynBits;        /* maximal allowed dynamic bits in frame */
  INT          grantedDynBits;    /* granted dynamic bits in frame */
  INT          totFillBits;       /* fill bits */
  INT          elementExtBits;    /* element associated extension payload bits, e.g. sbr, drc ... */
  INT          globalExtBits;     /* frame/au associated extension payload bits (anc data ...) */
  INT          staticBits;        /* aac side info bits */

  INT          totalNoRedPe;
  INT          totalGrantedPeCorr;

  INT          usedDynBits;       /* number of dynamic bits in use */
  INT          alignBits;         /* AU alignment bits */
  INT          totalBits;         /* sum of static, dyn, sbr, fill, align and dse bits */

} QC_OUT;

typedef struct {
  INT chBitrateEl;                    /* channel bitrate in element (totalbitrate*el_relativeBits/el_channels) */
  INT maxBitsEl;                      /* used in crash recovery */
  INT bitResLevelEl;                  /* update bitreservoir level in each call of FDKaacEnc_QCMain */
  INT maxBitResBitsEl;                /* nEffChannels*6144 - averageBitsInFrame */
  FIXP_DBL relativeBitsEl;            /* Bits relative to total Bits*/
} ELEMENT_BITS;

typedef struct
{
  /* this is basically struct QC_INIT */

  INT globHdrBits;
  INT maxBitsPerFrame;   /* maximal allowed bits per frame, 6144*nChannelsEff */
  INT minBitsPerFrame;   /* minimal allowd bits per fram, superframing - DRM */
  INT nElements;
  QCDATA_BR_MODE bitrateMode;
  INT bitDistributenMode; /* 0: full bitreservoir, 1: reduced bitreservoir, 2: disabled bitreservoir */
  INT bitResTot;
  INT bitResTotMax;
  INT maxIterations;      /* Maximum number of allowed iterations before FDKaacEnc_crashRecovery() is applied. */
  INT invQuant;

  FIXP_DBL vbrQualFactor;
  FIXP_DBL maxBitFac;

  PADDING padding;

  ELEMENT_BITS  *elementBits[(6)];
  BITCNTR_STATE *hBitCounter;
  ADJ_THR_STATE *hAdjThr;

} QC_STATE;

#endif /* _QC_DATA_H */