@ -51,44 +51,44 @@
/**
* information for single band used by 3 GPP TS26 .403 - inspired psychoacoustic model
*/
typedef struct Psy3gpp Band {
typedef struct Aac PsyBand{
float energy ; ///< band energy
float ffac ; ///< form factor
float thr ; ///< energy threshold
float min_snr ; ///< minimal SNR
float thr_quiet ; ///< threshold in quiet
} Psy3gpp Band ;
} Aac PsyBand;
/**
* single / pair channel context for psychoacoustic model
*/
typedef struct Psy3gpp Channel {
Psy3gpp Band band [ 128 ] ; ///< bands information
Psy3gpp Band prev_band [ 128 ] ; ///< bands information from the previous frame
typedef struct Aac PsyChannel{
Aac PsyBand band [ 128 ] ; ///< bands information
Aac PsyBand prev_band [ 128 ] ; ///< bands information from the previous frame
float win_energy ; ///< sliding average of channel energy
float iir_state [ 2 ] ; ///< hi-pass IIR filter state
uint8_t next_grouping ; ///< stored grouping scheme for the next frame (in case of 8 short window sequence)
enum WindowSequence next_window_seq ; ///< window sequence to be used in the next frame
} Psy3gpp Channel ;
} Aac PsyChannel;
/**
* psychoacoustic model frame type - dependent coefficients
*/
typedef struct Psy3gpp Coeffs {
typedef struct Aac PsyCoeffs{
float ath [ 64 ] ; ///< absolute threshold of hearing per bands
float barks [ 64 ] ; ///< Bark value for each spectral band in long frame
float spread_low [ 64 ] ; ///< spreading factor for low-to-high threshold spreading in long frame
float spread_hi [ 64 ] ; ///< spreading factor for high-to-low threshold spreading in long frame
} Psy3gpp Coeffs ;
} Aac PsyCoeffs;
/**
* 3 GPP TS26 .403 - inspired psychoacoustic model specific data
*/
typedef struct Psy3gpp Context {
Psy3gpp Coeffs psy_coef [ 2 ] ;
Psy3gpp Channel * ch ;
} Psy3gpp Context ;
typedef struct Aac PsyContext{
Aac PsyCoeffs psy_coef [ 2 ] ;
Aac PsyChannel * ch ;
} Aac PsyContext;
/**
* Calculate Bark value for given line .
@ -113,17 +113,17 @@ static av_cold float ath(float f, float add)
}
static av_cold int psy_3gpp_init ( FFPsyContext * ctx ) {
Psy3gpp Context * pctx ;
Aac PsyContext * pctx ;
float bark ;
int i , j , g , start ;
float prev , minscale , minath ;
ctx - > model_priv_data = av_mallocz ( sizeof ( Psy3gpp Context ) ) ;
pctx = ( Psy3gpp Context * ) ctx - > model_priv_data ;
ctx - > model_priv_data = av_mallocz ( sizeof ( Aac PsyContext) ) ;
pctx = ( Aac PsyContext* ) ctx - > model_priv_data ;
minath = ath ( 3410 , ATH_ADD ) ;
for ( j = 0 ; j < 2 ; j + + ) {
Psy3gpp Coeffs * coeffs = & pctx - > psy_coef [ j ] ;
Aac PsyCoeffs * coeffs = & pctx - > psy_coef [ j ] ;
float line_to_frequency = ctx - > avctx - > sample_rate / ( j ? 256.f : 2048.0f ) ;
i = 0 ;
prev = 0.0 ;
@ -147,7 +147,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
}
}
pctx - > ch = av_mallocz ( sizeof ( Psy3gpp Channel ) * ctx - > avctx - > channels ) ;
pctx - > ch = av_mallocz ( sizeof ( Aac PsyChannel) * ctx - > avctx - > channels ) ;
return 0 ;
}
@ -182,8 +182,8 @@ static FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
int i , j ;
int br = ctx - > avctx - > bit_rate / ctx - > avctx - > channels ;
int attack_ratio = br < = 16000 ? 18 : 10 ;
Psy3gpp Context * pctx = ( Psy3gpp Context * ) ctx - > model_priv_data ;
Psy3gpp Channel * pch = & pctx - > ch [ channel ] ;
Aac PsyContext * pctx = ( Aac PsyContext* ) ctx - > model_priv_data ;
Aac PsyChannel * pch = & pctx - > ch [ channel ] ;
uint8_t grouping = 0 ;
int next_type = pch - > next_window_seq ;
FFPsyWindowInfo wi ;
@ -266,18 +266,18 @@ static FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
static void psy_3gpp_analyze ( FFPsyContext * ctx , int channel ,
const float * coefs , FFPsyWindowInfo * wi )
{
Psy3gpp Context * pctx = ( Psy3gpp Context * ) ctx - > model_priv_data ;
Psy3gpp Channel * pch = & pctx - > ch [ channel ] ;
Aac PsyContext * pctx = ( Aac PsyContext* ) ctx - > model_priv_data ;
Aac PsyChannel * pch = & pctx - > ch [ channel ] ;
int start = 0 ;
int i , w , g ;
const int num_bands = ctx - > num_bands [ wi - > num_windows = = 8 ] ;
const uint8_t * band_sizes = ctx - > bands [ wi - > num_windows = = 8 ] ;
Psy3gpp Coeffs * coeffs = & pctx - > psy_coef [ wi - > num_windows = = 8 ] ;
Aac PsyCoeffs * coeffs = & pctx - > psy_coef [ wi - > num_windows = = 8 ] ;
//calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation"
for ( w = 0 ; w < wi - > num_windows * 16 ; w + = 16 ) {
for ( g = 0 ; g < num_bands ; g + + ) {
Psy3gpp Band * band = & pch - > band [ w + g ] ;
Aac PsyBand * band = & pch - > band [ w + g ] ;
band - > energy = 0.0f ;
for ( i = 0 ; i < band_sizes [ g ] ; i + + )
band - > energy + = coefs [ start + i ] * coefs [ start + i ] ;
@ -290,7 +290,7 @@ static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
}
//modify thresholds - spread, threshold in quiet - 5.4.3 "Spreaded Energy Calculation"
for ( w = 0 ; w < wi - > num_windows * 16 ; w + = 16 ) {
Psy3gpp Band * band = & pch - > band [ w ] ;
Aac PsyBand * band = & pch - > band [ w ] ;
for ( g = 1 ; g < num_bands ; g + + )
band [ g ] . thr = FFMAX ( band [ g ] . thr , band [ g - 1 ] . thr * coeffs - > spread_low [ g - 1 ] ) ;
for ( g = num_bands - 2 ; g > = 0 ; g - - )
@ -311,7 +311,7 @@ static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
static av_cold void psy_3gpp_end ( FFPsyContext * apc )
{
Psy3gpp Context * pctx = ( Psy3gpp Context * ) apc - > model_priv_data ;
Aac PsyContext * pctx = ( Aac PsyContext* ) apc - > model_priv_data ;
av_freep ( & pctx - > ch ) ;
av_freep ( & apc - > model_priv_data ) ;
}