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 <stdint.h>
26 
27 /**
28  * Number of mantissa bits written for each bap value.
29  * bap values with fractional bits are set to 0 and are calculated separately.
30  */
31 extern const uint16_t ff_ac3_bap_bits[16];
32 
33 typedef struct AC3DSPContext {
34  /**
35  * Set each encoded exponent in a block to the minimum of itself and the
36  * exponents in the same frequency bin of up to 5 following blocks.
37  * @param exp pointer to the start of the current block of exponents.
38  * constraints: align 16
39  * @param num_reuse_blocks number of blocks that will reuse exponents from the current block.
40  * constraints: range 0 to 5
41  * @param nb_coefs number of frequency coefficients.
42  */
43  void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
44 
45  /**
46  * Calculate the maximum MSB of the absolute value of each element in an
47  * array of int16_t.
48  * @param src input array
49  * constraints: align 16. values must be in range [-32767,32767]
50  * @param len number of values in the array
51  * constraints: multiple of 16 greater than 0
52  * @return a value with the same MSB as max(abs(src[]))
53  */
54  int (*ac3_max_msb_abs_int16)(const int16_t *src, int len);
55 
56  /**
57  * Left-shift each value in an array of int16_t by a specified amount.
58  * @param src input array
59  * constraints: align 16
60  * @param len number of values in the array
61  * constraints: multiple of 32 greater than 0
62  * @param shift left shift amount
63  * constraints: range [0,15]
64  */
65  void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift);
66 
67  /**
68  * Right-shift each value in an array of int32_t by a specified amount.
69  * @param src input array
70  * constraints: align 16
71  * @param len number of values in the array
72  * constraints: multiple of 16 greater than 0
73  * @param shift right shift amount
74  * constraints: range [0,31]
75  */
76  void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift);
77 
78  /**
79  * Convert an array of float in range [-1.0,1.0] to int32_t with range
80  * [-(1<<24),(1<<24)]
81  *
82  * @param dst destination array of int32_t.
83  * constraints: 16-byte aligned
84  * @param src source array of float.
85  * constraints: 16-byte aligned
86  * @param len number of elements to convert.
87  * constraints: multiple of 32 greater than zero
88  */
89  void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len);
90 
91  /**
92  * Calculate bit allocation pointers.
93  * The SNR is the difference between the masking curve and the signal. AC-3
94  * uses this value for each frequency bin to allocate bits. The snroffset
95  * parameter is a global adjustment to the SNR for all bins.
96  *
97  * @param[in] mask masking curve
98  * @param[in] psd signal power for each frequency bin
99  * @param[in] start starting bin location
100  * @param[in] end ending bin location
101  * @param[in] snr_offset SNR adjustment
102  * @param[in] floor noise floor
103  * @param[in] bap_tab look-up table for bit allocation pointers
104  * @param[out] bap bit allocation pointers
105  */
106  void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end,
107  int snr_offset, int floor,
108  const uint8_t *bap_tab, uint8_t *bap);
109 
110  /**
111  * Update bap counts using the supplied array of bap.
112  *
113  * @param[out] mant_cnt bap counts for 1 block
114  * @param[in] bap array of bap, pointing to start coef bin
115  * @param[in] len number of elements to process
116  */
117  void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len);
118 
119  /**
120  * Calculate the number of bits needed to encode a set of mantissas.
121  *
122  * @param[in] mant_cnt bap counts for all blocks
123  * @return mantissa bit count
124  */
125  int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]);
126 
127  void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs);
128 
129  void (*sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0,
130  const int32_t *coef1, int len);
131 
132  void (*sum_square_butterfly_float)(float sum[4], const float *coef0,
133  const float *coef1, int len);
134 
137  void (*downmix)(float **samples, float **matrix, int len);
138  void (*downmix_fixed)(int32_t **samples, int16_t **matrix, int len);
139 
140  /**
141  * Apply symmetric window in 16-bit fixed-point.
142  * @param output destination array
143  * constraints: 16-byte aligned
144  * @param input source array
145  * constraints: 16-byte aligned
146  * @param window window array
147  * constraints: 16-byte aligned, at least len/2 elements
148  * @param len full window length
149  * constraints: multiple of ? greater than zero
150  */
151  void (*apply_window_int16)(int16_t *output, const int16_t *input,
152  const int16_t *window, unsigned int len);
153 } AC3DSPContext;
154 
155 void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact);
156 void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact);
157 void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact);
158 void ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact);
159 
160 void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix,
161  int out_ch, int in_ch, int len);
162 void ff_ac3dsp_downmix_fixed(AC3DSPContext *c, int32_t **samples, int16_t **matrix,
163  int out_ch, int in_ch, int len);
164 
166 
167 #endif /* AVCODEC_AC3DSP_H */
static int shift(int a, int b)
Definition: sonic.c:82
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:117
void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c)
Definition: ac3dsp_init.c:139
void(* downmix)(float **samples, float **matrix, int len)
Definition: ac3dsp.h:137
void ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact)
Definition: ac3dsp_mips.c:403
static const uint8_t bap_tab[64]
Definition: dolby_e.h:632
#define src
Definition: vp8dsp.c:254
void(* extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs)
Definition: ac3dsp.h:127
void(* apply_window_int16)(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
Apply symmetric window in 16-bit fixed-point.
Definition: ac3dsp.h:151
uint8_t
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int out_channels
Definition: ac3dsp.h:135
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
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
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:106
int in_channels
Definition: ac3dsp.h:136
void ff_ac3dsp_downmix_fixed(AC3DSPContext *c, int32_t **samples, int16_t **matrix, int out_ch, int in_ch, int len)
Definition: ac3dsp.c:350
void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
Definition: ac3dsp_init.c:66
void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
static const uint16_t mask[17]
Definition: lzw.c:38
void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix, int out_ch, int in_ch, int len)
Definition: ac3dsp.c:390
int(* ac3_max_msb_abs_int16)(const int16_t *src, int len)
Calculate the maximum MSB of the absolute value of each element in an array of int16_t.
Definition: ac3dsp.h:54
void(* ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift)
Left-shift each value in an array of int16_t by a specified amount.
Definition: ac3dsp.h:65
int8_t exp
Definition: eval.c:72
void(* ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift)
Right-shift each value in an array of int32_t by a specified amount.
Definition: ac3dsp.h:76
static SDL_Window * window
Definition: ffplay.c:367
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int32_t
void(* sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0, const int32_t *coef1, int len)
Definition: ac3dsp.h:129
const uint16_t ff_ac3_bap_bits[16]
Number of mantissa bits written for each bap value.
Definition: ac3dsp.c:140
void(* downmix_fixed)(int32_t **samples, int16_t **matrix, int len)
Definition: ac3dsp.h:138
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:125
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
Definition: ac3dsp.c:422
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:43
int
int len
void(* sum_square_butterfly_float)(float sum[4], const float *coef0, const float *coef1, int len)
Definition: ac3dsp.h:132
Filter the word “frame” indicates either a video frame or a group of audio samples
void INT64 start
Definition: avisynth_c.h:766
void(* float_to_fixed24)(int32_t *dst, const float *src, unsigned int len)
Convert an array of float in range [-1.0,1.0] to int32_t with range [-(1<<24),(1<<24)].
Definition: ac3dsp.h:89