On Thu, 18 Oct 2012, Justin Ruggles wrote:
--- libavcodec/atrac3.c | 1057 +++++++++++++++++++++++------------------------ libavcodec/atrac3data.h | 98 +++-- 2 files changed, 571 insertions(+), 584 deletions(-)
The commit also contains some minor refactorings that could be mentioned in the commit message
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 94b355a..5eb0c7f 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -38,10 +38,10 @@ #include "libavutil/float_dsp.h" #include "avcodec.h" -#include "get_bits.h" #include "bytestream.h" #include "fft.h" #include "fmtconvert.h" +#include "get_bits.h" #include "atrac.h" #include "atrac3data.h" @@ -52,142 +52,130 @@ #define SAMPLES_PER_FRAME 1024 #define MDCT_SIZE 512 -/* These structures are needed to store the parsed gain control data. */ -typedef struct { - int num_gain_data; - int levcode[8]; - int loccode[8]; -} gain_info; - -typedef struct { - gain_info gBlock[4]; -} gain_block; - -typedef struct { - int pos; - int numCoefs; - float coef[8]; -} tonal_component; - -typedef struct { - int bandsCoded; - int numComponents; - tonal_component components[64]; - float prevFrame[SAMPLES_PER_FRAME]; - int gcBlkSwitch; - gain_block gainBlock[2]; +typedef struct GainInfo { + int num_gain_data; + int lev_code[8]; + int loc_code[8]; +} GainInfo; + +typedef struct GainBlock { + GainInfo g_block[4]; +} GainBlock; + +typedef struct TonalComponent { + int pos; + int num_coefs; + float coef[8]; +} TonalComponent; + +typedef struct ChannelUnit { + int bands_coded; + int num_components; + float prev_frame[SAMPLES_PER_FRAME]; + int gc_blk_switch; + TonalComponent components[64]; + GainBlock gain_block[2]; DECLARE_ALIGNED(32, float, spectrum)[SAMPLES_PER_FRAME]; - DECLARE_ALIGNED(32, float, IMDCT_buf)[SAMPLES_PER_FRAME]; + DECLARE_ALIGNED(32, float, imdct_buf)[SAMPLES_PER_FRAME]; - float delayBuf1[46]; ///<qmf delay buffers - float delayBuf2[46]; - float delayBuf3[46]; -} channel_unit; + float delay_buf1[46]; ///<qmf delay buffers + float delay_buf2[46]; + float delay_buf3[46];
I guess these ones could be aligned with the ones above?
+} ChannelUnit; typedef struct {
You could name the struct here (as you do above), for consistency.
- AVFrame frame; - GetBitContext gb; + AVFrame frame; + GetBitContext gb; //@{ /** stream data */ - int channels; - int codingMode; - int bit_rate; - int sample_rate; - int samples_per_channel; - int samples_per_frame; - - int bits_per_frame; - int bytes_per_frame; - int pBs; - channel_unit* pUnits; + int channels; + int coding_mode; + int bit_rate; + int sample_rate; + int samples_per_channel; + int samples_per_frame; + + int bits_per_frame; + int bytes_per_frame; + ChannelUnit *units; //@} //@{ /** joint-stereo related variables */ - int matrix_coeff_index_prev[4]; - int matrix_coeff_index_now[4]; - int matrix_coeff_index_next[4]; - int weighting_delay[6]; + int matrix_coeff_index_prev[4]; + int matrix_coeff_index_now[4]; + int matrix_coeff_index_next[4]; + int weighting_delay[6]; //@} //@{ /** data buffers */ - uint8_t* decoded_bytes_buffer; - float tempBuf[1070]; + uint8_t *decoded_bytes_buffer; + float temp_buf[1070]; //@} //@{ /** extradata */ - int atrac3version; - int delay; - int scrambled_stream; - int frame_factor; + int version; + int delay; + int scrambled_stream; + int frame_factor; //@} - FFTContext mdct_ctx; - FmtConvertContext fmt_conv; - AVFloatDSPContext fdsp; + FFTContext mdct_ctx; + FmtConvertContext fmt_conv; + AVFloatDSPContext fdsp; } ATRAC3Context; static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE]; -static VLC spectral_coeff_tab[7]; -static float gain_tab1[16]; -static float gain_tab2[31]; +static VLC spectral_coeff_tab[7]; +static float gain_tab1[16]; +static float gain_tab2[31]; -/** - * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands - * caused by the reverse spectra of the QMF. +/* + * Regular 512 points IMDCT without overlapping, with the exception of the + * swapping of odd bands caused by the reverse spectra of the QMF. * - * @param pInput float input - * @param pOutput float output * @param odd_band 1 if the band is an odd band */ - -static void IMLT(ATRAC3Context *q, float *pInput, float *pOutput, int odd_band) +static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band) { - int i; + int i; if (odd_band) { /** - * Reverse the odd bands before IMDCT, this is an effect of the QMF transform - * or it gives better compression to do it this way. - * FIXME: It should be possible to handle this in imdct_calc - * for that to happen a modification of the prerotation step of - * all SIMD code and C code is needed. - * Or fix the functions before so they generate a pre reversed spectrum. - */ - - for (i=0; i<128; i++) - FFSWAP(float, pInput[i], pInput[255-i]); + * Reverse the odd bands before IMDCT, this is an effect of the QMF + * transform or it gives better compression to do it this way. + * FIXME: It should be possible to handle this in imdct_calc + * for that to happen a modification of the prerotation step of + * all SIMD code and C code is needed. + * Or fix the functions before so they generate a pre reversed spectrum. + */ + for (i = 0; i < 128; i++) + FFSWAP(float, input[i], input[255 - i]); } - q->mdct_ctx.imdct_calc(&q->mdct_ctx,pOutput,pInput); + q->mdct_ctx.imdct_calc(&q->mdct_ctx, output, input); /* Perform windowing on the output. */ - q->fdsp.vector_fmul(pOutput, pOutput, mdct_window, MDCT_SIZE); - + q->fdsp.vector_fmul(output, output, mdct_window, MDCT_SIZE); } - -/** - * Atrac 3 indata descrambling, only used for data coming from the rm container - * - * @param inbuffer pointer to 8 bit array of indata - * @param out pointer to 8 bit array of outdata - * @param bytes amount of bytes +/* + * indata descrambling, only used for data coming from the rm container */ - -static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ +static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes) +{ int i, off; uint32_t c; - const uint32_t* buf; - uint32_t* obuf = (uint32_t*) out; + const uint32_t *buf; + uint32_t *output = (uint32_t *)out; - off = (intptr_t)inbuffer & 3; - buf = (const uint32_t*) (inbuffer - off); - c = av_be2ne32((0x537F6103 >> (off*8)) | (0x537F6103 << (32-(off*8)))); + off = (intptr_t)input & 3; + buf = (const uint32_t *)(input - off); + c = av_be2ne32((0x537F6103 >> (off * 8)) | (0x537F6103 << (32 - (off * 8)))); bytes += 3 + off; - for (i = 0; i < bytes/4; i++) - obuf[i] = c ^ buf[i]; + for (i = 0; i < bytes / 4; i++) + output[i] = c ^ buf[i]; if (off) av_log_ask_for_sample(NULL, "Offset of %d not handled.\n", off); @@ -195,35 +183,34 @@ static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ return off; } - -static av_cold int init_atrac3_transforms(ATRAC3Context *q) { +static av_cold int init_atrac3_transforms(ATRAC3Context *q) +{ float enc_window[256]; int i; - /* Generate the mdct window, for details see + /* generate the mdct window, for details see * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */ - for (i=0 ; i<256; i++) + for (i = 0; i < 256; i++) enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5; - if (!mdct_window[0]) - for (i=0 ; i<256; i++) { - mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]); - mdct_window[511-i] = mdct_window[i]; + if (!mdct_window[0]) { + for (i = 0; i < 256; i++) { + mdct_window[i] = enc_window[i] / + (enc_window[ i] * enc_window[ i] + + enc_window[255 - i] * enc_window[255 - i]); + mdct_window[511 - i] = mdct_window[i]; } + } - /* Initialize the MDCT transform. */ + /* initialize the MDCT transform */ return ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0 / 32768); } -/** - * Atrac3 uninit, free all allocated memory - */ - static av_cold int atrac3_decode_close(AVCodecContext *avctx) { ATRAC3Context *q = avctx->priv_data; - av_free(q->pUnits); + av_free(q->units); av_free(q->decoded_bytes_buffer); ff_mdct_end(&q->mdct_ctx); @@ -231,192 +218,200 @@ static av_cold int atrac3_decode_close(AVCodecContext *avctx) return 0; } -/** -/ * Mantissa decoding +/* + * Mantissa decoding * - * @param gb the GetBit context - * @param selector what table is the output values coded with - * @param codingFlag constant length coding or variable length coding - * @param mantissas mantissa output table - * @param numCodes amount of values to get + * @param selector which table the output values are coded with + * @param coding_flag constant length coding or variable length coding + * @param mantissas mantissa output table + * @param num_codes number of values to get */ - -static void readQuantSpectralCoeffs (GetBitContext *gb, int selector, int codingFlag, int* mantissas, int numCodes) +static void read_quant_spectral_coeffs(GetBitContext *gb, int selector, + int coding_flag, int *mantissas, + int num_codes) { - int numBits, cnt, code, huffSymb; + int i, code, huff_symb; if (selector == 1) - numCodes /= 2; + num_codes /= 2; - if (codingFlag != 0) { + if (coding_flag != 0) { /* constant length coding (CLC) */ - numBits = CLCLengthTab[selector]; + int num_bits = clc_length_tab[selector]; if (selector > 1) { - for (cnt = 0; cnt < numCodes; cnt++) { - if (numBits) - code = get_sbits(gb, numBits); + for (i = 0; i < num_codes; i++) { + if (num_bits) + code = get_sbits(gb, num_bits); else code = 0; - mantissas[cnt] = code; + mantissas[i] = code; } } else { - for (cnt = 0; cnt < numCodes; cnt++) { - if (numBits) - code = get_bits(gb, numBits); //numBits is always 4 in this case + for (i = 0; i < num_codes; i++) { + if (num_bits) + code = get_bits(gb, num_bits); // num_bits is always 4 in this case else code = 0; - mantissas[cnt*2] = seTab_0[code >> 2]; - mantissas[cnt*2+1] = seTab_0[code & 3]; + mantissas[i * 2 ] = mantissa_clc_tab[code >> 2]; + mantissas[i * 2 + 1] = mantissa_clc_tab[code & 3]; } } } else { /* variable length coding (VLC) */ if (selector != 1) { - for (cnt = 0; cnt < numCodes; cnt++) { - huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); - huffSymb += 1; - code = huffSymb >> 1; - if (huffSymb & 1) + for (i = 0; i < num_codes; i++) { + huff_symb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, + spectral_coeff_tab[selector-1].bits, 3); + huff_symb += 1; + code = huff_symb >> 1; + if (huff_symb & 1) code = -code; - mantissas[cnt] = code; + mantissas[i] = code; } } else { - for (cnt = 0; cnt < numCodes; cnt++) { - huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); - mantissas[cnt*2] = decTable1[huffSymb*2]; - mantissas[cnt*2+1] = decTable1[huffSymb*2+1]; + for (i = 0; i < num_codes; i++) { + huff_symb = get_vlc2(gb, spectral_coeff_tab[selector - 1].table, + spectral_coeff_tab[selector - 1].bits, 3); + mantissas[i * 2 ] = mantissa_vlc_tab[huff_symb * 2 ]; + mantissas[i * 2 + 1] = mantissa_vlc_tab[huff_symb * 2 + 1]; } } } } -/** +/* * Restore the quantized band spectrum coefficients * - * @param gb the GetBit context - * @param pOut decoded band spectrum - * @return outSubbands subband counter, fix for broken specification/files + * @return subband count, fix for broken specification/files */ - -static int decodeSpectrum (GetBitContext *gb, float *pOut) +static int decode_spectrum(GetBitContext *gb, float *output) { - int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn; - int subband_vlc_index[32], SF_idxs[32]; - int mantissas[128]; - float SF; - - numSubbands = get_bits(gb, 5); // number of coded subbands - codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC - - /* Get the VLC selector table for the subbands, 0 means not coded. */ - for (cnt = 0; cnt <= numSubbands; cnt++) - subband_vlc_index[cnt] = get_bits(gb, 3); - - /* Read the scale factor indexes from the stream. */ - for (cnt = 0; cnt <= numSubbands; cnt++) { - if (subband_vlc_index[cnt] != 0) - SF_idxs[cnt] = get_bits(gb, 6); + int num_subbands, coding_mode, i, j, first, last, subband_size; + int subband_vlc_index[32], sf_index[32]; + int mantissas[128]; + float scale_factor; + + num_subbands = get_bits(gb, 5); // number of coded subbands + coding_mode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC
These could be vertically aligned The rest of the patch looks good to me. // Martin _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel