本文整理汇总了C++中silk_LSHIFT函数的典型用法代码示例。如果您正苦于以下问题:C++ silk_LSHIFT函数的具体用法?C++ silk_LSHIFT怎么用?C++ silk_LSHIFT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了silk_LSHIFT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: silk_HP_variable_cutoff
/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
void silk_HP_variable_cutoff(silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */
)
{
int quality_Q15;
int32_t pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7;
silk_encoder_state *psEncC1 = &state_Fxx[0].sCmn;
/* Adaptive cutoff frequency: estimate low end of pitch frequency range */
if (psEncC1->prevSignalType == TYPE_VOICED) {
/* difference, in log domain */
pitch_freq_Hz_Q16 =
silk_DIV32_16(silk_LSHIFT
(silk_MUL(psEncC1->fs_kHz, 1000), 16),
psEncC1->prevLag);
pitch_freq_log_Q7 = silk_lin2log(pitch_freq_Hz_Q16) - (16 << 7);
/* adjustment based on quality */
quality_Q15 = psEncC1->input_quality_bands_Q15[0];
pitch_freq_log_Q7 =
silk_SMLAWB(pitch_freq_log_Q7,
silk_SMULWB(silk_LSHIFT(-quality_Q15, 2),
quality_Q15),
pitch_freq_log_Q7 -
(silk_lin2log
(SILK_FIX_CONST(VARIABLE_HP_MIN_CUTOFF_HZ, 16))
- (16 << 7)));
/* delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; */
delta_freq_Q7 =
pitch_freq_log_Q7 -
silk_RSHIFT(psEncC1->variable_HP_smth1_Q15, 8);
if (delta_freq_Q7 < 0) {
/* less smoothing for decreasing pitch frequency, to track something close to the minimum */
delta_freq_Q7 = silk_MUL(delta_freq_Q7, 3);
}
/* limit delta, to reduce impact of outliers in pitch estimation */
delta_freq_Q7 =
silk_LIMIT_32(delta_freq_Q7,
-SILK_FIX_CONST(VARIABLE_HP_MAX_DELTA_FREQ,
7),
SILK_FIX_CONST(VARIABLE_HP_MAX_DELTA_FREQ,
7));
/* update smoother */
psEncC1->variable_HP_smth1_Q15 =
silk_SMLAWB(psEncC1->variable_HP_smth1_Q15,
silk_SMULBB(psEncC1->speech_activity_Q8,
delta_freq_Q7),
SILK_FIX_CONST(VARIABLE_HP_SMTH_COEF1, 16));
/* limit frequency range */
psEncC1->variable_HP_smth1_Q15 =
silk_LIMIT_32(psEncC1->variable_HP_smth1_Q15,
silk_LSHIFT(silk_lin2log
(VARIABLE_HP_MIN_CUTOFF_HZ), 8),
silk_LSHIFT(silk_lin2log
(VARIABLE_HP_MAX_CUTOFF_HZ), 8));
}
}
示例2: silk_A2NLSF_init
static OPUS_INLINE void silk_A2NLSF_init(
const opus_int32 *a_Q16,
opus_int32 *P,
opus_int32 *Q,
const opus_int dd
)
{
opus_int k;
/* Convert filter coefs to even and odd polynomials */
P[dd] = silk_LSHIFT( 1, 16 );
Q[dd] = silk_LSHIFT( 1, 16 );
for( k = 0; k < dd; k++ ) {
P[ k ] = -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ]; /* Q16 */
Q[ k ] = -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ]; /* Q16 */
}
/* Divide out zeros as we have that for even filter orders, */
/* z = 1 is always a root in Q, and */
/* z = -1 is always a root in P */
for( k = dd; k > 0; k-- ) {
P[ k - 1 ] -= P[ k ];
Q[ k - 1 ] += Q[ k ];
}
/* Transform polynomials from cos(n*f) to cos(f)^n */
silk_A2NLSF_trans_poly( P, dd );
silk_A2NLSF_trans_poly( Q, dd );
}
示例3: silk_schur
/* uses SMLAWB(), requiring armv5E and higher. */
opus_int32 silk_schur( /* O Returns residual energy */
opus_int16 *rc_Q15, /* O reflection coefficients [order] Q15 */
const opus_int32 *c, /* I correlations [order+1] */
const opus_int32 order /* I prediction order */
)
{
opus_int k, n, lz;
opus_int32 C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ];
opus_int32 Ctmp1, Ctmp2, rc_tmp_Q15;
silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 );
/* Get number of leading zeros */
lz = silk_CLZ32( c[ 0 ] );
/* Copy correlations and adjust level to Q30 */
if( lz < 2 ) {
/* lz must be 1, so shift one to the right */
for( k = 0; k < order + 1; k++ ) {
C[ k ][ 0 ] = C[ k ][ 1 ] = silk_RSHIFT( c[ k ], 1 );
}
} else if( lz > 2 ) {
/* Shift to the left */
lz -= 2;
for( k = 0; k < order + 1; k++ ) {
C[ k ][ 0 ] = C[ k ][ 1 ] = silk_LSHIFT( c[ k ], lz );
}
} else {
/* No need to shift */
for( k = 0; k < order + 1; k++ ) {
C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ];
}
}
for( k = 0; k < order; k++ ) {
/* Get reflection coefficient */
rc_tmp_Q15 = -silk_DIV32_16( C[ k + 1 ][ 0 ], silk_max_32( silk_RSHIFT( C[ 0 ][ 1 ], 15 ), 1 ) );
/* Clip (shouldn't happen for properly conditioned inputs) */
rc_tmp_Q15 = silk_SAT16( rc_tmp_Q15 );
/* Store */
rc_Q15[ k ] = (opus_int16)rc_tmp_Q15;
/* Update correlations */
for( n = 0; n < order - k; n++ ) {
Ctmp1 = C[ n + k + 1 ][ 0 ];
Ctmp2 = C[ n ][ 1 ];
C[ n + k + 1 ][ 0 ] = silk_SMLAWB( Ctmp1, silk_LSHIFT( Ctmp2, 1 ), rc_tmp_Q15 );
C[ n ][ 1 ] = silk_SMLAWB( Ctmp2, silk_LSHIFT( Ctmp1, 1 ), rc_tmp_Q15 );
}
}
/* return residual energy */
return C[ 0 ][ 1 ];
}
示例4: silk_schur64
/* Uses SMULL(), available on armv4 */
opus_int32 silk_schur64( /* O returns residual energy */
opus_int32 rc_Q16[], /* O Reflection coefficients [order] Q16 */
const opus_int32 c[], /* I Correlations [order+1] */
opus_int32 order /* I Prediction order */
)
{
opus_int k, n;
opus_int32 C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ];
opus_int32 Ctmp1_Q30, Ctmp2_Q30, rc_tmp_Q31;
silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 );
/* Check for invalid input */
if( c[ 0 ] <= 0 ) {
silk_memset( rc_Q16, 0, order * sizeof( opus_int32 ) );
return 0;
}
for( k = 0; k < order + 1; k++ ) {
C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ];
}
for( k = 0; k < order; k++ ) {
/* Check that we won't be getting an unstable rc, otherwise stop here. */
if (silk_abs_int32(C[ k + 1 ][ 0 ]) >= C[ 0 ][ 1 ]) {
if ( C[ k + 1 ][ 0 ] > 0 ) {
rc_Q16[ k ] = -SILK_FIX_CONST( .99f, 16 );
} else {
rc_Q16[ k ] = SILK_FIX_CONST( .99f, 16 );
}
k++;
break;
}
/* Get reflection coefficient: divide two Q30 values and get result in Q31 */
rc_tmp_Q31 = silk_DIV32_varQ( -C[ k + 1 ][ 0 ], C[ 0 ][ 1 ], 31 );
/* Save the output */
rc_Q16[ k ] = silk_RSHIFT_ROUND( rc_tmp_Q31, 15 );
/* Update correlations */
for( n = 0; n < order - k; n++ ) {
Ctmp1_Q30 = C[ n + k + 1 ][ 0 ];
Ctmp2_Q30 = C[ n ][ 1 ];
/* Multiply and add the highest int32 */
C[ n + k + 1 ][ 0 ] = Ctmp1_Q30 + silk_SMMUL( silk_LSHIFT( Ctmp2_Q30, 1 ), rc_tmp_Q31 );
C[ n ][ 1 ] = Ctmp2_Q30 + silk_SMMUL( silk_LSHIFT( Ctmp1_Q30, 1 ), rc_tmp_Q31 );
}
}
for(; k < order; k++ ) {
rc_Q16[ k ] = 0;
}
return silk_max_32( 1, C[ 0 ][ 1 ] );
}
示例5: silk_PLC_glue_frames
/* Glues concealed frames with new good received frames */
void silk_PLC_glue_frames(
silk_decoder_state *psDec, /* I/O decoder state */
opus_int16 frame[], /* I/O signal */
opus_int length /* I length of signal */
)
{
opus_int i, energy_shift;
opus_int32 energy;
silk_PLC_struct *psPLC;
psPLC = &psDec->sPLC;
if( psDec->lossCnt ) {
/* Calculate energy in concealed residual */
silk_sum_sqr_shift( &psPLC->conc_energy, &psPLC->conc_energy_shift, frame, length );
psPLC->last_frame_lost = 1;
} else {
if( psDec->sPLC.last_frame_lost ) {
/* Calculate residual in decoded signal if last frame was lost */
silk_sum_sqr_shift( &energy, &energy_shift, frame, length );
/* Normalize energies */
if( energy_shift > psPLC->conc_energy_shift ) {
psPLC->conc_energy = silk_RSHIFT( psPLC->conc_energy, energy_shift - psPLC->conc_energy_shift );
} else if( energy_shift < psPLC->conc_energy_shift ) {
energy = silk_RSHIFT( energy, psPLC->conc_energy_shift - energy_shift );
}
/* Fade in the energy difference */
if( energy > psPLC->conc_energy ) {
opus_int32 frac_Q24, LZ;
opus_int32 gain_Q16, slope_Q16;
LZ = silk_CLZ32( psPLC->conc_energy );
LZ = LZ - 1;
psPLC->conc_energy = silk_LSHIFT( psPLC->conc_energy, LZ );
energy = silk_RSHIFT( energy, silk_max_32( 24 - LZ, 0 ) );
frac_Q24 = silk_DIV32( psPLC->conc_energy, silk_max( energy, 1 ) );
gain_Q16 = silk_LSHIFT( silk_SQRT_APPROX( frac_Q24 ), 4 );
slope_Q16 = silk_DIV32_16( ( (opus_int32)1 << 16 ) - gain_Q16, length );
/* Make slope 4x steeper to avoid missing onsets after DTX */
slope_Q16 = silk_LSHIFT( slope_Q16, 2 );
for( i = 0; i < length; i++ ) {
frame[ i ] = silk_SMULWB( gain_Q16, frame[ i ] );
gain_Q16 += slope_Q16;
if( gain_Q16 > (opus_int32)1 << 16 ) {
break;
}
}
}
}
psPLC->last_frame_lost = 0;
}
}
示例6: silk_prefilt_FIX
/* Prefilter for finding Quantizer input signal */
static OPUS_INLINE void silk_prefilt_FIX(
silk_prefilter_state_FIX *P, /* I/O state */
opus_int32 st_res_Q12[], /* I short term residual signal */
opus_int32 xw_Q3[], /* O prefiltered signal */
opus_int32 HarmShapeFIRPacked_Q12, /* I Harmonic shaping coeficients */
opus_int Tilt_Q14, /* I Tilt shaping coeficient */
opus_int32 LF_shp_Q14, /* I Low-frequancy shaping coeficients */
opus_int lag, /* I Lag for harmonic shaping */
opus_int length /* I Length of signals */
) {
opus_int i, idx, LTP_shp_buf_idx;
opus_int32 n_LTP_Q12, n_Tilt_Q10, n_LF_Q10;
opus_int32 sLF_MA_shp_Q12, sLF_AR_shp_Q12;
opus_int16 *LTP_shp_buf;
/* To speed up use temp variables instead of using the struct */
LTP_shp_buf = P->sLTP_shp;
LTP_shp_buf_idx = P->sLTP_shp_buf_idx;
sLF_AR_shp_Q12 = P->sLF_AR_shp_Q12;
sLF_MA_shp_Q12 = P->sLF_MA_shp_Q12;
for (i = 0; i < length; i++) {
if (lag > 0) {
/* unrolled loop */
silk_assert(HARM_SHAPE_FIR_TAPS == 3);
idx = lag + LTP_shp_buf_idx;
n_LTP_Q12 = silk_SMULBB(LTP_shp_buf[(idx - HARM_SHAPE_FIR_TAPS / 2 - 1) & LTP_MASK],
HarmShapeFIRPacked_Q12);
n_LTP_Q12 = silk_SMLABT(n_LTP_Q12,
LTP_shp_buf[(idx - HARM_SHAPE_FIR_TAPS / 2) & LTP_MASK],
HarmShapeFIRPacked_Q12);
n_LTP_Q12 = silk_SMLABB(n_LTP_Q12,
LTP_shp_buf[(idx - HARM_SHAPE_FIR_TAPS / 2 + 1) & LTP_MASK],
HarmShapeFIRPacked_Q12);
} else {
n_LTP_Q12 = 0;
}
n_Tilt_Q10 = silk_SMULWB(sLF_AR_shp_Q12, Tilt_Q14);
n_LF_Q10 = silk_SMLAWB(silk_SMULWT(sLF_AR_shp_Q12, LF_shp_Q14), sLF_MA_shp_Q12, LF_shp_Q14);
sLF_AR_shp_Q12 = silk_SUB32(st_res_Q12[i], silk_LSHIFT(n_Tilt_Q10, 2));
sLF_MA_shp_Q12 = silk_SUB32(sLF_AR_shp_Q12, silk_LSHIFT(n_LF_Q10, 2));
LTP_shp_buf_idx = (LTP_shp_buf_idx - 1) & LTP_MASK;
LTP_shp_buf[LTP_shp_buf_idx] = (opus_int16) silk_SAT16(
silk_RSHIFT_ROUND(sLF_MA_shp_Q12, 12));
xw_Q3[i] = silk_RSHIFT_ROUND(silk_SUB32(sLF_MA_shp_Q12, n_LTP_Q12), 9);
}
/* Copy temp variable back to state */
P->sLF_AR_shp_Q12 = sLF_AR_shp_Q12;
P->sLF_MA_shp_Q12 = sLF_MA_shp_Q12;
P->sLTP_shp_buf_idx = LTP_shp_buf_idx;
}
示例7: silk_stereo_find_predictor
/* Find least-squares prediction gain for one signal based on another and quantize it */
int32_t silk_stereo_find_predictor( /* O Returns predictor in Q13 */
int32_t * ratio_Q14, /* O Ratio of residual and mid energies */
const int16_t x[], /* I Basis signal */
const int16_t y[], /* I Target signal */
int32_t mid_res_amp_Q0[], /* I/O Smoothed mid, residual norms */
int length, /* I Number of samples */
int smooth_coef_Q16 /* I Smoothing coefficient */
)
{
int scale, scale1, scale2;
int32_t nrgx, nrgy, corr, pred_Q13, pred2_Q10;
/* Find predictor */
silk_sum_sqr_shift(&nrgx, &scale1, x, length);
silk_sum_sqr_shift(&nrgy, &scale2, y, length);
scale = silk_max_int(scale1, scale2);
scale = scale + (scale & 1); /* make even */
nrgy = silk_RSHIFT32(nrgy, scale - scale2);
nrgx = silk_RSHIFT32(nrgx, scale - scale1);
nrgx = silk_max_int(nrgx, 1);
corr = silk_inner_prod_aligned_scale(x, y, scale, length);
pred_Q13 = silk_DIV32_varQ(corr, nrgx, 13);
pred_Q13 = silk_LIMIT(pred_Q13, -(1 << 14), 1 << 14);
pred2_Q10 = silk_SMULWB(pred_Q13, pred_Q13);
/* Faster update for signals with large prediction parameters */
smooth_coef_Q16 =
(int) silk_max_int(smooth_coef_Q16, silk_abs(pred2_Q10));
/* Smoothed mid and residual norms */
assert(smooth_coef_Q16 < 32768);
scale = silk_RSHIFT(scale, 1);
mid_res_amp_Q0[0] =
silk_SMLAWB(mid_res_amp_Q0[0],
silk_LSHIFT(silk_SQRT_APPROX(nrgx),
scale) - mid_res_amp_Q0[0],
smooth_coef_Q16);
/* Residual energy = nrgy - 2 * pred * corr + pred^2 * nrgx */
nrgy = silk_SUB_LSHIFT32(nrgy, silk_SMULWB(corr, pred_Q13), 3 + 1);
nrgy = silk_ADD_LSHIFT32(nrgy, silk_SMULWB(nrgx, pred2_Q10), 6);
mid_res_amp_Q0[1] =
silk_SMLAWB(mid_res_amp_Q0[1],
silk_LSHIFT(silk_SQRT_APPROX(nrgy),
scale) - mid_res_amp_Q0[1],
smooth_coef_Q16);
/* Ratio of smoothed residual and mid norms */
*ratio_Q14 =
silk_DIV32_varQ(mid_res_amp_Q0[1], silk_max(mid_res_amp_Q0[0], 1),
14);
*ratio_Q14 = silk_LIMIT(*ratio_Q14, 0, 32767);
return pred_Q13;
}
示例8: silk_control_SNR
/* Control SNR of redidual quantizer */
opus_int silk_control_SNR(
silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
opus_int32 TargetRate_bps /* I Target max bitrate (bps) */
) {
opus_int k, ret = SILK_NO_ERROR;
opus_int32 frac_Q6;
const opus_int32 *rateTable;
/* Set bitrate/coding quality */
TargetRate_bps = silk_LIMIT(TargetRate_bps, MIN_TARGET_RATE_BPS, MAX_TARGET_RATE_BPS);
if (TargetRate_bps != psEncC->TargetRate_bps) {
psEncC->TargetRate_bps = TargetRate_bps;
/* If new TargetRate_bps, translate to SNR_dB value */
if (psEncC->fs_kHz == 8) {
rateTable = silk_TargetRate_table_NB;
} else if (psEncC->fs_kHz == 12) {
rateTable = silk_TargetRate_table_MB;
} else {
rateTable = silk_TargetRate_table_WB;
}
/* Reduce bitrate for 10 ms modes in these calculations */
if (psEncC->nb_subfr == 2) {
TargetRate_bps -= REDUCE_BITRATE_10_MS_BPS;
}
/* Find bitrate interval in table and interpolate */
for (k = 1; k < TARGET_RATE_TAB_SZ; k++) {
if (TargetRate_bps <= rateTable[k]) {
frac_Q6 = silk_DIV32(silk_LSHIFT(TargetRate_bps - rateTable[k - 1], 6),
rateTable[k] - rateTable[k - 1]);
psEncC->SNR_dB_Q7 = silk_LSHIFT(silk_SNR_table_Q1[k - 1], 6) + silk_MUL(frac_Q6,
silk_SNR_table_Q1[k] -
silk_SNR_table_Q1[
k -
1]);
break;
}
}
/* Reduce coding quality whenever LBRR is enabled, to free up some bits */
if (psEncC->LBRR_enabled) {
psEncC->SNR_dB_Q7 = silk_SMLABB(psEncC->SNR_dB_Q7, 12 - psEncC->LBRR_GainIncreases,
SILK_FIX_CONST(-0.25, 7));
}
}
return ret;
}
示例9: silk_A2NLSF_eval_poly
/* Polynomial evaluation */
static OPUS_INLINE opus_int32 silk_A2NLSF_eval_poly( /* return the polynomial evaluation, in Q16 */
opus_int32 *p, /* I Polynomial, Q16 */
const opus_int32 x, /* I Evaluation point, Q12 */
const opus_int dd /* I Order */
)
{
opus_int n;
opus_int32 x_Q16, y32;
y32 = p[ dd ]; /* Q16 */
x_Q16 = silk_LSHIFT( x, 4 );
if ( opus_likely( 8 == dd ) )
{
y32 = (opus_int32) silk_SMLAWW( p[ 7 ], y32, x_Q16 );
y32 = (opus_int32) silk_SMLAWW( p[ 6 ], y32, x_Q16 );
y32 = (opus_int32) silk_SMLAWW( p[ 5 ], y32, x_Q16 );
y32 = (opus_int32) silk_SMLAWW( p[ 4 ], y32, x_Q16 );
y32 = (opus_int32) silk_SMLAWW( p[ 3 ], y32, x_Q16 );
y32 = (opus_int32) silk_SMLAWW( p[ 2 ], y32, x_Q16 );
y32 = (opus_int32) silk_SMLAWW( p[ 1 ], y32, x_Q16 );
y32 = (opus_int32) silk_SMLAWW( p[ 0 ], y32, x_Q16 );
}
else
{
for( n = dd - 1; n >= 0; n-- ) {
y32 = (opus_int32) silk_SMLAWW( p[ n ], y32, x_Q16 ); /* Q16 */
}
}
return y32;
}
示例10: silk_gains_dequant
/* Gains scalar dequantization, uniform on log scale */
void silk_gains_dequant(
opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* O quantized gains */
const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */
opus_int8 *prev_ind, /* I/O last index in previous frame */
const opus_int conditional, /* I first gain is delta coded if 1 */
const opus_int nb_subfr /* I number of subframes */
)
{
opus_int k, ind_tmp, double_step_size_threshold;
for( k = 0; k < nb_subfr; k++ ) {
if( k == 0 && conditional == 0 ) {
/* Gain index is not allowed to go down more than 16 steps (~21.8 dB) */
*prev_ind = silk_max_int( ind[ k ], *prev_ind - 16 );
} else {
/* Delta index */
ind_tmp = ind[ k ] + MIN_DELTA_GAIN_QUANT;
/* Accumulate deltas */
double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANT - N_LEVELS_QGAIN + *prev_ind;
if( ind_tmp > double_step_size_threshold ) {
*prev_ind += silk_LSHIFT( ind_tmp, 1 ) - double_step_size_threshold;
} else {
*prev_ind += ind_tmp;
}
}
*prev_ind = silk_LIMIT_int( *prev_ind, 0, N_LEVELS_QGAIN - 1 );
/* Scale and convert to linear scale */
gain_Q16[ k ] = silk_log2lin( silk_min_32( silk_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */
}
}
示例11: silk_NLSF_decode
void silk_NLSF_decode(
opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
)
{
opus_int i;
opus_uint8 pred_Q8[ MAX_LPC_ORDER ];
opus_int16 ec_ix[ MAX_LPC_ORDER ];
opus_int16 res_Q10[ MAX_LPC_ORDER ];
opus_int32 NLSF_Q15_tmp;
const opus_uint8 *pCB_element;
const opus_int16 *pCB_Wght_Q9;
/* Unpack entropy table indices and predictor for current CB1 index */
silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, NLSFIndices[ 0 ] );
/* Predictive residual dequantizer */
silk_NLSF_residual_dequant( res_Q10, &NLSFIndices[ 1 ], pred_Q8, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->order );
/* Apply inverse square-rooted weights to first stage and add to output */
pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ];
pCB_Wght_Q9 = &psNLSF_CB->CB1_Wght_Q9[ NLSFIndices[ 0 ] * psNLSF_CB->order ];
for( i = 0; i < psNLSF_CB->order; i++ ) {
NLSF_Q15_tmp = silk_ADD_LSHIFT32( silk_DIV32_16( silk_LSHIFT( (opus_int32)res_Q10[ i ], 14 ), pCB_Wght_Q9[ i ] ), (opus_int16)pCB_element[ i ], 7 );
pNLSF_Q15[ i ] = (opus_int16)silk_LIMIT( NLSF_Q15_tmp, 0, 32767 );
}
/* NLSF stabilization */
silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order );
}
示例12: silk_process_gains_FIX
/* Processing of gains */
void silk_process_gains_FIX(
silk_encoder_state_FIX *psEnc, /* I/O Encoder state */
silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */
opus_int condCoding /* I The type of conditional coding to use */
)
{
silk_shape_state_FIX *psShapeSt = &psEnc->sShape;
opus_int k;
opus_int32 s_Q16, InvMaxSqrVal_Q16, gain, gain_squared, ResNrg, ResNrgPart, quant_offset_Q10;
/* Gain reduction when LTP coding gain is high */
if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) {
/*s = -0.5f * silk_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); */
s_Q16 = -silk_sigm_Q15( silk_RSHIFT_ROUND( psEncCtrl->LTPredCodGain_Q7 - SILK_FIX_CONST( 12.0, 7 ), 4 ) );
for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {
psEncCtrl->Gains_Q16[ k ] = silk_SMLAWB( psEncCtrl->Gains_Q16[ k ], psEncCtrl->Gains_Q16[ k ], s_Q16 );
}
}
/* Limit the quantized signal */
/* InvMaxSqrVal = pow( 2.0f, 0.33f * ( 21.0f - SNR_dB ) ) / subfr_length; */
InvMaxSqrVal_Q16 = silk_DIV32_16( silk_log2lin(
silk_SMULWB( SILK_FIX_CONST( 21 + 16 / 0.33, 7 ) - psEnc->sCmn.SNR_dB_Q7, SILK_FIX_CONST( 0.33, 16 ) ) ), psEnc->sCmn.subfr_length );
for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {
/* Soft limit on ratio residual energy and squared gains */
ResNrg = psEncCtrl->ResNrg[ k ];
ResNrgPart = silk_SMULWW( ResNrg, InvMaxSqrVal_Q16 );
if( psEncCtrl->ResNrgQ[ k ] > 0 ) {
ResNrgPart = silk_RSHIFT_ROUND( ResNrgPart, psEncCtrl->ResNrgQ[ k ] );
} else {
if( ResNrgPart >= silk_RSHIFT( silk_int32_MAX, -psEncCtrl->ResNrgQ[ k ] ) ) {
ResNrgPart = silk_int32_MAX;
} else {
ResNrgPart = silk_LSHIFT( ResNrgPart, -psEncCtrl->ResNrgQ[ k ] );
}
}
gain = psEncCtrl->Gains_Q16[ k ];
gain_squared = silk_ADD_SAT32( ResNrgPart, silk_SMMUL( gain, gain ) );
if( gain_squared < silk_int16_MAX ) {
/* recalculate with higher precision */
gain_squared = silk_SMLAWW( silk_LSHIFT( ResNrgPart, 16 ), gain, gain );
silk_assert( gain_squared > 0 );
gain = silk_SQRT_APPROX( gain_squared ); /* Q8 */
gain = silk_min( gain, silk_int32_MAX >> 8 );
psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32( gain, 8 ); /* Q16 */
} else {
示例13: silk_LPC_fit
/* Convert int32 coefficients to int16 coefs and make sure there's no wrap-around */
void silk_LPC_fit(
opus_int16 *a_QOUT, /* O Output signal */
opus_int32 *a_QIN, /* I/O Input signal */
const opus_int QOUT, /* I Input Q domain */
const opus_int QIN, /* I Input Q domain */
const opus_int d /* I Filter order */
)
{
opus_int i, k, idx = 0;
opus_int32 maxabs, absval, chirp_Q16;
/* Limit the maximum absolute value of the prediction coefficients, so that they'll fit in int16 */
for( i = 0; i < 10; i++ ) {
/* Find maximum absolute value and its index */
maxabs = 0;
for( k = 0; k < d; k++ ) {
absval = silk_abs( a_QIN[k] );
if( absval > maxabs ) {
maxabs = absval;
idx = k;
}
}
maxabs = silk_RSHIFT_ROUND( maxabs, QIN - QOUT );
if( maxabs > silk_int16_MAX ) {
/* Reduce magnitude of prediction coefficients */
maxabs = silk_min( maxabs, 163838 ); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */
chirp_Q16 = SILK_FIX_CONST( 0.999, 16 ) - silk_DIV32( silk_LSHIFT( maxabs - silk_int16_MAX, 14 ),
silk_RSHIFT32( silk_MUL( maxabs, idx + 1), 2 ) );
silk_bwexpander_32( a_QIN, d, chirp_Q16 );
} else {
break;
}
}
if( i == 10 ) {
/* Reached the last iteration, clip the coefficients */
for( k = 0; k < d; k++ ) {
a_QOUT[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( a_QIN[ k ], QIN - QOUT ) );
a_QIN[ k ] = silk_LSHIFT( (opus_int32)a_QOUT[ k ], QIN - QOUT );
}
} else {
for( k = 0; k < d; k++ ) {
a_QOUT[ k ] = (opus_int16)silk_RSHIFT_ROUND( a_QIN[ k ], QIN - QOUT );
}
}
}
示例14: silk_PLC_Reset
void silk_PLC_Reset(
silk_decoder_state *psDec /* I/O Decoder state */
)
{
psDec->sPLC.pitchL_Q8 = silk_LSHIFT( psDec->frame_length, 8 - 1 );
psDec->sPLC.prevGain_Q16[ 0 ] = SILK_FIX_CONST( 1, 16 );
psDec->sPLC.prevGain_Q16[ 1 ] = SILK_FIX_CONST( 1, 16 );
psDec->sPLC.subfr_length = 20;
psDec->sPLC.nb_subfr = 2;
}
示例15: silk_k2a
/* Step up function, converts reflection coefficients to prediction coefficients */
void silk_k2a(
opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */
const opus_int16 *rc_Q15, /* I Reflection coefficients [order] Q15 */
const opus_int32 order /* I Prediction order */
)
{
opus_int k, n;
opus_int32 Atmp[ SILK_MAX_ORDER_LPC ];
for( k = 0; k < order; k++ ) {
for( n = 0; n < k; n++ ) {
Atmp[ n ] = A_Q24[ n ];
}
for( n = 0; n < k; n++ ) {
A_Q24[ n ] = silk_SMLAWB( A_Q24[ n ], silk_LSHIFT( Atmp[ k - n - 1 ], 1 ), rc_Q15[ k ] );
}
A_Q24[ k ] = -silk_LSHIFT( (opus_int32)rc_Q15[ k ], 9 );
}
}