Revision 4e092320 libavcodec/ac3dec.c

View differences:

libavcodec/ac3dec.c
150 150
    MDCTContext imdct_512;  //for 512 sample imdct transform
151 151
    MDCTContext imdct_256;  //for 256 sample imdct transform
152 152
    DSPContext  dsp;        //for optimization
153
    float       add_bias;   ///< offset for float_to_int16 conversion
154
    float       mul_bias;   ///< scaling for float_to_int16 conversion
153 155

  
154 156
    DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS-1][256]); //output after imdct transform and windowing
157
    DECLARE_ALIGNED_16(short, int_output[AC3_MAX_CHANNELS-1][256]); ///< final 16-bit integer output
155 158
    DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS-1][256]);  //delay - added to the next block
156 159
    DECLARE_ALIGNED_16(float, tmp_imdct[256]);                  //temporary storage for imdct transform
157 160
    DECLARE_ALIGNED_16(float, tmp_output[512]);                 //temporary storage for output before windowing
......
262 265
    dsputil_init(&ctx->dsp, avctx);
263 266
    av_init_random(0, &ctx->dith_state);
264 267

  
268
    if(ctx->dsp.float_to_int16 == ff_float_to_int16_c) {
269
        ctx->add_bias = 385.0f;
270
        ctx->mul_bias = 1.0f;
271
    } else {
272
        ctx->add_bias = 0.0f;
273
        ctx->mul_bias = 32767.0f;
274
    }
275

  
265 276
    return 0;
266 277
}
267 278
/*********** END INIT FUNCTIONS ***********/
......
651 662
                                          ctx->tmp_imdct);
652 663
        }
653 664
        ctx->dsp.vector_fmul_add_add(ctx->output[ch-1], ctx->tmp_output,
654
                                     ctx->window, ctx->delay[ch-1], 384, 256, 1);
665
                                     ctx->window, ctx->delay[ch-1], ctx->add_bias, 256, 1);
655 666
        ctx->dsp.vector_fmul_reverse(ctx->delay[ch-1], ctx->tmp_output+256,
656 667
                                     ctx->window, 256);
657 668
    }
......
921 932

  
922 933
    /* apply scaling to coefficients (headroom, dynrng) */
923 934
    for(ch=1; ch<=ctx->nchans; ch++) {
924
        float gain = 2.0f;
935
        float gain = 2.0f * ctx->mul_bias;
925 936
        if(ctx->acmod == AC3_ACMOD_DUALMONO && ch == 2) {
926 937
            gain *= ctx->dynrng2;
927 938
        } else {
......
934 945

  
935 946
    do_imdct(ctx);
936 947

  
937
    return 0;
938
}
948
    /* convert float to 16-bit integer */
949
    for(ch=0; ch<ctx->out_channels; ch++) {
950
        ctx->dsp.float_to_int16(ctx->int_output[ch], ctx->output[ch], 256);
951
    }
939 952

  
940
static inline int16_t convert(int32_t i)
941
{
942
    if (i > 0x43c07fff)
943
        return 32767;
944
    else if (i <= 0x43bf8000)
945
        return -32768;
946
    else
947
        return (i - 0x43c00000);
953
    return 0;
948 954
}
949 955

  
950 956
/* Decode ac3 frame.
......
960 966
    AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
961 967
    int16_t *out_samples = (int16_t *)data;
962 968
    int i, blk, ch;
963
    int32_t *int_ptr[6];
964

  
965
    for (ch = 0; ch < 6; ch++)
966
        int_ptr[ch] = (int32_t *)(&ctx->output[ch]);
967 969

  
968 970
    //Initialize the GetBitContext with the start of valid AC3 Frame.
969 971
    init_get_bits(&ctx->gb, buf, buf_size * 8);
......
999 1001
        }
1000 1002
        for (i = 0; i < 256; i++)
1001 1003
            for (ch = 0; ch < ctx->out_channels; ch++)
1002
                *(out_samples++) = convert(int_ptr[ch][i]);
1004
                *(out_samples++) = ctx->int_output[ch][i];
1003 1005
    }
1004 1006
    *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t);
1005 1007
    return ctx->frame_size;

Also available in: Unified diff