1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

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.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-02-29 22:12:48 +01:00 committed by Lynne
parent 8b2261e573
commit fc3c2ea8dc
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
6 changed files with 53 additions and 22 deletions

View File

@ -30,9 +30,6 @@
#ifndef AVCODEC_AAC_H
#define AVCODEC_AAC_H
#include "aac_defines.h"
#define MAX_CHANNELS 64
#define MAX_ELEM_ID 16
@ -85,20 +82,6 @@ enum ChannelPosition {
AAC_CHANNEL_CC = 5,
};
/**
* Predictor State
*/
typedef struct PredictorState {
AAC_FLOAT cor0;
AAC_FLOAT cor1;
AAC_FLOAT var0;
AAC_FLOAT var1;
AAC_FLOAT r0;
AAC_FLOAT r1;
AAC_FLOAT k1;
AAC_FLOAT x_est;
} PredictorState;
#define MAX_PREDICTORS 672
#define SCALE_DIV_512 36 ///< scalefactor difference that corresponds to scale difference in 512 times

View File

@ -72,6 +72,20 @@ typedef int AAC_SIGNE;
0x40000000) >> 31)
#define AAC_HALF_SUM(x, y) (((x) >> 1) + ((y) >> 1))
/**
* Predictor State
*/
typedef struct PredictorStateFixed {
SoftFloat cor0;
SoftFloat cor1;
SoftFloat var0;
SoftFloat var1;
SoftFloat r0;
SoftFloat r1;
SoftFloat k1;
SoftFloat x_est;
} PredictorState;
#ifdef LPC_USE_FIXED
#error aac_defines.h must be included before lpc_functions.h for fixed point decoder
#endif
@ -112,6 +126,20 @@ typedef unsigned AAC_SIGNE;
#define AAC_MSUB31_V3(x, y, z) ((x) - (y)) * (z)
#define AAC_HALF_SUM(x, y) ((x) + (y)) * 0.5f
/**
* Predictor State
*/
typedef struct PredictorState {
float cor0;
float cor1;
float var0;
float var1;
float r0;
float r1;
float k1;
float x_est;
} PredictorState;
#endif /* USE_FIXED */
#endif /* AVCODEC_AAC_DEFINES_H */

View File

@ -140,7 +140,10 @@ typedef struct SingleChannelElement {
DECLARE_ALIGNED(32, INTFLOAT, saved)[1536]; ///< overlap
DECLARE_ALIGNED(32, INTFLOAT, ret_buf)[2048]; ///< PCM output buffer
DECLARE_ALIGNED(16, INTFLOAT, ltp_state)[3072]; ///< time signal for LTP
PredictorState predictor_state[MAX_PREDICTORS];
union {
struct PredictorStateFixed *RENAME_FIXED(predictor_state);
struct PredictorState *predictor_state;
};
INTFLOAT *ret; ///< PCM output
} SingleChannelElement;

View File

@ -1942,7 +1942,7 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce)
int sfb, k;
if (!sce->ics.predictor_initialized) {
reset_all_predictors(sce->predictor_state);
reset_all_predictors(sce->AAC_RENAME(predictor_state));
sce->ics.predictor_initialized = 1;
}
@ -1953,16 +1953,16 @@ static void apply_prediction(AACDecContext *ac, SingleChannelElement *sce)
for (k = sce->ics.swb_offset[sfb];
k < sce->ics.swb_offset[sfb + 1];
k++) {
predict(&sce->predictor_state[k], &sce->coeffs[k],
predict(&sce->AAC_RENAME(predictor_state)[k], &sce->coeffs[k],
sce->ics.predictor_present &&
sce->ics.prediction_used[sfb]);
}
}
if (sce->ics.predictor_reset_group)
reset_predictor_group(sce->predictor_state,
reset_predictor_group(sce->AAC_RENAME(predictor_state),
sce->ics.predictor_reset_group);
} else
reset_all_predictors(sce->predictor_state);
reset_all_predictors(sce->AAC_RENAME(predictor_state));
}
static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb)

View File

@ -49,6 +49,20 @@ typedef enum AACCoder {
AAC_CODER_NB,
}AACCoder;
/**
* Predictor State
*/
typedef struct PredictorState {
float cor0;
float cor1;
float var0;
float var1;
float r0;
float r1;
float k1;
float x_est;
} PredictorState;
typedef struct AACEncOptions {
int coder;
int pns;

View File

@ -40,6 +40,7 @@
typedef struct ExtChannelElement {
ChannelElement ch;
PredictorState predictor_state[2][MAX_PREDICTORS];
SpectralBandReplication sbr;
} ExtChannelElement;
@ -87,6 +88,8 @@ av_cold int AAC_RENAME(ff_aac_sbr_ctx_alloc_init)(AACDecContext *ac,
return AVERROR(ENOMEM);
*che = &ext->ch;
sbr = &ext->sbr;
ext->ch.ch[0].AAC_RENAME(predictor_state) = ext->predictor_state[0];
ext->ch.ch[1].AAC_RENAME(predictor_state) = ext->predictor_state[1];
sbr->kx[0] = sbr->kx[1];
sbr->id_aac = id_aac;