av_log(AV_LOG_DEBUG, "Block #%d (%d)\n", block_num, count++);
av_log(NULL, AV_LOG_DEBUG, "Block #%d (%d)\n", block_num, count++);
static void output_audio_block(AC3EncodeContext *s,                               uint8_t exp_strategy[AC3_MAX_CHANNELS],                               uint8_t encoded_exp[AC3_MAX_CHANNELS][N/2],                               uint8_t bap[AC3_MAX_CHANNELS][N/2],                               int32_t mdct_coefs[AC3_MAX_CHANNELS][N/2],                               int8_t global_exp[AC3_MAX_CHANNELS],                               int block_num){    int ch, nb_groups, group_size, i, baie, rbnd;    uint8_t *p;    uint16_t qmant[AC3_MAX_CHANNELS][N/2];    int exp0, exp1;    int mant1_cnt, mant2_cnt, mant4_cnt;    uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr;    int delta0, delta1, delta2;    for(ch=0;ch<s->nb_channels;ch++)         put_bits(&s->pb, 1, 0); /* 512 point MDCT */    for(ch=0;ch<s->nb_channels;ch++)         put_bits(&s->pb, 1, 1); /* no dither */    put_bits(&s->pb, 1, 0); /* no dynamic range */    if (block_num == 0) {        /* for block 0, even if no coupling, we must say it. This is a           waste of bit :-) */        put_bits(&s->pb, 1, 1); /* coupling strategy present */        put_bits(&s->pb, 1, 0); /* no coupling strategy */    } else {        put_bits(&s->pb, 1, 0); /* no new coupling strategy */    }    if (s->acmod == 2)      {	if(block_num==0)	  {	    /* first block must define rematrixing (rematstr)  */	    put_bits(&s->pb, 1, 1); 	    	    /* dummy rematrixing rematflg(1:4)=0 */	    for (rbnd=0;rbnd<4;rbnd++)	      put_bits(&s->pb, 1, 0); 	  }	else 	  {	    /* no matrixing (but should be used in the future) */	    put_bits(&s->pb, 1, 0);	  }       }#if defined(DEBUG)     {      static int count = 0;      av_log(AV_LOG_DEBUG, "Block #%d (%d)\n", block_num, count++);    }#endif    /* exponent strategy */    for(ch=0;ch<s->nb_channels;ch++) {        put_bits(&s->pb, 2, exp_strategy[ch]);    }        if (s->lfe) {	put_bits(&s->pb, 1, exp_strategy[s->lfe_channel]);    }    for(ch=0;ch<s->nb_channels;ch++) {        if (exp_strategy[ch] != EXP_REUSE)            put_bits(&s->pb, 6, s->chbwcod[ch]);    }        /* exponents */    for (ch = 0; ch < s->nb_all_channels; ch++) {        switch(exp_strategy[ch]) {        case EXP_REUSE:            continue;        case EXP_D15:            group_size = 1;            break;        case EXP_D25:            group_size = 2;            break;        default:        case EXP_D45:            group_size = 4;            break;        }	nb_groups = (s->nb_coefs[ch] + (group_size * 3) - 4) / (3 * group_size);        p = encoded_exp[ch];        /* first exponent */        exp1 = *p++;        put_bits(&s->pb, 4, exp1);        /* next ones are delta encoded */        for(i=0;i<nb_groups;i++) {            /* merge three delta in one code */            exp0 = exp1;            exp1 = p[0];            p += group_size;            delta0 = exp1 - exp0 + 2;            exp0 = exp1;            exp1 = p[0];            p += group_size;            delta1 = exp1 - exp0 + 2;            exp0 = exp1;            exp1 = p[0];            p += group_size;            delta2 = exp1 - exp0 + 2;            put_bits(&s->pb, 7, ((delta0 * 5 + delta1) * 5) + delta2);        }	if (ch != s->lfe_channel)	    put_bits(&s->pb, 2, 0); /* no gain range info */    }    /* bit allocation info */    baie = (block_num == 0);    put_bits(&s->pb, 1, baie);    if (baie) {        put_bits(&s->pb, 2, s->sdecaycod);        put_bits(&s->pb, 2, s->fdecaycod);        put_bits(&s->pb, 2, s->sgaincod);        put_bits(&s->pb, 2, s->dbkneecod);        put_bits(&s->pb, 3, s->floorcod);    }    /* snr offset */    put_bits(&s->pb, 1, baie); /* always present with bai */    if (baie) {        put_bits(&s->pb, 6, s->csnroffst);        for(ch=0;ch<s->nb_all_channels;ch++) {            put_bits(&s->pb, 4, s->fsnroffst[ch]);            put_bits(&s->pb, 3, s->fgaincod[ch]);        }    }        put_bits(&s->pb, 1, 0); /* no delta bit allocation */    put_bits(&s->pb, 1, 0); /* no data to skip */    /* mantissa encoding : we use two passes to handle the grouping. A       one pass method may be faster, but it would necessitate to       modify the output stream. */    /* first pass: quantize */    mant1_cnt = mant2_cnt = mant4_cnt = 0;    qmant1_ptr = qmant2_ptr = qmant4_ptr = NULL;    for (ch = 0; ch < s->nb_all_channels; ch++) {        int b, c, e, v;        for(i=0;i<s->nb_coefs[ch];i++) {            c = mdct_coefs[ch][i];            e = encoded_exp[ch][i] - global_exp[ch];            b = bap[ch][i];            switch(b) {            case 0:                v = 0;                break;            case 1:                v = sym_quant(c, e, 3);                switch(mant1_cnt) {                case 0:                    qmant1_ptr = &qmant[ch][i];                    v = 9 * v;                    mant1_cnt = 1;                    break;                case 1:                    *qmant1_ptr += 3 * v;                    mant1_cnt = 2;                    v = 128;                    break;                default:                    *qmant1_ptr += v;                    mant1_cnt = 0;                    v = 128;                    break;                }                break;            case 2:                v = sym_quant(c, e, 5);                switch(mant2_cnt) {                case 0:                    qmant2_ptr = &qmant[ch][i];                    v = 25 * v;                    mant2_cnt = 1;                    break;                case 1:                    *qmant2_ptr += 5 * v;                    mant2_cnt = 2;                    v = 128;                    break;                default:                    *qmant2_ptr += v;                    mant2_cnt = 0;                    v = 128;                    break;                }                break;            case 3:                v = sym_quant(c, e, 7);                break;            case 4:                v = sym_quant(c, e, 11);                switch(mant4_cnt) {                case 0:                    qmant4_ptr = &qmant[ch][i];                    v = 11 * v;                    mant4_cnt = 1;                    break;                default:                    *qmant4_ptr += v;                    mant4_cnt = 0;                    v = 128;                    break;                }                break;            case 5:                v = sym_quant(c, e, 15);                break;            case 14:                v = asym_quant(c, e, 14);                break;            case 15:                v = asym_quant(c, e, 16);                break;            default:                v = asym_quant(c, e, b - 1);                break;            }            qmant[ch][i] = v;        }    }    /* second pass : output the values */    for (ch = 0; ch < s->nb_all_channels; ch++) {        int b, q;                for(i=0;i<s->nb_coefs[ch];i++) {            q = qmant[ch][i];            b = bap[ch][i];            switch(b) {            case 0:                break;            case 1:                if (q != 128)                     put_bits(&s->pb, 5, q);                break;            case 2:                if (q != 128)                     put_bits(&s->pb, 7, q);                break;            case 3:                put_bits(&s->pb, 3, q);                break;            case 4:                if (q != 128)                    put_bits(&s->pb, 7, q);                break;            case 14:                put_bits(&s->pb, 14, q);                break;            case 15:                put_bits(&s->pb, 16, q);                break;            default:                put_bits(&s->pb, b - 1, q);                break;            }        }    }}