1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * AC-3 DSP functions 3cabdff1aSopenharmony_ci * Copyright (c) 2011 Justin Ruggles 4cabdff1aSopenharmony_ci * 5cabdff1aSopenharmony_ci * This file is part of FFmpeg. 6cabdff1aSopenharmony_ci * 7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 11cabdff1aSopenharmony_ci * 12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15cabdff1aSopenharmony_ci * Lesser General Public License for more details. 16cabdff1aSopenharmony_ci * 17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20cabdff1aSopenharmony_ci */ 21cabdff1aSopenharmony_ci 22cabdff1aSopenharmony_ci#ifndef AVCODEC_AC3DSP_H 23cabdff1aSopenharmony_ci#define AVCODEC_AC3DSP_H 24cabdff1aSopenharmony_ci 25cabdff1aSopenharmony_ci#include <stdint.h> 26cabdff1aSopenharmony_ci 27cabdff1aSopenharmony_ci/** 28cabdff1aSopenharmony_ci * Number of mantissa bits written for each bap value. 29cabdff1aSopenharmony_ci * bap values with fractional bits are set to 0 and are calculated separately. 30cabdff1aSopenharmony_ci */ 31cabdff1aSopenharmony_ciextern const uint16_t ff_ac3_bap_bits[16]; 32cabdff1aSopenharmony_ci 33cabdff1aSopenharmony_citypedef struct AC3DSPContext { 34cabdff1aSopenharmony_ci /** 35cabdff1aSopenharmony_ci * Set each encoded exponent in a block to the minimum of itself and the 36cabdff1aSopenharmony_ci * exponents in the same frequency bin of up to 5 following blocks. 37cabdff1aSopenharmony_ci * @param exp pointer to the start of the current block of exponents. 38cabdff1aSopenharmony_ci * constraints: align 16 39cabdff1aSopenharmony_ci * @param num_reuse_blocks number of blocks that will reuse exponents from the current block. 40cabdff1aSopenharmony_ci * constraints: range 0 to 5 41cabdff1aSopenharmony_ci * @param nb_coefs number of frequency coefficients. 42cabdff1aSopenharmony_ci */ 43cabdff1aSopenharmony_ci void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs); 44cabdff1aSopenharmony_ci 45cabdff1aSopenharmony_ci /** 46cabdff1aSopenharmony_ci * Convert an array of float in range [-1.0,1.0] to int32_t with range 47cabdff1aSopenharmony_ci * [-(1<<24),(1<<24)] 48cabdff1aSopenharmony_ci * 49cabdff1aSopenharmony_ci * @param dst destination array of int32_t. 50cabdff1aSopenharmony_ci * constraints: 16-byte aligned 51cabdff1aSopenharmony_ci * @param src source array of float. 52cabdff1aSopenharmony_ci * constraints: 16-byte aligned 53cabdff1aSopenharmony_ci * @param len number of elements to convert. 54cabdff1aSopenharmony_ci * constraints: multiple of 32 greater than zero 55cabdff1aSopenharmony_ci */ 56cabdff1aSopenharmony_ci void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len); 57cabdff1aSopenharmony_ci 58cabdff1aSopenharmony_ci /** 59cabdff1aSopenharmony_ci * Calculate bit allocation pointers. 60cabdff1aSopenharmony_ci * The SNR is the difference between the masking curve and the signal. AC-3 61cabdff1aSopenharmony_ci * uses this value for each frequency bin to allocate bits. The snroffset 62cabdff1aSopenharmony_ci * parameter is a global adjustment to the SNR for all bins. 63cabdff1aSopenharmony_ci * 64cabdff1aSopenharmony_ci * @param[in] mask masking curve 65cabdff1aSopenharmony_ci * @param[in] psd signal power for each frequency bin 66cabdff1aSopenharmony_ci * @param[in] start starting bin location 67cabdff1aSopenharmony_ci * @param[in] end ending bin location 68cabdff1aSopenharmony_ci * @param[in] snr_offset SNR adjustment 69cabdff1aSopenharmony_ci * @param[in] floor noise floor 70cabdff1aSopenharmony_ci * @param[in] bap_tab look-up table for bit allocation pointers 71cabdff1aSopenharmony_ci * @param[out] bap bit allocation pointers 72cabdff1aSopenharmony_ci */ 73cabdff1aSopenharmony_ci void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, 74cabdff1aSopenharmony_ci int snr_offset, int floor, 75cabdff1aSopenharmony_ci const uint8_t *bap_tab, uint8_t *bap); 76cabdff1aSopenharmony_ci 77cabdff1aSopenharmony_ci /** 78cabdff1aSopenharmony_ci * Update bap counts using the supplied array of bap. 79cabdff1aSopenharmony_ci * 80cabdff1aSopenharmony_ci * @param[out] mant_cnt bap counts for 1 block 81cabdff1aSopenharmony_ci * @param[in] bap array of bap, pointing to start coef bin 82cabdff1aSopenharmony_ci * @param[in] len number of elements to process 83cabdff1aSopenharmony_ci */ 84cabdff1aSopenharmony_ci void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len); 85cabdff1aSopenharmony_ci 86cabdff1aSopenharmony_ci /** 87cabdff1aSopenharmony_ci * Calculate the number of bits needed to encode a set of mantissas. 88cabdff1aSopenharmony_ci * 89cabdff1aSopenharmony_ci * @param[in] mant_cnt bap counts for all blocks 90cabdff1aSopenharmony_ci * @return mantissa bit count 91cabdff1aSopenharmony_ci */ 92cabdff1aSopenharmony_ci int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]); 93cabdff1aSopenharmony_ci 94cabdff1aSopenharmony_ci void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs); 95cabdff1aSopenharmony_ci 96cabdff1aSopenharmony_ci void (*sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0, 97cabdff1aSopenharmony_ci const int32_t *coef1, int len); 98cabdff1aSopenharmony_ci 99cabdff1aSopenharmony_ci void (*sum_square_butterfly_float)(float sum[4], const float *coef0, 100cabdff1aSopenharmony_ci const float *coef1, int len); 101cabdff1aSopenharmony_ci 102cabdff1aSopenharmony_ci int out_channels; 103cabdff1aSopenharmony_ci int in_channels; 104cabdff1aSopenharmony_ci void (*downmix)(float **samples, float **matrix, int len); 105cabdff1aSopenharmony_ci void (*downmix_fixed)(int32_t **samples, int16_t **matrix, int len); 106cabdff1aSopenharmony_ci} AC3DSPContext; 107cabdff1aSopenharmony_ci 108cabdff1aSopenharmony_civoid ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); 109cabdff1aSopenharmony_civoid ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact); 110cabdff1aSopenharmony_civoid ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact); 111cabdff1aSopenharmony_civoid ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact); 112cabdff1aSopenharmony_ci 113cabdff1aSopenharmony_civoid ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix, 114cabdff1aSopenharmony_ci int out_ch, int in_ch, int len); 115cabdff1aSopenharmony_civoid ff_ac3dsp_downmix_fixed(AC3DSPContext *c, int32_t **samples, int16_t **matrix, 116cabdff1aSopenharmony_ci int out_ch, int in_ch, int len); 117cabdff1aSopenharmony_ci 118cabdff1aSopenharmony_civoid ff_ac3dsp_set_downmix_x86(AC3DSPContext *c); 119cabdff1aSopenharmony_ci 120cabdff1aSopenharmony_ci#endif /* AVCODEC_AC3DSP_H */ 121