diff options
author | Diego Biurrun <diego@biurrun.de> | 2005-12-17 18:14:38 +0000 |
---|---|---|
committer | Diego Biurrun <diego@biurrun.de> | 2005-12-17 18:14:38 +0000 |
commit | 115329f16062074e11ccf3b89ead6176606c9696 (patch) | |
tree | e98aa993905a702688bf821737ab9a443969fc28 /libavcodec/ac3enc.c | |
parent | d76319b1ab716320f6e6a4d690b85fe4504ebd5b (diff) | |
download | ffmpeg-115329f16062074e11ccf3b89ead6176606c9696.tar.gz |
COSMETICS: Remove all trailing whitespace.
Originally committed as revision 4749 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r-- | libavcodec/ac3enc.c | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index aae06e4545..a8c90b355d 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -46,9 +46,9 @@ typedef struct AC3EncodeContext { short last_samples[AC3_MAX_CHANNELS][256]; unsigned int chbwcod[AC3_MAX_CHANNELS]; int nb_coefs[AC3_MAX_CHANNELS]; - + /* bitrate allocation control */ - int sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod; + int sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod; AC3BitAllocParameters bit_alloc; int csnroffst; int fgaincod[AC3_MAX_CHANNELS]; @@ -74,7 +74,7 @@ static inline int16_t fix15(float a) v = (int)(a * (float)(1 << 15)); if (v < -32767) v = -32767; - else if (v > 32767) + else if (v > 32767) v = 32767; return v; } @@ -83,7 +83,7 @@ static inline int calc_lowcomp1(int a, int b0, int b1) { if ((b0 + 256) == b1) { a = 384 ; - } else if (b0 > b1) { + } else if (b0 > b1) { a = a - 64; if (a < 0) a=0; } @@ -95,7 +95,7 @@ static inline int calc_lowcomp(int a, int b0, int b1, int bin) if (bin < 7) { if ((b0 + 256) == b1) { a = 384 ; - } else if (b0 > b1) { + } else if (b0 > b1) { a = a - 64; if (a < 0) a=0; } @@ -118,7 +118,7 @@ static inline int calc_lowcomp(int a, int b0, int b1, int bin) void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, int8_t *exp, int start, int end, int snroffset, int fgain, int is_lfe, - int deltbae,int deltnseg, + int deltbae,int deltnseg, uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba) { int bin,i,j,k,end1,v,v1,bndstrt,bndend,lowcomp,begin; @@ -164,7 +164,7 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, /* excitation function */ bndstrt = masktab[start]; bndend = masktab[end-1] + 1; - + if (bndstrt == 0) { lowcomp = 0; lowcomp = calc_lowcomp1(lowcomp, bndpsd[0], bndpsd[1]) ; @@ -185,32 +185,32 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, } } } - + end1=bndend; if (end1 > 22) end1=22; - + for (bin = begin; bin < end1; bin++) { if (!(is_lfe && bin == 6)) lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin) ; - + fastleak -= s->fdecay ; v = bndpsd[bin] - fgain; if (fastleak < v) fastleak = v; - + slowleak -= s->sdecay ; v = bndpsd[bin] - s->sgain; if (slowleak < v) slowleak = v; - + v=fastleak - lowcomp; if (slowleak > v) v=slowleak; - + excite[bin] = v; } begin = 22; } else { /* coupling channel */ begin = bndstrt; - + fastleak = (s->cplfleak << 8) + 768; slowleak = (s->cplsleak << 8) + 768; } @@ -261,7 +261,7 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, } /* compute bit allocation */ - + i = start ; j = masktab[start] ; do { @@ -361,7 +361,7 @@ static void fft(IComplex *z, int ln) p=&z[0]; j=(np >> 1); do { - BF(p[0].re, p[0].im, p[1].re, p[1].im, + BF(p[0].re, p[0].im, p[1].re, p[1].im, p[0].re, p[0].im, p[1].re, p[1].im); p+=2; } while (--j != 0); @@ -371,9 +371,9 @@ static void fft(IComplex *z, int ln) p=&z[0]; j=np >> 2; do { - BF(p[0].re, p[0].im, p[2].re, p[2].im, + BF(p[0].re, p[0].im, p[2].re, p[2].im, p[0].re, p[0].im, p[2].re, p[2].im); - BF(p[1].re, p[1].im, p[3].re, p[3].im, + BF(p[1].re, p[1].im, p[3].re, p[3].im, p[1].re, p[1].im, p[3].im, -p[3].re); p+=4; } while (--j != 0); @@ -390,7 +390,7 @@ static void fft(IComplex *z, int ln) BF(p->re, p->im, q->re, q->im, p->re, p->im, q->re, q->im); - + p++; q++; for(l = nblocks; l < np2; l += nblocks) { @@ -412,7 +412,7 @@ static void fft(IComplex *z, int ln) static void mdct512(int32_t *out, int16_t *in) { int i, re, im, re1, im1; - int16_t rot[N]; + int16_t rot[N]; IComplex x[N/4]; /* shift to simplify computations */ @@ -420,7 +420,7 @@ static void mdct512(int32_t *out, int16_t *in) rot[i] = -in[i + 3*N/4]; for(i=N/4;i<N;i++) rot[i] = in[i - N/4]; - + /* pre rotation */ for(i=0;i<N/4;i++) { re = ((int)rot[2*i] - (int)rot[N-1-2*i]) >> 1; @@ -429,7 +429,7 @@ static void mdct512(int32_t *out, int16_t *in) } fft(x, MDCT_NBITS - 2); - + /* post rotation */ for(i=0;i<N/4;i++) { re = x[i].re; @@ -457,13 +457,13 @@ static void compute_exp_strategy(uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNEL { int i, j; int exp_diff; - + /* estimate if the exponent variation & decide if they should be reused in the next frame */ exp_strategy[0][ch] = EXP_NEW; for(i=1;i<NB_BLOCKS;i++) { exp_diff = calc_exp_diff(exp[i][ch], exp[i-1][ch], N/2); -#ifdef DEBUG +#ifdef DEBUG av_log(NULL, AV_LOG_DEBUG, "exp_diff=%d\n", exp_diff); #endif if (exp_diff > EXP_DIFF_THRESHOLD) @@ -507,11 +507,11 @@ static void exponent_min(uint8_t exp[N/2], uint8_t exp1[N/2], int n) exp[i] = exp1[i]; } } - + /* update the exponents so that they are the ones the decoder will decode. Return the number of bits used to code the exponents */ -static int encode_exp(uint8_t encoded_exp[N/2], - uint8_t exp[N/2], +static int encode_exp(uint8_t encoded_exp[N/2], + uint8_t exp[N/2], int nb_exps, int exp_strategy) { @@ -566,7 +566,7 @@ static int encode_exp(uint8_t encoded_exp[N/2], } k += group_size; } - + #if defined(DEBUG) av_log(NULL, AV_LOG_DEBUG, "exponents: strategy=%d\n", exp_strategy); for(i=0;i<=nb_groups * group_size;i++) { @@ -592,14 +592,14 @@ static int compute_mantissa_size(AC3EncodeContext *s, uint8_t *m, int nb_coefs) break; case 1: /* 3 mantissa in 5 bits */ - if (s->mant1_cnt == 0) + if (s->mant1_cnt == 0) bits += 5; if (++s->mant1_cnt == 3) s->mant1_cnt = 0; break; case 2: /* 3 mantissa in 7 bits */ - if (s->mant2_cnt == 0) + if (s->mant2_cnt == 0) bits += 7; if (++s->mant2_cnt == 3) s->mant2_cnt = 0; @@ -611,7 +611,7 @@ static int compute_mantissa_size(AC3EncodeContext *s, uint8_t *m, int nb_coefs) /* 2 mantissa in 7 bits */ if (s->mant4_cnt == 0) bits += 7; - if (++s->mant4_cnt == 2) + if (++s->mant4_cnt == 2) s->mant4_cnt = 0; break; case 14: @@ -643,21 +643,21 @@ static int bit_alloc(AC3EncodeContext *s, s->mant2_cnt = 0; s->mant4_cnt = 0; for(ch=0;ch<s->nb_all_channels;ch++) { - ac3_parametric_bit_allocation(&s->bit_alloc, - bap[i][ch], (int8_t *)encoded_exp[i][ch], - 0, s->nb_coefs[ch], - (((csnroffst-15) << 4) + - fsnroffst) << 2, + ac3_parametric_bit_allocation(&s->bit_alloc, + bap[i][ch], (int8_t *)encoded_exp[i][ch], + 0, s->nb_coefs[ch], + (((csnroffst-15) << 4) + + fsnroffst) << 2, fgaintab[s->fgaincod[ch]], ch == s->lfe_channel, 2, 0, NULL, NULL, NULL); - frame_bits += compute_mantissa_size(s, bap[i][ch], + frame_bits += compute_mantissa_size(s, bap[i][ch], s->nb_coefs[ch]); } } #if 0 - printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n", - csnroffst, fsnroffst, frame_bits, + printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n", + csnroffst, fsnroffst, frame_bits, 16 * s->frame_size - ((frame_bits + 7) & ~7)); #endif return 16 * s->frame_size - frame_bits; @@ -682,9 +682,9 @@ static int compute_bit_allocation(AC3EncodeContext *s, s->sgaincod = 1; s->dbkneecod = 2; s->floorcod = 4; - for(ch=0;ch<s->nb_all_channels;ch++) + for(ch=0;ch<s->nb_all_channels;ch++) s->fgaincod[ch] = 4; - + /* compute real values */ s->bit_alloc.fscod = s->fscod; s->bit_alloc.halfratecod = s->halfratecod; @@ -693,7 +693,7 @@ static int compute_bit_allocation(AC3EncodeContext *s, s->bit_alloc.sgain = sgaintab[s->sgaincod]; s->bit_alloc.dbknee = dbkneetab[s->dbkneecod]; s->bit_alloc.floor = floortab[s->floorcod]; - + /* header size */ frame_bits += 65; // if (s->acmod == 2) @@ -735,39 +735,39 @@ static int compute_bit_allocation(AC3EncodeContext *s, offset until we can pack everything in the requested frame size */ csnroffst = s->csnroffst; - while (csnroffst >= 0 && + while (csnroffst >= 0 && bit_alloc(s, bap, encoded_exp, exp_strategy, frame_bits, csnroffst, 0) < 0) csnroffst -= SNR_INC1; if (csnroffst < 0) { av_log(NULL, AV_LOG_ERROR, "Yack, Error !!!\n"); return -1; } - while ((csnroffst + SNR_INC1) <= 63 && - bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, + while ((csnroffst + SNR_INC1) <= 63 && + bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, csnroffst + SNR_INC1, 0) >= 0) { csnroffst += SNR_INC1; memcpy(bap, bap1, sizeof(bap1)); } - while ((csnroffst + 1) <= 63 && + while ((csnroffst + 1) <= 63 && bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, csnroffst + 1, 0) >= 0) { csnroffst++; memcpy(bap, bap1, sizeof(bap1)); } fsnroffst = 0; - while ((fsnroffst + SNR_INC1) <= 15 && - bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, + while ((fsnroffst + SNR_INC1) <= 15 && + bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, csnroffst, fsnroffst + SNR_INC1) >= 0) { fsnroffst += SNR_INC1; memcpy(bap, bap1, sizeof(bap1)); } - while ((fsnroffst + 1) <= 15 && - bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, + while ((fsnroffst + 1) <= 15 && + bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, csnroffst, fsnroffst + 1) >= 0) { fsnroffst++; memcpy(bap, bap1, sizeof(bap1)); } - + s->csnroffst = csnroffst; for(ch=0;ch<s->nb_all_channels;ch++) s->fsnroffst[ch] = fsnroffst; @@ -824,7 +824,7 @@ static int AC3_encode_init(AVCodecContext *avctx) }; avctx->frame_size = AC3_FRAME_SIZE; - + /* number of channels */ if (channels < 1 || channels > 6) return -1; @@ -836,12 +836,12 @@ static int AC3_encode_init(AVCodecContext *avctx) /* frequency */ for(i=0;i<3;i++) { - for(j=0;j<3;j++) + for(j=0;j<3;j++) if ((ac3_freqs[j] >> i) == freq) goto found; } return -1; - found: + found: s->sample_rate = freq; s->halfratecod = i; s->fscod = j; @@ -861,7 +861,7 @@ static int AC3_encode_init(AVCodecContext *avctx) s->frame_size_min = (bitrate * 1000 * AC3_FRAME_SIZE) / (freq * 16); /* for now we do not handle fractional sizes */ s->frame_size = s->frame_size_min; - + /* bit allocation init */ for(ch=0;ch<s->nb_channels;ch++) { /* bandwidth for each channel */ @@ -887,7 +887,7 @@ static int AC3_encode_init(AVCodecContext *avctx) } ac3_crc_init(); - + avctx->coded_frame= avcodec_alloc_frame(); avctx->coded_frame->key_frame= 1; @@ -979,9 +979,9 @@ static void output_audio_block(AC3EncodeContext *s, uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; int delta0, delta1, delta2; - for(ch=0;ch<s->nb_channels;ch++) + 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++) + 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) { @@ -998,20 +998,20 @@ static void output_audio_block(AC3EncodeContext *s, if(block_num==0) { /* first block must define rematrixing (rematstr) */ - put_bits(&s->pb, 1, 1); - + put_bits(&s->pb, 1, 1); + /* dummy rematrixing rematflg(1:4)=0 */ for (rbnd=0;rbnd<4;rbnd++) - put_bits(&s->pb, 1, 0); + put_bits(&s->pb, 1, 0); } - else + else { /* no matrixing (but should be used in the future) */ put_bits(&s->pb, 1, 0); - } + } } -#if defined(DEBUG) +#if defined(DEBUG) { static int count = 0; av_log(NULL, AV_LOG_DEBUG, "Block #%d (%d)\n", block_num, count++); @@ -1021,7 +1021,7 @@ static void output_audio_block(AC3EncodeContext *s, 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]); } @@ -1030,7 +1030,7 @@ static void output_audio_block(AC3EncodeContext *s, 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]) { @@ -1099,7 +1099,7 @@ static void output_audio_block(AC3EncodeContext *s, 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 */ @@ -1200,7 +1200,7 @@ static void output_audio_block(AC3EncodeContext *s, /* 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]; @@ -1208,11 +1208,11 @@ static void output_audio_block(AC3EncodeContext *s, case 0: break; case 1: - if (q != 128) + if (q != 128) put_bits(&s->pb, 5, q); break; case 2: - if (q != 128) + if (q != 128) put_bits(&s->pb, 7, q); break; case 3: @@ -1247,7 +1247,7 @@ static void ac3_crc_init(void) for(n=0;n<256;n++) { c = n << 8; for (k = 0; k < 8; k++) { - if (c & (1 << 15)) + if (c & (1 << 15)) c = ((c << 1) & 0xffff) ^ (CRC16_POLY & 0xffff); else c = c << 1; @@ -1338,7 +1338,7 @@ static int output_frame_end(AC3EncodeContext *s) assert(n >= 0); if(n>0) memset(pbBufPtr(&s->pb), 0, n); - + /* Now we must compute both crcs : this is not so easy for crc1 because it is at the beginning of the data... */ frame_size_58 = (frame_size >> 1) + (frame_size >> 3); @@ -1348,7 +1348,7 @@ static int output_frame_end(AC3EncodeContext *s) crc1 = mul_poly(crc_inv, crc1, CRC16_POLY); frame[2] = crc1 >> 8; frame[3] = crc1; - + crc2 = ac3_crc(frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2, 0); frame[2*frame_size - 2] = crc2 >> 8; frame[2*frame_size - 1] = crc2; @@ -1386,18 +1386,18 @@ static int AC3_encode_frame(AVCodecContext *avctx, for(j=0;j<N/2;j++) { v = *sptr; input_samples[j + N/2] = v; - s->last_samples[ch][j] = v; + s->last_samples[ch][j] = v; sptr += sinc; } /* apply the MDCT window */ for(j=0;j<N/2;j++) { - input_samples[j] = MUL16(input_samples[j], + input_samples[j] = MUL16(input_samples[j], ac3_window[j]) >> 15; - input_samples[N-j-1] = MUL16(input_samples[N-j-1], + input_samples[N-j-1] = MUL16(input_samples[N-j-1], ac3_window[j]) >> 15; } - + /* Normalize the samples to use the maximum available precision */ v = 14 - log2_tab(input_samples, N); @@ -1408,7 +1408,7 @@ static int AC3_encode_frame(AVCodecContext *avctx, /* do the MDCT */ mdct512(mdct_coef[i][ch], input_samples); - + /* compute "exponents". We take into account the normalization there */ for(j=0;j<N/2;j++) { @@ -1426,7 +1426,7 @@ static int AC3_encode_frame(AVCodecContext *avctx, exp[i][ch][j] = e; } } - + compute_exp_strategy(exp_strategy, exp, ch, ch == s->lfe_channel); /* compute the exponents as the decoder will see them. The @@ -1440,11 +1440,11 @@ static int AC3_encode_frame(AVCodecContext *avctx, j++; } frame_bits += encode_exp(encoded_exp[i][ch], - exp[i][ch], s->nb_coefs[ch], + exp[i][ch], s->nb_coefs[ch], exp_strategy[i][ch]); /* copy encoded exponents for reuse case */ for(k=i+1;k<j;k++) { - memcpy(encoded_exp[k][ch], encoded_exp[i][ch], + memcpy(encoded_exp[k][ch], encoded_exp[i][ch], s->nb_coefs[ch] * sizeof(uint8_t)); } i = j; @@ -1454,9 +1454,9 @@ static int AC3_encode_frame(AVCodecContext *avctx, compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits); /* everything is known... let's output the frame */ output_frame_header(s, frame); - + for(i=0;i<NB_BLOCKS;i++) { - output_audio_block(s, exp_strategy[i], encoded_exp[i], + output_audio_block(s, exp_strategy[i], encoded_exp[i], bap[i], mdct_coef[i], exp_samples[i], i); } return output_frame_end(s); @@ -1498,8 +1498,8 @@ void fft_test(void) sum_re += in1[n].re * cos(a) - in1[n].im * sin(a); sum_im += in1[n].re * sin(a) + in1[n].im * cos(a); } - printf("%3d: %6d,%6d %6.0f,%6.0f\n", - k, in[k].re, in[k].im, sum_re / FN, sum_im / FN); + printf("%3d: %6d,%6d %6.0f,%6.0f\n", + k, in[k].re, in[k].im, sum_re / FN, sum_im / FN); } } @@ -1518,7 +1518,7 @@ void mdct_test(void) } mdct512(output, input); - + /* do it by hand */ for(k=0;k<N/2;k++) { s = 0; @@ -1528,7 +1528,7 @@ void mdct_test(void) } output1[k] = -2 * s / N; } - + err = 0; emax = 0; for(i=0;i<N/2;i++) { @@ -1547,7 +1547,7 @@ void test_ac3(void) unsigned char frame[AC3_MAX_CODED_FRAME_SIZE]; short samples[AC3_FRAME_SIZE]; int ret, i; - + AC3_encode_init(&ctx, 44100, 64000, 1); fft_test(); |