FastLED 3.9.15
Loading...
Searching...
No Matches

◆ DequantChannel()

int32_t fl::third_party::DequantChannel ( int32_t * sampleBuf,
int32_t * workBuf,
int32_t * nonZeroBound,
FrameHeader * fh,
SideInfoSub * sis,
ScaleFactorInfoSub * sfis,
CriticalBandInfo * cbi )

Definition at line 252 of file dqchan.hpp.

254{
255 int32_t i, j, w, cb;
256 int32_t cbEndL, cbStartS, cbEndS;
257 int32_t nSamps, nonZero, sfactMultiplier, gbMask;
258 int32_t globalGain, gainI;
259 int32_t cbMax[3];
260 ARRAY3 *buf; /* short block reorder */
261
262 /* set default start/end points for short/long blocks - will update with non-zero cb info */
263 if (sis->blockType == 2) {
264 if (sis->mixedBlock) {
265 cbEndL = (fh->ver == MPEG1 ? 8 : 6);
266 cbStartS = 3;
267 } else {
268 cbEndL = 0;
269 cbStartS = 0;
270 }
271 cbEndS = 13;
272 } else {
273 /* long block */
274 cbEndL = 22;
275 cbStartS = 13;
276 cbEndS = 13;
277 }
278 cbMax[2] = cbMax[1] = cbMax[0] = 0;
279 gbMask = 0;
280 i = 0;
281
282 /* sfactScale = 0 --> quantizer step size = 2
283 * sfactScale = 1 --> quantizer step size = sqrt(2)
284 * so sfactMultiplier = 2 or 4 (jump through globalGain by powers of 2 or sqrt(2))
285 */
286 sfactMultiplier = 2 * (sis->sfactScale + 1);
287
288 /* offset globalGain by -2 if midSide enabled, for 1/sqrt(2) used in MidSideProc()
289 * (DequantBlock() does 0.25 * gainI so knocking it down by two is the same as
290 * dividing every sample by sqrt(2) = multiplying by 2^-.5)
291 */
292 globalGain = sis->globalGain;
293 if (fh->modeExt >> 1)
294 globalGain -= 2;
295 globalGain += IMDCT_SCALE; /* scale everything by sqrt(2), for fast IMDCT36 */
296
297 /* long blocks */
298 for (cb = 0; cb < cbEndL; cb++) {
299
300 nonZero = 0;
301 nSamps = fh->sfBand->l[cb + 1] - fh->sfBand->l[cb];
302 gainI = 210 - globalGain + sfactMultiplier * (sfis->l[cb] + (sis->preFlag ? (int)preTab[cb] : 0));
303
304 nonZero |= DequantBlock(sampleBuf + i, sampleBuf + i, nSamps, gainI);
305 i += nSamps;
306
307 /* update highest non-zero critical band */
308 if (nonZero)
309 cbMax[0] = cb;
310 gbMask |= nonZero;
311
312 if (i >= *nonZeroBound)
313 break;
314 }
315
316 /* set cbi (Type, EndS[], EndSMax will be overwritten if we proceed to do short blocks) */
317 cbi->cbType = 0; /* long only */
318 cbi->cbEndL = cbMax[0];
319 cbi->cbEndS[0] = cbi->cbEndS[1] = cbi->cbEndS[2] = 0;
320 cbi->cbEndSMax = 0;
321
322 /* early exit if no short blocks */
323 if (cbStartS >= 12)
324 return CLZ(gbMask) - 1;
325
326 /* short blocks */
327 cbMax[2] = cbMax[1] = cbMax[0] = cbStartS;
328 for (cb = cbStartS; cb < cbEndS; cb++) {
329
330 nSamps = fh->sfBand->s[cb + 1] - fh->sfBand->s[cb];
331 for (w = 0; w < 3; w++) {
332 nonZero = 0;
333 gainI = 210 - globalGain + 8*sis->subBlockGain[w] + sfactMultiplier*(sfis->s[cb][w]);
334
335 nonZero |= DequantBlock(sampleBuf + i + nSamps*w, workBuf + nSamps*w, nSamps, gainI);
336
337 /* update highest non-zero critical band */
338 if (nonZero)
339 cbMax[w] = cb;
340 gbMask |= nonZero;
341 }
342
343 /* reorder blocks */
344 buf = (ARRAY3 *)(sampleBuf + i);
345 i += 3*nSamps;
346 for (j = 0; j < nSamps; j++) {
347 buf[j][0] = workBuf[0*nSamps + j];
348 buf[j][1] = workBuf[1*nSamps + j];
349 buf[j][2] = workBuf[2*nSamps + j];
350 }
351
352 ASSERT(3*nSamps <= MAX_REORDER_SAMPS);
353
354 if (i >= *nonZeroBound)
355 break;
356 }
357
358 /* i = last non-zero INPUT sample processed, which corresponds to highest possible non-zero
359 * OUTPUT sample (after reorder)
360 * however, the original nzb is no longer necessarily true
361 * for each cb, buf[][] is updated with 3*nSamps samples (i increases 3*nSamps each time)
362 * (buf[j + 1][0] = 3 (input) samples ahead of buf[j][0])
363 * so update nonZeroBound to i
364 */
365 *nonZeroBound = i;
366
367 ASSERT(*nonZeroBound <= MAX_NSAMP);
368
369 cbi->cbType = (sis->mixedBlock ? 2 : 1); /* 2 = mixed short/long, 1 = short only */
370
371 cbi->cbEndS[0] = cbMax[0];
372 cbi->cbEndS[1] = cbMax[1];
373 cbi->cbEndS[2] = cbMax[2];
374
375 cbi->cbEndSMax = cbMax[0];
376 cbi->cbEndSMax = MAX(cbi->cbEndSMax, cbMax[1]);
377 cbi->cbEndSMax = MAX(cbi->cbEndSMax, cbMax[2]);
378
379 return CLZ(gbMask) - 1;
380}
#define MAX_REORDER_SAMPS
Definition coder.h:108
#define ASSERT(x)
Definition coder.h:56
#define IMDCT_SCALE
Definition coder.h:103
#define MAX(a, b)
Definition coder.h:60
@ MPEG1
Definition mp3dec.h:83
#define MAX_NSAMP
Definition mp3dec.h:79
static int DequantBlock(int32_t *inbuf, int32_t *outbuf, int num, int scale) FL_NOEXCEPT
Definition dqchan.hpp:140
static const char preTab[22]
Definition dqchan.hpp:58
int ARRAY3[3]
Definition dqchan.hpp:55
fl::i32 int32_t
Definition coder.h:220
__inline int32_t CLZ(int32_t x) FL_NOEXCEPT
Leading zeros.
Definition assembly.h:527
const SFBandTable * sfBand
Definition coder.h:175

References ASSERT, CLZ(), DequantBlock(), FL_NOEXCEPT, IMDCT_SCALE, MAX, MAX_NSAMP, MAX_REORDER_SAMPS, MPEG1, and preTab.

Referenced by Dequantize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: