comparison ac3dec.c @ 5479:943c732c905d libavcodec

use dsputil for float to signed 16-bit sample conversion
author jbr
date Sat, 04 Aug 2007 20:59:22 +0000
parents ec1f268792cd
children 930bca6dd95f
comparison
equal deleted inserted replaced
5478:41103dc22ad5 5479:943c732c905d
148 148
149 /* For IMDCT. */ 149 /* For IMDCT. */
150 MDCTContext imdct_512; //for 512 sample imdct transform 150 MDCTContext imdct_512; //for 512 sample imdct transform
151 MDCTContext imdct_256; //for 256 sample imdct transform 151 MDCTContext imdct_256; //for 256 sample imdct transform
152 DSPContext dsp; //for optimization 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 DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS-1][256]); //output after imdct transform and windowing 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 DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS-1][256]); //delay - added to the next block 158 DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS-1][256]); //delay - added to the next block
156 DECLARE_ALIGNED_16(float, tmp_imdct[256]); //temporary storage for imdct transform 159 DECLARE_ALIGNED_16(float, tmp_imdct[256]); //temporary storage for imdct transform
157 DECLARE_ALIGNED_16(float, tmp_output[512]); //temporary storage for output before windowing 160 DECLARE_ALIGNED_16(float, tmp_output[512]); //temporary storage for output before windowing
158 DECLARE_ALIGNED_16(float, window[256]); //window coefficients 161 DECLARE_ALIGNED_16(float, window[256]); //window coefficients
159 162
259 ff_mdct_init(&ctx->imdct_256, 8, 1); 262 ff_mdct_init(&ctx->imdct_256, 8, 1);
260 ff_mdct_init(&ctx->imdct_512, 9, 1); 263 ff_mdct_init(&ctx->imdct_512, 9, 1);
261 ac3_window_init(ctx->window); 264 ac3_window_init(ctx->window);
262 dsputil_init(&ctx->dsp, avctx); 265 dsputil_init(&ctx->dsp, avctx);
263 av_init_random(0, &ctx->dith_state); 266 av_init_random(0, &ctx->dith_state);
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 }
264 275
265 return 0; 276 return 0;
266 } 277 }
267 /*********** END INIT FUNCTIONS ***********/ 278 /*********** END INIT FUNCTIONS ***********/
268 279
649 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, 660 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output,
650 ctx->transform_coeffs[ch], 661 ctx->transform_coeffs[ch],
651 ctx->tmp_imdct); 662 ctx->tmp_imdct);
652 } 663 }
653 ctx->dsp.vector_fmul_add_add(ctx->output[ch-1], ctx->tmp_output, 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 ctx->dsp.vector_fmul_reverse(ctx->delay[ch-1], ctx->tmp_output+256, 666 ctx->dsp.vector_fmul_reverse(ctx->delay[ch-1], ctx->tmp_output+256,
656 ctx->window, 256); 667 ctx->window, 256);
657 } 668 }
658 } 669 }
659 670
919 if(ctx->acmod == AC3_ACMOD_STEREO) 930 if(ctx->acmod == AC3_ACMOD_STEREO)
920 do_rematrixing(ctx); 931 do_rematrixing(ctx);
921 932
922 /* apply scaling to coefficients (headroom, dynrng) */ 933 /* apply scaling to coefficients (headroom, dynrng) */
923 for(ch=1; ch<=ctx->nchans; ch++) { 934 for(ch=1; ch<=ctx->nchans; ch++) {
924 float gain = 2.0f; 935 float gain = 2.0f * ctx->mul_bias;
925 if(ctx->acmod == AC3_ACMOD_DUALMONO && ch == 2) { 936 if(ctx->acmod == AC3_ACMOD_DUALMONO && ch == 2) {
926 gain *= ctx->dynrng2; 937 gain *= ctx->dynrng2;
927 } else { 938 } else {
928 gain *= ctx->dynrng; 939 gain *= ctx->dynrng;
929 } 940 }
932 } 943 }
933 } 944 }
934 945
935 do_imdct(ctx); 946 do_imdct(ctx);
936 947
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 }
952
937 return 0; 953 return 0;
938 }
939
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);
948 } 954 }
949 955
950 /* Decode ac3 frame. 956 /* Decode ac3 frame.
951 * 957 *
952 * @param avctx Pointer to AVCodecContext 958 * @param avctx Pointer to AVCodecContext
958 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size) 964 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
959 { 965 {
960 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; 966 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
961 int16_t *out_samples = (int16_t *)data; 967 int16_t *out_samples = (int16_t *)data;
962 int i, blk, ch; 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 //Initialize the GetBitContext with the start of valid AC3 Frame. 970 //Initialize the GetBitContext with the start of valid AC3 Frame.
969 init_get_bits(&ctx->gb, buf, buf_size * 8); 971 init_get_bits(&ctx->gb, buf, buf_size * 8);
970 972
971 //Parse the syncinfo. 973 //Parse the syncinfo.
997 *data_size = 0; 999 *data_size = 0;
998 return ctx->frame_size; 1000 return ctx->frame_size;
999 } 1001 }
1000 for (i = 0; i < 256; i++) 1002 for (i = 0; i < 256; i++)
1001 for (ch = 0; ch < ctx->out_channels; ch++) 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 *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t); 1006 *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t);
1005 return ctx->frame_size; 1007 return ctx->frame_size;
1006 } 1008 }
1007 1009