Lines Matching refs:state

56     a52_state_t * state;
59 state = malloc (sizeof (a52_state_t));
60 if (state == NULL)
63 state->samples = memalign (16, 256 * 12 * sizeof (sample_t));
64 if (state->samples == NULL) {
65 free (state);
70 state->samples[i] = 0;
72 state->downmixed = 1;
74 state->lfsr_state = 1;
78 return state;
81 sample_t * a52_samples (a52_state_t * state)
83 return state->samples;
131 int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
139 state->fscod = buf[4] >> 6;
140 state->halfrate = halfrate[buf[5] >> 3];
141 state->acmod = acmod = buf[6] >> 5;
143 a52_bitstream_set_ptr (state, buf + 6);
144 bitstream_get (state, 3); /* skip acmod we already parsed */
146 if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */
150 state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */
153 state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */
155 state->lfeon = bitstream_get (state, 1);
157 state->output = a52_downmix_init (acmod, *flags, level,
158 state->clev, state->slev);
159 if (state->output < 0)
161 if (state->lfeon && (*flags & A52_LFE))
162 state->output |= A52_LFE;
163 *flags = state->output;
165 state->dynrng = state->level = 2 * *level;
166 state->bias = bias;
167 state->dynrnge = 1;
168 state->dynrngcall = NULL;
169 state->cplba.deltbae = DELTA_BIT_NONE;
170 state->ba[0].deltbae = state->ba[1].deltbae = state->ba[2].deltbae =
171 state->ba[3].deltbae = state->ba[4].deltbae = DELTA_BIT_NONE;
175 bitstream_get (state, 5); /* dialnorm */
176 if (bitstream_get (state, 1)) /* compre */
177 bitstream_get (state, 8); /* compr */
178 if (bitstream_get (state, 1)) /* langcode */
179 bitstream_get (state, 8); /* langcod */
180 if (bitstream_get (state, 1)) /* audprodie */
181 bitstream_get (state, 7); /* mixlevel + roomtyp */
184 bitstream_get (state, 2); /* copyrightb + origbs */
186 if (bitstream_get (state, 1)) /* timecod1e */
187 bitstream_get (state, 14); /* timecod1 */
188 if (bitstream_get (state, 1)) /* timecod2e */
189 bitstream_get (state, 14); /* timecod2 */
191 if (bitstream_get (state, 1)) { /* addbsie */
194 addbsil = bitstream_get (state, 6);
196 bitstream_get (state, 8); /* addbsi */
203 void a52_dynrng (a52_state_t * state,
206 state->dynrnge = 0;
208 state->dynrnge = 1;
209 state->dynrngcall = call;
210 state->dynrngdata = data;
214 static int parse_exponents (a52_state_t * state, int expstr, int ngrps,
220 exps = bitstream_get (state, 7);
268 static int parse_deltba (a52_state_t * state, int8_t * deltba)
274 deltnseg = bitstream_get (state, 3);
277 j += bitstream_get (state, 5);
278 deltlen = bitstream_get (state, 4);
279 delta = bitstream_get (state, 3);
292 static inline int zero_snr_offsets (int nfchans, a52_state_t * state)
296 if ((state->csnroffst) ||
297 (state->chincpl && state->cplba.bai >> 3) || /* cplinu, fsnroffst */
298 (state->lfeon && state->lfeba.bai >> 3)) /* fsnroffst */
301 if (state->ba[i].bai >> 3) /* fsnroffst */
306 static inline int16_t dither_gen (a52_state_t * state)
310 nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8);
312 state->lfsr_state = (uint16_t) nstate;
317 static void coeff_get (a52_state_t * state, sample_t * coeff,
339 coeff[i] = dither_gen (state) * LEVEL_3DB * factor[exp[i]];
353 code = bitstream_get (state, 5);
369 code = bitstream_get (state, 7);
379 coeff[i] = q_3[bitstream_get (state, 3)] * factor[exp[i]];
390 code = bitstream_get (state, 7);
399 coeff[i] = q_5[bitstream_get (state, 4)] * factor[exp[i]];
403 coeff[i] = ((bitstream_get_2 (state, bapi) << (16 - bapi)) *
409 static void coeff_get_coupling (a52_state_t * state, int nfchans,
418 exp = state->cpl_expbap.exp;
419 bap = state->cpl_expbap.bap;
421 cplbndstrc = state->cplbndstrc;
422 i = state->cplstrtmant;
423 while (i < state->cplendmant) {
431 cplco[ch] = state->cplco[ch][bnd] * coeff[ch];
443 if ((state->chincpl >> ch) & 1) {
446 dither_gen (state));
460 code = bitstream_get (state, 5);
476 code = bitstream_get (state, 7);
486 cplcoeff = q_3[bitstream_get (state, 3)];
497 code = bitstream_get (state, 7);
506 cplcoeff = q_5[bitstream_get (state, 4)];
510 cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi);
515 if ((state->chincpl >> ch) & 1)
522 int a52_block (a52_state_t * state)
534 nfchans = nfchans_tbl[state->acmod];
537 blksw[i] = bitstream_get (state, 1);
540 dithflag[i] = bitstream_get (state, 1);
542 chaninfo = !state->acmod;
544 if (bitstream_get (state, 1)) { /* dynrnge */
547 dynrng = bitstream_get_2 (state, 8);
548 if (state->dynrnge) {
553 if (state->dynrngcall)
554 range = state->dynrngcall (range, state->dynrngdata);
555 state->dynrng = state->level * range;
560 if (bitstream_get (state, 1)) { /* cplstre */
561 state->chincpl = 0;
562 if (bitstream_get (state, 1)) { /* cplinu */
570 state->chincpl |= bitstream_get (state, 1) << i;
571 switch (state->acmod) {
575 state->phsflginu = bitstream_get (state, 1);
577 cplbegf = bitstream_get (state, 4);
578 cplendf = bitstream_get (state, 4);
582 state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf;
583 state->cplstrtbnd = bndtab[cplbegf];
584 state->cplstrtmant = cplbegf * 12 + 37;
585 state->cplendmant = cplendf * 12 + 73;
587 state->cplbndstrc = 0;
589 if (bitstream_get (state, 1)) {
590 state->cplbndstrc |= 1 << i;
591 state->ncplbnd--;
596 if (state->chincpl) { /* cplinu */
601 if ((state->chincpl) >> i & 1)
602 if (bitstream_get (state, 1)) { /* cplcoe */
606 mstrcplco = 3 * bitstream_get (state, 2);
607 for (j = 0; j < state->ncplbnd; j++) {
608 cplcoexp = bitstream_get (state, 4);
609 cplcomant = bitstream_get (state, 4);
614 state->cplco[i][j] =
618 if ((state->acmod == 2) && state->phsflginu && cplcoe)
619 for (j = 0; j < state->ncplbnd; j++)
620 if (bitstream_get (state, 1)) /* phsflg */
621 state->cplco[1][j] = -state->cplco[1][j];
624 if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */
627 state->rematflg = 0;
628 end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */
631 state->rematflg |= bitstream_get (state, 1) << i;
637 if (state->chincpl) /* cplinu */
638 cplexpstr = bitstream_get (state, 2);
640 chexpstr[i] = bitstream_get (state, 2);
641 if (state->lfeon)
642 lfeexpstr = bitstream_get (state, 1);
646 if ((state->chincpl >> i) & 1)
647 state->endmant[i] = state->cplstrtmant;
651 chbwcod = bitstream_get (state, 6);
654 state->endmant[i] = chbwcod * 3 + 73;
664 ncplgrps = ((state->cplendmant - state->cplstrtmant) /
666 cplabsexp = bitstream_get (state, 4) << 1;
667 if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp,
668 state->cpl_expbap.exp + state->cplstrtmant))
677 nchgrps = (state->endmant[i] + grp_size - 4) / grp_size;
678 state->fbw_expbap[i].exp[0] = bitstream_get (state, 4);
679 if (parse_exponents (state, chexpstr[i], nchgrps,
680 state->fbw_expbap[i].exp[0],
681 state->fbw_expbap[i].exp + 1))
683 bitstream_get (state, 2); /* gainrng */
687 state->lfe_expbap.exp[0] = bitstream_get (state, 4);
688 if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0],
689 state->lfe_expbap.exp + 1))
693 if (bitstream_get (state, 1)) { /* baie */
695 state->bai = bitstream_get (state, 11);
697 if (bitstream_get (state, 1)) { /* snroffste */
699 state->csnroffst = bitstream_get (state, 6);
700 if (state->chincpl) /* cplinu */
701 state->cplba.bai = bitstream_get (state, 7);
703 state->ba[i].bai = bitstream_get (state, 7);
704 if (state->lfeon)
705 state->lfeba.bai = bitstream_get (state, 7);
707 if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */
709 state->cplfleak = 9 - bitstream_get (state, 3);
710 state->cplsleak = 9 - bitstream_get (state, 3);
713 if (bitstream_get (state, 1)) { /* deltbaie */
715 if (state->chincpl) /* cplinu */
716 state->cplba.deltbae = bitstream_get (state, 2);
718 state->ba[i].deltbae = bitstream_get (state, 2);
719 if (state->chincpl && /* cplinu */
720 (state->cplba.deltbae == DELTA_BIT_NEW) &&
721 parse_deltba (state, state->cplba.deltba))
724 if ((state->ba[i].deltbae == DELTA_BIT_NEW) &&
725 parse_deltba (state, state->ba[i].deltba))
730 if (zero_snr_offsets (nfchans, state)) {
731 memset (state->cpl_expbap.bap, 0, sizeof (state->cpl_expbap.bap));
733 memset (state->fbw_expbap[i].bap, 0,
734 sizeof (state->fbw_expbap[i].bap));
735 memset (state->lfe_expbap.bap, 0, sizeof (state->lfe_expbap.bap));
737 if (state->chincpl && (do_bit_alloc & 64)) /* cplinu */
738 a52_bit_allocate (state, &state->cplba, state->cplstrtbnd,
739 state->cplstrtmant, state->cplendmant,
740 state->cplfleak << 8, state->cplsleak << 8,
741 &state->cpl_expbap);
744 a52_bit_allocate (state, state->ba + i, 0, 0,
745 state->endmant[i], 0, 0,
746 state->fbw_expbap +i);
747 if (state->lfeon && (do_bit_alloc & 32)) {
748 state->lfeba.deltbae = DELTA_BIT_NONE;
749 a52_bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0,
750 &state->lfe_expbap);
755 if (bitstream_get (state, 1)) { /* skiple */
756 i = bitstream_get (state, 9); /* skipl */
758 bitstream_get (state, 8);
761 samples = state->samples;
762 if (state->output & A52_LFE)
765 chanbias = a52_downmix_coeff (coeff, state->acmod, state->output,
766 state->dynrng, state->clev, state->slev);
774 coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quantizer,
775 coeff[i], dithflag[i], state->endmant[i]);
777 if ((state->chincpl >> i) & 1) {
780 coeff_get_coupling (state, nfchans, coeff,
784 j = state->cplendmant;
786 j = state->endmant[i];
792 if (state->acmod == 2) {
795 end = ((state->endmant[0] < state->endmant[1]) ?
796 state->endmant[0] : state->endmant[1]);
800 rematflg = state->rematflg;
822 if (state->lfeon) {
823 if (state->output & A52_LFE) {
824 coeff_get (state, samples - 256, &state->lfe_expbap, &quantizer,
825 state->dynrng, 0, 7);
828 a52_imdct_512 (samples - 256, samples + 1536 - 256, state->bias);
831 coeff_get (state, samples + 1280, &state->lfe_expbap, &quantizer,
837 if (nfchans_tbl[state->output & A52_CHANNEL_MASK] < nfchans)
843 if (state->downmixed) {
844 state->downmixed = 0;
845 a52_upmix (samples + 1536, state->acmod, state->output);
853 bias = state->bias;
870 a52_downmix (samples, state->acmod, state->output, state->bias,
871 state->clev, state->slev);
873 nfchans = nfchans_tbl[state->output & A52_CHANNEL_MASK];
875 a52_downmix (samples, state->acmod, state->output, 0,
876 state->clev, state->slev);
878 if (!state->downmixed) {
879 state->downmixed = 1;
880 a52_downmix (samples + 1536, state->acmod, state->output, 0,
881 state->clev, state->slev);
887 state->bias);
891 state->bias);
897 void a52_free (a52_state_t * state)
899 free (state->samples);
900 free (state);