History

avcodec/aacdec: PredictorState array out of SingleChannelElement

sizeof(PredictorState) is different for the floating-point and the fixed-point AAC decoders; this is an obstacle for deduplicating code between these decoders. So don't include this array in SingleChannelElement, instead add a union of pointers to the fixed-point PredictorState and the floating-point PredictorState. The actual arrays are part of the extended ChannelElement to be allocated by ff_aac_sbr_ctx_alloc_init(); it also sets the pointers.

Andreas Rheinhardt committed 2 years ago

Commit fc3c2ea1 parent 8b2261e6 files · +53 −22Browse files

Unified · Split

6 files
  1. libavcodec/aac.h +0 −17
  2. libavcodec/aac_defines.h +28 −0
  3. libavcodec/aacdec.h +4 −1
  4. libavcodec/aacdec_template.c +4 −4
  5. libavcodec/aacenc.h +14 −0
  6. libavcodec/aacsbr_template.c +3 −0
libavcodec/aac.h+0−17
@@ -30,9 +30,6 @@ · 29 unmodified lines
3030 #ifndef AVCODEC_AAC_H
3131 #define AVCODEC_AAC_H
3232
33−
34−#include "aac_defines.h"
35−
3633 #define MAX_CHANNELS 64
3734 #define MAX_ELEM_ID 16
3835
@@ -85,20 +82,6 @@ enum ChannelPosition { · 46 unmodified lines
8582 AAC_CHANNEL_CC = 5,
8683 };
8784
88−/**
89− * Predictor State
90− */
91−typedef struct PredictorState {
92− AAC_FLOAT cor0;
93− AAC_FLOAT cor1;
94− AAC_FLOAT var0;
95− AAC_FLOAT var1;
96− AAC_FLOAT r0;
97− AAC_FLOAT r1;
98− AAC_FLOAT k1;
99− AAC_FLOAT x_est;
100−} PredictorState;
101−
10285 #define MAX_PREDICTORS 672
10386
10487 #define SCALE_DIV_512 36 ///< scalefactor difference that corresponds to scale difference in 512 times
libavcodec/aac_defines.h+28−0
@@ -72,6 +72,20 @@ typedef int AAC_SIGNE; · 71 unmodified lines
7272 0x40000000) >> 31)
7373 #define AAC_HALF_SUM(x, y) (((x) >> 1) + ((y) >> 1))
7474
75+/**
76+ * Predictor State
77+ */
78+typedef struct PredictorStateFixed {
79+ SoftFloat cor0;
80+ SoftFloat cor1;
81+ SoftFloat var0;
82+ SoftFloat var1;
83+ SoftFloat r0;
84+ SoftFloat r1;
85+ SoftFloat k1;
86+ SoftFloat x_est;
87+} PredictorState;
88+
7589 #ifdef LPC_USE_FIXED
7690 #error aac_defines.h must be included before lpc_functions.h for fixed point decoder
7791 #endif
@@ -112,6 +126,20 @@ typedef unsigned AAC_SIGNE; · 34 unmodified lines
112126 #define AAC_MSUB31_V3(x, y, z) ((x) - (y)) * (z)
113127 #define AAC_HALF_SUM(x, y) ((x) + (y)) * 0.5f
114128
129+/**
130+ * Predictor State
131+ */
132+typedef struct PredictorState {
133+ float cor0;
134+ float cor1;
135+ float var0;
136+ float var1;
137+ float r0;
138+ float r1;
139+ float k1;
140+ float x_est;
141+} PredictorState;
142+
115143 #endif /* USE_FIXED */
116144
117145 #endif /* AVCODEC_AAC_DEFINES_H */
libavcodec/aacdec.h+4−1
@@ -140,7 +140,10 @@ typedef struct SingleChannelElement { · 139 unmodified lines
140140 DECLARE_ALIGNED(32, INTFLOAT, saved)[1536]; ///< overlap
141141 DECLARE_ALIGNED(32, INTFLOAT, ret_buf)[2048]; ///< PCM output buffer
142142 DECLARE_ALIGNED(16, INTFLOAT, ltp_state)[3072]; ///< time signal for LTP
143− PredictorState predictor_state[MAX_PREDICTORS];
143+ union {
144+ struct PredictorStateFixed *RENAME_FIXED(predictor_state);
145+ struct PredictorState *predictor_state;
146+ };
144147 INTFLOAT *ret; ///< PCM output
145148 } SingleChannelElement;
146149
libavcodec/aacdec_template.c+4−4
@@ -1942,7 +1942,7 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce) · 1941 unmodified lines
19421942 int sfb, k;
19431943
19441944 if (!sce->ics.predictor_initialized) {
1945− reset_all_predictors(sce->predictor_state);
1945+ reset_all_predictors(sce->AAC_RENAME(predictor_state));
19461946 sce->ics.predictor_initialized = 1;
19471947 }
19481948
@@ -1953,16 +1953,16 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce) · 4 unmodified lines
19531953 for (k = sce->ics.swb_offset[sfb];
19541954 k < sce->ics.swb_offset[sfb + 1];
19551955 k++) {
1956− predict(&sce->predictor_state[k], &sce->coeffs[k],
1956+ predict(&sce->AAC_RENAME(predictor_state)[k], &sce->coeffs[k],
19571957 sce->ics.predictor_present &&
19581958 sce->ics.prediction_used[sfb]);
19591959 }
19601960 }
19611961 if (sce->ics.predictor_reset_group)
1962− reset_predictor_group(sce->predictor_state,
1962+ reset_predictor_group(sce->AAC_RENAME(predictor_state),
19631963 sce->ics.predictor_reset_group);
19641964 } else
1965− reset_all_predictors(sce->predictor_state);
1965+ reset_all_predictors(sce->AAC_RENAME(predictor_state));
19661966 }
19671967
19681968 static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb)
libavcodec/aacenc.h+14−0
@@ -49,6 +49,20 @@ typedef enum AACCoder { · 48 unmodified lines
4949 AAC_CODER_NB,
5050 }AACCoder;
5151
52+/**
53+ * Predictor State
54+ */
55+typedef struct PredictorState {
56+ float cor0;
57+ float cor1;
58+ float var0;
59+ float var1;
60+ float r0;
61+ float r1;
62+ float k1;
63+ float x_est;
64+} PredictorState;
65+
5266 typedef struct AACEncOptions {
5367 int coder;
5468 int pns;
libavcodec/aacsbr_template.c+3−0
@@ -40,6 +40,7 @@ · 39 unmodified lines
4040
4141 typedef struct ExtChannelElement {
4242 ChannelElement ch;
43+ PredictorState predictor_state[2][MAX_PREDICTORS];
4344 SpectralBandReplication sbr;
4445 } ExtChannelElement;
4546
@@ -87,6 +88,8 @@ av_cold int AAC_RENAME(ff_aac_sbr_ctx_alloc_init)(AACDecContext *ac, · 41 unmodified lines
8788 return AVERROR(ENOMEM);
8889 *che = &ext->ch;
8990 sbr = &ext->sbr;
91+ ext->ch.ch[0].AAC_RENAME(predictor_state) = ext->predictor_state[0];
92+ ext->ch.ch[1].AAC_RENAME(predictor_state) = ext->predictor_state[1];
9093
9194 sbr->kx[0] = sbr->kx[1];
9295 sbr->id_aac = id_aac;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t