MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_subbands

Function encode_subbands

libavcodec/mpegaudioenc.c:604–665  ·  view source on GitHub ↗

Quantization & write sub band samples

Source from the content-addressed store, hash-verified

602
603/// Quantization & write sub band samples
604static av_always_inline void encode_subbands(MpegAudioContext *const s,
605 PutBitContext *const p,
606 const uint8_t bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],
607 int is_fixed)
608{
609 for (int k = 0; k < 3; ++k) {
610 for (int l = 0; l < 12; l += 3) {
611 for (int i = 0, j = 0; i < s->sblimit; ++i) {
612 const int bit_alloc_bits = s->alloc_table[j];
613 for (int ch = 0; ch < s->nb_channels; ++ch) {
614 const int b = bit_alloc[ch][i];
615 if (b) {
616 /* we encode 3 sub band samples of the same sub band at a time */
617 const int qindex = s->alloc_table[j + b];
618 const int steps = ff_mpa_quant_steps[qindex];
619 int q[3];
620
621 for (int m = 0; m < 3; ++m) {
622 const int sample = s->sb_samples[ch][k][l + m][i];
623 /* divide by scale factor */
624 if (!is_fixed) {
625 float a = (float)sample * s->scale_factor_inv_table[s->scale_factors[ch][i][k]];
626 q[m] = (int)((a + 1.0) * steps * 0.5);
627 } else {
628 const int e = s->scale_factors[ch][i][k];
629 const int shift = s->scale_factor_shift[e];
630 const int mult = s->scale_factor_mult[e];
631 int q1;
632
633 /* normalize to P bits */
634 if (shift < 0)
635 q1 = sample * (1 << -shift);
636 else
637 q1 = sample >> shift;
638 q1 = (q1 * mult) >> P;
639 q1 += 1 << P;
640 if (q1 < 0)
641 q1 = 0;
642 q[m] = (q1 * (unsigned)steps) >> (P + 1);
643 }
644 if (q[m] >= steps)
645 q[m] = steps - 1;
646 av_assert2(q[m] >= 0 && q[m] < steps);
647 }
648 const int bits = ff_mpa_quant_bits[qindex];
649 if (bits < 0) {
650 /* group the 3 values to save bits */
651 put_bits(p, -bits,
652 q[0] + steps * (q[1] + steps * q[2]));
653 } else {
654 put_bits(p, bits, q[0]);
655 put_bits(p, bits, q[1]);
656 put_bits(p, bits, q[2]);
657 }
658 }
659 }
660 /* next subband in alloc table */
661 j += 1 << bit_alloc_bits;

Callers 1

encode_frameFunction · 0.85

Calls 1

put_bitsFunction · 0.70

Tested by

no test coverage detected