Revision 2d2692eb

View differences:

libavcodec/ac3enc.c
50 50
    int bits_written;
51 51
    int samples_written;
52 52

  
53
    int nb_all_channels;
54
    int nb_channels;
55
    int lfe;
53
    int fbw_channels;
54
    int channels;
55
    int lfe_on;
56 56
    int lfe_channel;
57 57
    int channel_mode;
58 58
    const uint8_t *channel_map;
59 59

  
60
    int chbwcod[AC3_MAX_CHANNELS];
60
    int bandwidth_code[AC3_MAX_CHANNELS];
61 61
    int nb_coefs[AC3_MAX_CHANNELS];
62 62

  
63 63
    /* bitrate allocation control */
......
432 432
    int16_t band_psd[NB_BLOCKS][AC3_MAX_CHANNELS][50];
433 433

  
434 434
    for(blk=0; blk<NB_BLOCKS; blk++) {
435
        for(ch=0;ch<s->nb_all_channels;ch++) {
435
        for(ch=0;ch<s->channels;ch++) {
436 436
            if(exp_strategy[blk][ch] == EXP_REUSE) {
437 437
                memcpy(psd[blk][ch], psd[blk-1][ch], (N/2)*sizeof(int16_t));
438 438
                memcpy(mask[blk][ch], mask[blk-1][ch], 50*sizeof(int16_t));
......
467 467
        s->mant1_cnt = 0;
468 468
        s->mant2_cnt = 0;
469 469
        s->mant4_cnt = 0;
470
        for(ch=0;ch<s->nb_all_channels;ch++) {
470
        for(ch=0;ch<s->channels;ch++) {
471 471
            ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,
472 472
                                      s->nb_coefs[ch], snr_offset,
473 473
                                      s->bit_alloc.floor, ff_ac3_bap_tab,
......
505 505
    s->slow_gain_code = 1;
506 506
    s->db_per_bit_code = 2;
507 507
    s->floor_code = 4;
508
    for(ch=0;ch<s->nb_all_channels;ch++)
508
    for(ch=0;ch<s->channels;ch++)
509 509
        s->fast_gain_code[ch] = 4;
510 510

  
511 511
    /* compute real values */
......
525 525

  
526 526
    /* audio blocks */
527 527
    for(i=0;i<NB_BLOCKS;i++) {
528
        frame_bits += s->nb_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
528
        frame_bits += s->fbw_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
529 529
        if (s->channel_mode == AC3_CHMODE_STEREO) {
530 530
            frame_bits++; /* rematstr */
531 531
            if(i==0) frame_bits += 4;
532 532
        }
533
        frame_bits += 2 * s->nb_channels; /* chexpstr[2] * c */
534
        if (s->lfe)
533
        frame_bits += 2 * s->fbw_channels; /* chexpstr[2] * c */
534
        if (s->lfe_on)
535 535
            frame_bits++; /* lfeexpstr */
536
        for(ch=0;ch<s->nb_channels;ch++) {
536
        for(ch=0;ch<s->fbw_channels;ch++) {
537 537
            if (exp_strategy[i][ch] != EXP_REUSE)
538 538
                frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
539 539
        }
......
546 546
    /* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */
547 547
    /* csnroffset[6] */
548 548
    /* (fsnoffset[4] + fgaincod[4]) * c */
549
    frame_bits += 2*4 + 3 + 6 + s->nb_all_channels * (4 + 3);
549
    frame_bits += 2*4 + 3 + 6 + s->channels * (4 + 3);
550 550

  
551 551
    /* auxdatae, crcrsv */
552 552
    frame_bits += 2;
......
595 595
    }
596 596

  
597 597
    s->coarse_snr_offset = coarse_snr_offset;
598
    for(ch=0;ch<s->nb_all_channels;ch++)
598
    for(ch=0;ch<s->channels;ch++)
599 599
        s->fine_snr_offset[ch] = fine_snr_offset;
600 600
#if defined(DEBUG_BITALLOC)
601 601
    {
602 602
        int j;
603 603

  
604 604
        for(i=0;i<6;i++) {
605
            for(ch=0;ch<s->nb_all_channels;ch++) {
605
            for(ch=0;ch<s->channels;ch++) {
606 606
                printf("Block #%d Ch%d:\n", i, ch);
607 607
                printf("bap=");
608 608
                for(j=0;j<s->nb_coefs[ch];j++) {
......
631 631
    if (av_get_channel_layout_nb_channels(ch_layout) != channels)
632 632
        return -1;
633 633

  
634
    s->lfe = !!(ch_layout & AV_CH_LOW_FREQUENCY);
635
    s->nb_all_channels = channels;
636
    s->nb_channels = channels - s->lfe;
637
    s->lfe_channel = s->lfe ? s->nb_channels : -1;
638
    if (s->lfe)
634
    s->lfe_on       = !!(ch_layout & AV_CH_LOW_FREQUENCY);
635
    s->channels     = channels;
636
    s->fbw_channels = channels - s->lfe_on;
637
    s->lfe_channel  = s->lfe_on ? s->fbw_channels : -1;
638
    if (s->lfe_on)
639 639
        ch_layout -= AV_CH_LOW_FREQUENCY;
640 640

  
641 641
    switch (ch_layout) {
......
652 652
        return -1;
653 653
    }
654 654

  
655
    s->channel_map = ff_ac3_enc_channel_map[s->channel_mode][s->lfe];
655
    s->channel_map = ff_ac3_enc_channel_map[s->channel_mode][s->lfe_on];
656 656
    *channel_layout = ch_layout;
657
    if (s->lfe)
657
    if (s->lfe_on)
658 658
        *channel_layout |= AV_CH_LOW_FREQUENCY;
659 659

  
660 660
    return 0;
......
723 723
           size, so that we avoid annoying high frequency artifacts */
724 724
        bw_code = 50;
725 725
    }
726
    for(ch=0;ch<s->nb_channels;ch++) {
726
    for(ch=0;ch<s->fbw_channels;ch++) {
727 727
        /* bandwidth for each channel */
728
        s->chbwcod[ch] = bw_code;
728
        s->bandwidth_code[ch] = bw_code;
729 729
        s->nb_coefs[ch] = bw_code * 3 + 73;
730 730
    }
731
    if (s->lfe) {
731
    if (s->lfe_on) {
732 732
        s->nb_coefs[s->lfe_channel] = 7; /* fixed */
733 733
    }
734 734
    /* initial snr offset */
......
766 766
        put_bits(&s->pb, 2, 1); /* XXX -6 dB */
767 767
    if (s->channel_mode == AC3_CHMODE_STEREO)
768 768
        put_bits(&s->pb, 2, 0); /* surround not indicated */
769
    put_bits(&s->pb, 1, s->lfe); /* LFE */
769
    put_bits(&s->pb, 1, s->lfe_on); /* LFE */
770 770
    put_bits(&s->pb, 5, 31); /* dialog norm: -31 db */
771 771
    put_bits(&s->pb, 1, 0); /* no compression control word */
772 772
    put_bits(&s->pb, 1, 0); /* no lang code */
......
833 833
    uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr;
834 834
    int delta0, delta1, delta2;
835 835

  
836
    for(ch=0;ch<s->nb_channels;ch++)
836
    for(ch=0;ch<s->fbw_channels;ch++)
837 837
        put_bits(&s->pb, 1, 0); /* 512 point MDCT */
838
    for(ch=0;ch<s->nb_channels;ch++)
838
    for(ch=0;ch<s->fbw_channels;ch++)
839 839
        put_bits(&s->pb, 1, 1); /* no dither */
840 840
    put_bits(&s->pb, 1, 0); /* no dynamic range */
841 841
    if (block_num == 0) {
......
872 872
    }
873 873
#endif
874 874
    /* exponent strategy */
875
    for(ch=0;ch<s->nb_channels;ch++) {
875
    for(ch=0;ch<s->fbw_channels;ch++) {
876 876
        put_bits(&s->pb, 2, exp_strategy[ch]);
877 877
    }
878 878

  
879
    if (s->lfe) {
879
    if (s->lfe_on) {
880 880
        put_bits(&s->pb, 1, exp_strategy[s->lfe_channel]);
881 881
    }
882 882

  
883
    for(ch=0;ch<s->nb_channels;ch++) {
883
    for(ch=0;ch<s->fbw_channels;ch++) {
884 884
        if (exp_strategy[ch] != EXP_REUSE)
885
            put_bits(&s->pb, 6, s->chbwcod[ch]);
885
            put_bits(&s->pb, 6, s->bandwidth_code[ch]);
886 886
    }
887 887

  
888 888
    /* exponents */
889
    for (ch = 0; ch < s->nb_all_channels; ch++) {
889
    for (ch = 0; ch < s->channels; ch++) {
890 890
        switch(exp_strategy[ch]) {
891 891
        case EXP_REUSE:
892 892
            continue;
......
948 948
    put_bits(&s->pb, 1, baie); /* always present with bai */
949 949
    if (baie) {
950 950
        put_bits(&s->pb, 6, s->coarse_snr_offset);
951
        for(ch=0;ch<s->nb_all_channels;ch++) {
951
        for(ch=0;ch<s->channels;ch++) {
952 952
            put_bits(&s->pb, 4, s->fine_snr_offset[ch]);
953 953
            put_bits(&s->pb, 3, s->fast_gain_code[ch]);
954 954
        }
......
965 965
    mant1_cnt = mant2_cnt = mant4_cnt = 0;
966 966
    qmant1_ptr = qmant2_ptr = qmant4_ptr = NULL;
967 967

  
968
    for (ch = 0; ch < s->nb_all_channels; ch++) {
968
    for (ch = 0; ch < s->channels; ch++) {
969 969
        int b, c, e, v;
970 970

  
971 971
        for(i=0;i<s->nb_coefs[ch];i++) {
......
1052 1052
    }
1053 1053

  
1054 1054
    /* second pass : output the values */
1055
    for (ch = 0; ch < s->nb_all_channels; ch++) {
1055
    for (ch = 0; ch < s->channels; ch++) {
1056 1056
        int b, q;
1057 1057

  
1058 1058
        for(i=0;i<s->nb_coefs[ch];i++) {
......
1201 1201
    int frame_bits;
1202 1202

  
1203 1203
    frame_bits = 0;
1204
    for(ch=0;ch<s->nb_all_channels;ch++) {
1204
    for(ch=0;ch<s->channels;ch++) {
1205 1205
        int ich = s->channel_map[ch];
1206 1206
        /* fixed mdct to the six sub blocks & exponent computation */
1207 1207
        for(i=0;i<NB_BLOCKS;i++) {
......
1210 1210

  
1211 1211
            /* compute input samples */
1212 1212
            memcpy(input_samples, s->last_samples[ich], N/2 * sizeof(int16_t));
1213
            sinc = s->nb_all_channels;
1213
            sinc = s->channels;
1214 1214
            sptr = samples + (sinc * (N/2) * i) + ich;
1215 1215
            for(j=0;j<N/2;j++) {
1216 1216
                v = *sptr;

Also available in: Unified diff