FFmpeg
ac3dsp.h
Go to the documentation of this file.
1 /*
2  * AC-3 DSP functions
3  * Copyright (c) 2011 Justin Ruggles
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVCODEC_AC3DSP_H
23 #define AVCODEC_AC3DSP_H
24 
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 /**
29  * Number of mantissa bits written for each bap value.
30  * bap values with fractional bits are set to 0 and are calculated separately.
31  */
32 extern const uint16_t ff_ac3_bap_bits[16];
33 
34 typedef struct AC3DSPContext {
35  /**
36  * Set each encoded exponent in a block to the minimum of itself and the
37  * exponents in the same frequency bin of up to 5 following blocks.
38  * @param exp pointer to the start of the current block of exponents.
39  * constraints: align 16
40  * @param num_reuse_blocks number of blocks that will reuse exponents from the current block.
41  * constraints: range 0 to 5
42  * @param nb_coefs number of frequency coefficients.
43  */
44  void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
45 
46  /**
47  * Convert an array of float in range [-1.0,1.0] to int32_t with range
48  * [-(1<<24),(1<<24)]
49  *
50  * @param dst destination array of int32_t.
51  * constraints: 32-byte aligned
52  * @param src source array of float.
53  * constraints: 32-byte aligned
54  * @param len number of elements to convert.
55  * constraints: multiple of 32 greater than zero
56  */
57  void (*float_to_fixed24)(int32_t *dst, const float *src, size_t len);
58 
59  /**
60  * Calculate bit allocation pointers.
61  * The SNR is the difference between the masking curve and the signal. AC-3
62  * uses this value for each frequency bin to allocate bits. The snroffset
63  * parameter is a global adjustment to the SNR for all bins.
64  *
65  * @param[in] mask masking curve
66  * @param[in] psd signal power for each frequency bin
67  * @param[in] start starting bin location
68  * @param[in] end ending bin location
69  * @param[in] snr_offset SNR adjustment
70  * @param[in] floor noise floor
71  * @param[in] bap_tab look-up table for bit allocation pointers
72  * @param[out] bap bit allocation pointers
73  */
74  void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end,
75  int snr_offset, int floor,
76  const uint8_t *bap_tab, uint8_t *bap);
77 
78  /**
79  * Update bap counts using the supplied array of bap.
80  *
81  * @param[out] mant_cnt bap counts for 1 block
82  * @param[in] bap array of bap, pointing to start coef bin
83  * @param[in] len number of elements to process
84  */
85  void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len);
86 
87  /**
88  * Calculate the number of bits needed to encode a set of mantissas.
89  *
90  * @param[in] mant_cnt bap counts for all blocks
91  * @return mantissa bit count
92  */
93  int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]);
94 
95  void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs);
96 
97  void (*sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0,
98  const int32_t *coef1, int len);
99 
100  void (*sum_square_butterfly_float)(float sum[4], const float *coef0,
101  const float *coef1, int len);
102 
105  void (*downmix)(float **samples, float **matrix, int len);
106  void (*downmix_fixed)(int32_t **samples, int16_t **matrix, int len);
107 } AC3DSPContext;
108 
115 
116 void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix,
117  int out_ch, int in_ch, int len);
119  int out_ch, int in_ch, int len);
120 
122 
123 #endif /* AVCODEC_AC3DSP_H */
nb_coefs
static int nb_coefs(int length, int level, uint64_t sn)
Definition: af_afwtdn.c:515
AC3DSPContext::in_channels
int in_channels
Definition: ac3dsp.h:104
matrix
Definition: vc1dsp.c:43
int64_t
long long int64_t
Definition: coverity.c:34
mask
int mask
Definition: mediacodecdec_common.c:154
AC3DSPContext
Definition: ac3dsp.h:34
ff_ac3dsp_init_riscv
void ff_ac3dsp_init_riscv(AC3DSPContext *c)
Definition: ac3dsp_init.c:39
ff_ac3dsp_downmix
void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix, int out_ch, int in_ch, int len)
Definition: ac3dsp.c:344
ff_ac3_bap_bits
const uint16_t ff_ac3_bap_bits[16]
Number of mantissa bits written for each bap value.
Definition: ac3dsp.c:107
AC3DSPContext::ac3_exponent_min
void(* ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
Set each encoded exponent in a block to the minimum of itself and the exponents in the same frequency...
Definition: ac3dsp.h:44
AC3DSPContext::sum_square_butterfly_int32
void(* sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0, const int32_t *coef1, int len)
Definition: ac3dsp.h:97
ff_ac3dsp_set_downmix_x86
void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c)
Definition: ac3dsp_init.c:73
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
AC3DSPContext::sum_square_butterfly_float
void(* sum_square_butterfly_float)(float sum[4], const float *coef0, const float *coef1, int len)
Definition: ac3dsp.h:100
AC3DSPContext::compute_mantissa_size
int(* compute_mantissa_size)(uint16_t mant_cnt[6][16])
Calculate the number of bits needed to encode a set of mantissas.
Definition: ac3dsp.h:93
AC3DSPContext::extract_exponents
void(* extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs)
Definition: ac3dsp.h:95
bap_tab
static const uint8_t bap_tab[64]
Definition: dolby_e.c:599
exp
int8_t exp
Definition: eval.c:73
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_ac3dsp_init_aarch64
void ff_ac3dsp_init_aarch64(AC3DSPContext *c)
Definition: ac3dsp_init_aarch64.c:40
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
ff_ac3dsp_downmix_fixed
void ff_ac3dsp_downmix_fixed(AC3DSPContext *c, int32_t **samples, int16_t **matrix, int out_ch, int in_ch, int len)
Definition: ac3dsp.c:317
AC3DSPContext::update_bap_counts
void(* update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len)
Update bap counts using the supplied array of bap.
Definition: ac3dsp.h:85
ff_ac3dsp_init_arm
void ff_ac3dsp_init_arm(AC3DSPContext *c)
Definition: ac3dsp_init_arm.c:47
ff_ac3dsp_init
void ff_ac3dsp_init(AC3DSPContext *c)
Definition: ac3dsp.c:377
len
int len
Definition: vorbis_enc_data.h:426
AC3DSPContext::bit_alloc_calc_bap
void(* bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap)
Calculate bit allocation pointers.
Definition: ac3dsp.h:74
AC3DSPContext::float_to_fixed24
void(* float_to_fixed24)(int32_t *dst, const float *src, size_t len)
Convert an array of float in range [-1.0,1.0] to int32_t with range [-(1<<24),(1<<24)].
Definition: ac3dsp.h:57
AC3DSPContext::out_channels
int out_channels
Definition: ac3dsp.h:103
AC3DSPContext::downmix_fixed
void(* downmix_fixed)(int32_t **samples, int16_t **matrix, int len)
Definition: ac3dsp.h:106
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
AC3DSPContext::downmix
void(* downmix)(float **samples, float **matrix, int len)
Definition: ac3dsp.h:105
ff_ac3dsp_init_x86
void ff_ac3dsp_init_x86(AC3DSPContext *c)
Definition: ac3dsp_init.c:37
ff_ac3dsp_init_mips
void ff_ac3dsp_init_mips(AC3DSPContext *c)
Definition: ac3dsp_mips.c:408
int32_t
int32_t
Definition: audioconvert.c:56
src
#define src
Definition: vp8dsp.c:248