-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsbrside.c
622 lines (519 loc) · 20.9 KB
/
sbrside.c
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: $Id: sbrside.c,v 1.2 2005/05/24 16:01:55 albertofloyd Exp $
*
* Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file,
* are subject to the current version of the RealNetworks Public
* Source License (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the current version of the RealNetworks Community
* Source License (the "RCSL") available at
* http://www.helixcommunity.org/content/rcsl, in which case the RCSL
* will apply. You may also obtain the license terms directly from
* RealNetworks. You may not use this file except in compliance with
* the RPSL or, if you have a valid RCSL with RealNetworks applicable
* to this file, the RCSL. Please see the applicable RPSL or RCSL for
* the rights, obligations and limitations governing use of the
* contents of the file.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the
* portions it created.
*
* This file, and the files included with this file, is distributed
* and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
* ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
/**************************************************************************************
* Fixed-point HE-AAC decoder
* Jon Recker ([email protected])
* February 2005
*
* sbrside.c - functions for unpacking side info from SBR bitstream
**************************************************************************************/
#include "sbr.h"
/**************************************************************************************
* Function: GetSampRateIdx
*
* Description: get index of given sample rate
*
* Inputs: sample rate (in Hz)
*
* Outputs: none
*
* Return: index of sample rate (table 1.15 in 14496-3:2001(E))
* -1 if sample rate not found in table
**************************************************************************************/
int GetSampRateIdx(int sampRate)
{
int idx;
for (idx = 0; idx < NUM_SAMPLE_RATES; idx++) {
if (sampRate == sampRateTab[idx])
return idx;
}
return -1;
}
/**************************************************************************************
* Function: UnpackSBRHeader
*
* Description: unpack SBR header (table 4.56)
*
* Inputs: BitStreamInfo struct pointing to start of SBR header
*
* Outputs: initialized SBRHeader struct for this SCE/CPE block
*
* Return: non-zero if frame reset is triggered, zero otherwise
**************************************************************************************/
int UnpackSBRHeader(BitStreamInfo *bsi, SBRHeader *sbrHdr)
{
SBRHeader sbrHdrPrev;
/* save previous values so we know whether to reset decoder */
sbrHdrPrev.startFreq = sbrHdr->startFreq;
sbrHdrPrev.stopFreq = sbrHdr->stopFreq;
sbrHdrPrev.freqScale = sbrHdr->freqScale;
sbrHdrPrev.alterScale = sbrHdr->alterScale;
sbrHdrPrev.crossOverBand = sbrHdr->crossOverBand;
sbrHdrPrev.noiseBands = sbrHdr->noiseBands;
sbrHdr->ampRes = GetBits(bsi, 1);
sbrHdr->startFreq = GetBits(bsi, 4);
sbrHdr->stopFreq = GetBits(bsi, 4);
sbrHdr->crossOverBand = GetBits(bsi, 3);
sbrHdr->resBitsHdr = GetBits(bsi, 2);
sbrHdr->hdrExtra1 = GetBits(bsi, 1);
sbrHdr->hdrExtra2 = GetBits(bsi, 1);
if (sbrHdr->hdrExtra1) {
sbrHdr->freqScale = GetBits(bsi, 2);
sbrHdr->alterScale = GetBits(bsi, 1);
sbrHdr->noiseBands = GetBits(bsi, 2);
} else {
/* defaults */
sbrHdr->freqScale = 2;
sbrHdr->alterScale = 1;
sbrHdr->noiseBands = 2;
}
if (sbrHdr->hdrExtra2) {
sbrHdr->limiterBands = GetBits(bsi, 2);
sbrHdr->limiterGains = GetBits(bsi, 2);
sbrHdr->interpFreq = GetBits(bsi, 1);
sbrHdr->smoothMode = GetBits(bsi, 1);
} else {
/* defaults */
sbrHdr->limiterBands = 2;
sbrHdr->limiterGains = 2;
sbrHdr->interpFreq = 1;
sbrHdr->smoothMode = 1;
}
sbrHdr->count++;
/* if any of these have changed from previous frame, reset the SBR module */
if (sbrHdr->startFreq != sbrHdrPrev.startFreq || sbrHdr->stopFreq != sbrHdrPrev.stopFreq ||
sbrHdr->freqScale != sbrHdrPrev.freqScale || sbrHdr->alterScale != sbrHdrPrev.alterScale ||
sbrHdr->crossOverBand != sbrHdrPrev.crossOverBand || sbrHdr->noiseBands != sbrHdrPrev.noiseBands
)
return -1;
else
return 0;
}
/* cLog2[i] = ceil(log2(i)) (disregard i == 0) */
static const unsigned char cLog2[9] = {0, 0, 1, 2, 2, 3, 3, 3, 3};
/**************************************************************************************
* Function: UnpackSBRGrid
*
* Description: unpack SBR grid (table 4.62)
*
* Inputs: BitStreamInfo struct pointing to start of SBR grid
* initialized SBRHeader struct for this SCE/CPE block
*
* Outputs: initialized SBRGrid struct for this channel
*
* Return: 0 if successful, error code (< 0) if error
**************************************************************************************/
static int UnpackSBRGrid(BitStreamInfo *bsi, SBRHeader *sbrHdr, SBRGrid *sbrGrid)
{
int numEnvRaw, env, rel, pBits, border, middleBorder=0;
unsigned char relBordLead[MAX_NUM_ENV] = {0}, relBordTrail[MAX_NUM_ENV] = {0};
unsigned char relBorder0[3], relBorder1[3], relBorder[3];
unsigned char numRelBorder0, numRelBorder1, numRelBorder, numRelLead=0, numRelTrail;
unsigned char absBordLead=0, absBordTrail=0, absBorder;
sbrGrid->ampResFrame = sbrHdr->ampRes;
sbrGrid->frameClass = GetBits(bsi, 2);
switch (sbrGrid->frameClass) {
case SBR_GRID_FIXFIX:
numEnvRaw = GetBits(bsi, 2);
sbrGrid->numEnv = (1 << numEnvRaw);
if (sbrGrid->numEnv == 1)
sbrGrid->ampResFrame = 0;
if(sbrGrid->numEnv != 1 && sbrGrid->numEnv != 2 && sbrGrid->numEnv != 4)
return ERR_AAC_UNKNOWN;
sbrGrid->freqRes[0] = GetBits(bsi, 1);
for (env = 1; env < sbrGrid->numEnv; env++)
sbrGrid->freqRes[env] = sbrGrid->freqRes[0];
absBordLead = 0;
absBordTrail = NUM_TIME_SLOTS;
numRelLead = sbrGrid->numEnv - 1;
numRelTrail = 0;
/* numEnv = 1, 2, or 4 */
if (sbrGrid->numEnv == 1) border = NUM_TIME_SLOTS / 1;
else if (sbrGrid->numEnv == 2) border = NUM_TIME_SLOTS / 2;
else border = NUM_TIME_SLOTS / 4;
for (rel = 0; rel < numRelLead; rel++)
relBordLead[rel] = border;
middleBorder = (sbrGrid->numEnv >> 1);
break;
case SBR_GRID_FIXVAR:
absBorder = GetBits(bsi, 2) + NUM_TIME_SLOTS;
numRelBorder = GetBits(bsi, 2);
sbrGrid->numEnv = numRelBorder + 1;
for (rel = 0; rel < numRelBorder; rel++)
relBorder[rel] = 2*GetBits(bsi, 2) + 2;
pBits = cLog2[sbrGrid->numEnv + 1];
sbrGrid->pointer = GetBits(bsi, pBits);
for (env = sbrGrid->numEnv - 1; env >= 0; env--)
sbrGrid->freqRes[env] = GetBits(bsi, 1);
absBordLead = 0;
absBordTrail = absBorder;
numRelLead = 0;
numRelTrail = numRelBorder;
for (rel = 0; rel < numRelTrail; rel++)
relBordTrail[rel] = relBorder[rel];
if (sbrGrid->pointer > 1) middleBorder = sbrGrid->numEnv + 1 - sbrGrid->pointer;
else middleBorder = sbrGrid->numEnv - 1;
break;
case SBR_GRID_VARFIX:
absBorder = GetBits(bsi, 2);
numRelBorder = GetBits(bsi, 2);
sbrGrid->numEnv = numRelBorder + 1;
for (rel = 0; rel < numRelBorder; rel++)
relBorder[rel] = 2*GetBits(bsi, 2) + 2;
pBits = cLog2[sbrGrid->numEnv + 1];
sbrGrid->pointer = GetBits(bsi, pBits);
for (env = 0; env < sbrGrid->numEnv; env++)
sbrGrid->freqRes[env] = GetBits(bsi, 1);
absBordLead = absBorder;
absBordTrail = NUM_TIME_SLOTS;
numRelLead = numRelBorder;
numRelTrail = 0;
for (rel = 0; rel < numRelLead; rel++)
relBordLead[rel] = relBorder[rel];
if (sbrGrid->pointer == 0) middleBorder = 1;
else if (sbrGrid->pointer == 1) middleBorder = sbrGrid->numEnv - 1;
else middleBorder = sbrGrid->pointer - 1;
break;
case SBR_GRID_VARVAR:
absBordLead = GetBits(bsi, 2); /* absBorder0 */
absBordTrail = GetBits(bsi, 2) + NUM_TIME_SLOTS; /* absBorder1 */
numRelBorder0 = GetBits(bsi, 2);
numRelBorder1 = GetBits(bsi, 2);
sbrGrid->numEnv = numRelBorder0 + numRelBorder1 + 1;
if(sbrGrid->numEnv > 5)
return ERR_AAC_UNKNOWN;
for (rel = 0; rel < numRelBorder0; rel++)
relBorder0[rel] = 2*GetBits(bsi, 2) + 2;
for (rel = 0; rel < numRelBorder1; rel++)
relBorder1[rel] = 2*GetBits(bsi, 2) + 2;
pBits = cLog2[numRelBorder0 + numRelBorder1 + 2];
sbrGrid->pointer = GetBits(bsi, pBits);
for (env = 0; env < sbrGrid->numEnv; env++)
sbrGrid->freqRes[env] = GetBits(bsi, 1);
numRelLead = numRelBorder0;
numRelTrail = numRelBorder1;
for (rel = 0; rel < numRelLead; rel++)
relBordLead[rel] = relBorder0[rel];
for (rel = 0; rel < numRelTrail; rel++)
relBordTrail[rel] = relBorder1[rel];
if (sbrGrid->pointer > 1) middleBorder = sbrGrid->numEnv + 1 - sbrGrid->pointer;
else middleBorder = sbrGrid->numEnv - 1;
break;
}
/* build time border vector */
sbrGrid->envTimeBorder[0] = absBordLead * SAMPLES_PER_SLOT;
rel = 0;
border = absBordLead;
for (env = 1; env <= numRelLead; env++) {
border += relBordLead[rel++];
sbrGrid->envTimeBorder[env] = border * SAMPLES_PER_SLOT;
}
rel = 0;
border = absBordTrail;
for (env = sbrGrid->numEnv - 1; env > numRelLead; env--) {
border -= relBordTrail[rel++];
sbrGrid->envTimeBorder[env] = border * SAMPLES_PER_SLOT;
}
sbrGrid->envTimeBorder[sbrGrid->numEnv] = absBordTrail * SAMPLES_PER_SLOT;
if (sbrGrid->numEnv > 1) {
sbrGrid->numNoiseFloors = 2;
sbrGrid->noiseTimeBorder[0] = sbrGrid->envTimeBorder[0];
sbrGrid->noiseTimeBorder[1] = sbrGrid->envTimeBorder[middleBorder];
sbrGrid->noiseTimeBorder[2] = sbrGrid->envTimeBorder[sbrGrid->numEnv];
} else {
sbrGrid->numNoiseFloors = 1;
sbrGrid->noiseTimeBorder[0] = sbrGrid->envTimeBorder[0];
sbrGrid->noiseTimeBorder[1] = sbrGrid->envTimeBorder[1];
}
return ERR_AAC_NONE;
}
/**************************************************************************************
* Function: UnpackDeltaTimeFreq
*
* Description: unpack time/freq flags for delta coding of SBR envelopes (table 4.63)
*
* Inputs: BitStreamInfo struct pointing to start of dt/df flags
* number of envelopes
* number of noise floors
*
* Outputs: delta flags for envelope and noise floors
*
* Return: none
**************************************************************************************/
static void UnpackDeltaTimeFreq(BitStreamInfo *bsi, int numEnv, unsigned char *deltaFlagEnv,
int numNoiseFloors, unsigned char *deltaFlagNoise)
{
int env, noiseFloor;
for (env = 0; env < numEnv; env++)
deltaFlagEnv[env] = GetBits(bsi, 1);
for (noiseFloor = 0; noiseFloor < numNoiseFloors; noiseFloor++)
deltaFlagNoise[noiseFloor] = GetBits(bsi, 1);
}
/**************************************************************************************
* Function: UnpackInverseFilterMode
*
* Description: unpack invf flags for chirp factor calculation (table 4.64)
*
* Inputs: BitStreamInfo struct pointing to start of invf flags
* number of noise floor bands
*
* Outputs: invf flags for noise floor bands
*
* Return: none
**************************************************************************************/
static void UnpackInverseFilterMode(BitStreamInfo *bsi, int numNoiseFloorBands, unsigned char *mode)
{
int n;
for (n = 0; n < numNoiseFloorBands; n++)
mode[n] = GetBits(bsi, 2);
}
/**************************************************************************************
* Function: UnpackSinusoids
*
* Description: unpack sinusoid (harmonic) flags for each SBR subband (table 4.67)
*
* Inputs: BitStreamInfo struct pointing to start of sinusoid flags
* number of high resolution SBR subbands (nHigh)
*
* Outputs: sinusoid flags for each SBR subband, zero-filled above nHigh
*
* Return: none
**************************************************************************************/
static void UnpackSinusoids(BitStreamInfo *bsi, int nHigh, int addHarmonicFlag, unsigned char *addHarmonic)
{
int n;
n = 0;
if (addHarmonicFlag) {
for ( ; n < nHigh; n++)
addHarmonic[n] = GetBits(bsi, 1);
}
/* zero out unused bands */
for ( ; n < MAX_QMF_BANDS; n++)
addHarmonic[n] = 0;
}
/**************************************************************************************
* Function: CopyCouplingGrid
*
* Description: copy grid parameters from left to right for channel coupling
*
* Inputs: initialized SBRGrid struct for left channel
*
* Outputs: initialized SBRGrid struct for right channel
*
* Return: none
**************************************************************************************/
static void CopyCouplingGrid(SBRGrid *sbrGridLeft, SBRGrid *sbrGridRight)
{
int env, noiseFloor;
sbrGridRight->frameClass = sbrGridLeft->frameClass;
sbrGridRight->ampResFrame = sbrGridLeft->ampResFrame;
sbrGridRight->pointer = sbrGridLeft->pointer;
sbrGridRight->numEnv = sbrGridLeft->numEnv;
for (env = 0; env < sbrGridLeft->numEnv; env++) {
sbrGridRight->envTimeBorder[env] = sbrGridLeft->envTimeBorder[env];
sbrGridRight->freqRes[env] = sbrGridLeft->freqRes[env];
}
sbrGridRight->envTimeBorder[env] = sbrGridLeft->envTimeBorder[env]; /* borders are [0, numEnv] inclusive */
sbrGridRight->numNoiseFloors = sbrGridLeft->numNoiseFloors;
for (noiseFloor = 0; noiseFloor <= sbrGridLeft->numNoiseFloors; noiseFloor++)
sbrGridRight->noiseTimeBorder[noiseFloor] = sbrGridLeft->noiseTimeBorder[noiseFloor];
/* numEnvPrev, numNoiseFloorsPrev, freqResPrev are updated in DecodeSBREnvelope() and DecodeSBRNoise() */
}
/**************************************************************************************
* Function: CopyCouplingInverseFilterMode
*
* Description: copy invf flags from left to right for channel coupling
*
* Inputs: invf flags for left channel
* number of noise floor bands
*
* Outputs: invf flags for right channel
*
* Return: none
**************************************************************************************/
static void CopyCouplingInverseFilterMode(int numNoiseFloorBands, unsigned char *modeLeft, unsigned char *modeRight)
{
int band;
for (band = 0; band < numNoiseFloorBands; band++)
modeRight[band] = modeLeft[band];
}
/**************************************************************************************
* Function: UnpackSBRSingleChannel
*
* Description: unpack sideband info (grid, delta flags, invf flags, envelope and
* noise floor configuration, sinusoids) for a single channel
*
* Inputs: BitStreamInfo struct pointing to start of sideband info
* initialized PSInfoSBR struct (after parsing SBR header and building
* frequency tables)
* base output channel (range = [0, nChans-1])
*
* Outputs: updated PSInfoSBR struct (SBRGrid and SBRChan)
*
* Return: 0 if successful, error code (< 0) if error
**************************************************************************************/
int UnpackSBRSingleChannel(BitStreamInfo *bsi, PSInfoSBR *psi, int chBase)
{
int bitsLeft, ret;
SBRHeader *sbrHdr = &(psi->sbrHdr[chBase]);
SBRGrid *sbrGridL = &(psi->sbrGrid[chBase+0]);
SBRFreq *sbrFreq = &(psi->sbrFreq[chBase]);
SBRChan *sbrChanL = &(psi->sbrChan[chBase+0]);
psi->dataExtra = GetBits(bsi, 1);
if (psi->dataExtra)
psi->resBitsData = GetBits(bsi, 4);
ret = UnpackSBRGrid(bsi, sbrHdr, sbrGridL);
if(ret != ERR_AAC_NONE)
return ret;
UnpackDeltaTimeFreq(bsi, sbrGridL->numEnv, sbrChanL->deltaFlagEnv, sbrGridL->numNoiseFloors, sbrChanL->deltaFlagNoise);
UnpackInverseFilterMode(bsi, sbrFreq->numNoiseFloorBands, sbrChanL->invfMode[1]);
ret = DecodeSBREnvelope(bsi, psi, sbrGridL, sbrFreq, sbrChanL, 0);
if(ret != ERR_AAC_NONE)
return ret;
ret = DecodeSBRNoise(bsi, psi, sbrGridL, sbrFreq, sbrChanL, 0);
if (ret != ERR_AAC_NONE)
return ret;
sbrChanL->addHarmonicFlag[1] = GetBits(bsi, 1);
UnpackSinusoids(bsi, sbrFreq->nHigh, sbrChanL->addHarmonicFlag[1], sbrChanL->addHarmonic[1]);
psi->extendedDataPresent = GetBits(bsi, 1);
if (psi->extendedDataPresent) {
psi->extendedDataSize = GetBits(bsi, 4);
if (psi->extendedDataSize == 15)
psi->extendedDataSize += GetBits(bsi, 8);
bitsLeft = 8 * psi->extendedDataSize;
/* get ID, unpack extension info, do whatever is necessary with it... */
while (bitsLeft > 0) {
GetBits(bsi, 8);
bitsLeft -= 8;
}
}
return ERR_AAC_NONE;
}
/**************************************************************************************
* Function: UnpackSBRChannelPair
*
* Description: unpack sideband info (grid, delta flags, invf flags, envelope and
* noise floor configuration, sinusoids) for a channel pair
*
* Inputs: BitStreamInfo struct pointing to start of sideband info
* initialized PSInfoSBR struct (after parsing SBR header and building
* frequency tables)
* base output channel (range = [0, nChans-1])
*
* Outputs: updated PSInfoSBR struct (SBRGrid and SBRChan for both channels)
*
* Return: 0 if successful, error code (< 0) if error
**************************************************************************************/
int UnpackSBRChannelPair(BitStreamInfo *bsi, PSInfoSBR *psi, int chBase)
{
int bitsLeft, ret;
SBRHeader *sbrHdr = &(psi->sbrHdr[chBase]);
SBRGrid *sbrGridL = &(psi->sbrGrid[chBase+0]), *sbrGridR = &(psi->sbrGrid[chBase+1]);
SBRFreq *sbrFreq = &(psi->sbrFreq[chBase]);
SBRChan *sbrChanL = &(psi->sbrChan[chBase+0]), *sbrChanR = &(psi->sbrChan[chBase+1]);
psi->dataExtra = GetBits(bsi, 1);
if (psi->dataExtra) {
psi->resBitsData = GetBits(bsi, 4);
psi->resBitsData = GetBits(bsi, 4);
}
psi->couplingFlag = GetBits(bsi, 1);
if (psi->couplingFlag) {
ret = UnpackSBRGrid(bsi, sbrHdr, sbrGridL);
if (ret != ERR_AAC_NONE)
return ret;
CopyCouplingGrid(sbrGridL, sbrGridR);
UnpackDeltaTimeFreq(bsi, sbrGridL->numEnv, sbrChanL->deltaFlagEnv, sbrGridL->numNoiseFloors, sbrChanL->deltaFlagNoise);
UnpackDeltaTimeFreq(bsi, sbrGridR->numEnv, sbrChanR->deltaFlagEnv, sbrGridR->numNoiseFloors, sbrChanR->deltaFlagNoise);
UnpackInverseFilterMode(bsi, sbrFreq->numNoiseFloorBands, sbrChanL->invfMode[1]);
CopyCouplingInverseFilterMode(sbrFreq->numNoiseFloorBands, sbrChanL->invfMode[1], sbrChanR->invfMode[1]);
ret = DecodeSBREnvelope(bsi, psi, sbrGridL, sbrFreq, sbrChanL, 0);
if (ret != ERR_AAC_NONE)
return ret;
ret = DecodeSBRNoise(bsi, psi, sbrGridL, sbrFreq, sbrChanL, 0);
if (ret != ERR_AAC_NONE)
return ret;
ret = DecodeSBREnvelope(bsi, psi, sbrGridR, sbrFreq, sbrChanR, 1);
if (ret != ERR_AAC_NONE)
return ret;
ret = DecodeSBRNoise(bsi, psi, sbrGridR, sbrFreq, sbrChanR, 1);
if (ret != ERR_AAC_NONE)
return ret;
/* pass RIGHT sbrChan struct */
UncoupleSBREnvelope(psi, sbrGridL, sbrFreq, sbrChanR);
UncoupleSBRNoise(psi, sbrGridL, sbrFreq, sbrChanR);
} else {
ret = UnpackSBRGrid(bsi, sbrHdr, sbrGridL);
if (ret != ERR_AAC_NONE)
return ret;
ret = UnpackSBRGrid(bsi, sbrHdr, sbrGridR);
if (ret != ERR_AAC_NONE)
return ret;
UnpackDeltaTimeFreq(bsi, sbrGridL->numEnv, sbrChanL->deltaFlagEnv, sbrGridL->numNoiseFloors, sbrChanL->deltaFlagNoise);
UnpackDeltaTimeFreq(bsi, sbrGridR->numEnv, sbrChanR->deltaFlagEnv, sbrGridR->numNoiseFloors, sbrChanR->deltaFlagNoise);
UnpackInverseFilterMode(bsi, sbrFreq->numNoiseFloorBands, sbrChanL->invfMode[1]);
UnpackInverseFilterMode(bsi, sbrFreq->numNoiseFloorBands, sbrChanR->invfMode[1]);
ret = DecodeSBREnvelope(bsi, psi, sbrGridL, sbrFreq, sbrChanL, 0);
if (ret != ERR_AAC_NONE)
return ret;
ret = DecodeSBREnvelope(bsi, psi, sbrGridR, sbrFreq, sbrChanR, 1);
if (ret != ERR_AAC_NONE)
return ret;
ret = DecodeSBRNoise(bsi, psi, sbrGridL, sbrFreq, sbrChanL, 0);
if (ret != ERR_AAC_NONE)
return ret;
ret = DecodeSBRNoise(bsi, psi, sbrGridR, sbrFreq, sbrChanR, 1);
if (ret != ERR_AAC_NONE)
return ret;
}
sbrChanL->addHarmonicFlag[1] = GetBits(bsi, 1);
UnpackSinusoids(bsi, sbrFreq->nHigh, sbrChanL->addHarmonicFlag[1], sbrChanL->addHarmonic[1]);
sbrChanR->addHarmonicFlag[1] = GetBits(bsi, 1);
UnpackSinusoids(bsi, sbrFreq->nHigh, sbrChanR->addHarmonicFlag[1], sbrChanR->addHarmonic[1]);
psi->extendedDataPresent = GetBits(bsi, 1);
if (psi->extendedDataPresent) {
psi->extendedDataSize = GetBits(bsi, 4);
if (psi->extendedDataSize == 15)
psi->extendedDataSize += GetBits(bsi, 8);
bitsLeft = 8 * psi->extendedDataSize;
/* get ID, unpack extension info, do whatever is necessary with it... */
while (bitsLeft > 0) {
GetBits(bsi, 8);
bitsLeft -= 8;
}
}
return ERR_AAC_NONE;
}