/* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate */ static OPUS_INLINE void silk_LBRR_encode_FLP(
silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ const silk_float xfw[], /* I Input signal */
opus_int condCoding /* I The type of conditional coding used so far for this frame */
);
void silk_encode_do_VAD_FLP(
silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
opus_int activity /* I Decision of Opus voice activity detector */
)
{ const opus_int activity_threshold = SILK_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 );
/****************************/ /* Voice Activity Detection */ /****************************/
silk_VAD_GetSA_Q8( &psEnc->sCmn, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.arch ); /* If Opus VAD is inactive and Silk VAD is active: lower Silk VAD to just under the threshold */ if( activity == VAD_NO_ACTIVITY && psEnc->sCmn.speech_activity_Q8 >= activity_threshold ) {
psEnc->sCmn.speech_activity_Q8 = activity_threshold - 1;
}
/****************/ /* Encode frame */ /****************/
opus_int silk_encode_frame_FLP(
silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
opus_int32 *pnBytesOut, /* O Number of payload bytes; */
ec_enc *psRangeEnc, /* I/O compressor data structure */
opus_int condCoding, /* I The type of conditional coding to use */
opus_int maxBits, /* I If > 0: maximum number of output bits */
opus_int useCBR /* I Flag to force constant-bitrate operation */
)
{
silk_encoder_control_FLP sEncCtrl;
opus_int i, iter, maxIter, found_upper, found_lower, ret = 0;
silk_float *x_frame, *res_pitch_frame;
silk_float res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];
ec_enc sRangeEnc_copy, sRangeEnc_copy2;
VARDECL(silk_nsq_state, sNSQ_copy);
opus_int32 seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gainMult_upper;
opus_int32 gainsID, gainsID_lower, gainsID_upper;
opus_int16 gainMult_Q8;
opus_int16 ec_prevLagIndex_copy;
opus_int ec_prevSignalType_copy;
opus_int8 LastGainIndex_copy2;
opus_int32 pGains_Q16[ MAX_NB_SUBFR ];
opus_int gain_lock[ MAX_NB_SUBFR ] = {0};
opus_int16 best_gain_mult[ MAX_NB_SUBFR ];
opus_int best_sum[ MAX_NB_SUBFR ];
opus_int bits_margin;
SAVE_STACK;
/* Using ALLOC() instead of a regular stack allocation to minimize real stack use when using the pseudostack.
This is useful on some embedded systems. */
ALLOC(sNSQ_copy, 2, silk_nsq_state);
/* For CBR, 5 bits below budget is close enough. For VBR, allow up to 25% below the cap if we initially busted the budget. */
bits_margin = useCBR ? 5 : maxBits/4; /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */
LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_upper = 0;
/**************************************************************/ /* Set up Input Pointers, and insert frame in input buffer */ /**************************************************************/ /* pointers aligned with start of frame to encode */
x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; /* start of frame to encode */
res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; /* start of pitch LPC residual frame */
/*******************************************/ /* Copy new frame to front of input buffer */ /*******************************************/
silk_short2float_array( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length );
/* Add tiny signal to avoid high CPU load from denormalized floating point numbers */ for( i = 0; i < 8; i++ ) {
x_frame[ LA_SHAPE_MS * psEnc->sCmn.fs_kHz + i * ( psEnc->sCmn.frame_length >> 3 ) ] += ( 1 - ( i & 2) ) * 1e-6f;
}
/* If we still bust after the last iteration, do some damage control. */ if ( iter == maxIter && !found_lower && nBits > maxBits ) {
silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) );
/* Keep gains the same as the last frame. */
psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
psEnc->sCmn.indices.GainsIndices[ i ] = 4;
} if (condCoding != CODE_CONDITIONALLY) {
psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGainIndexPrev;
}
psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy;
psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; /* Clear all pulses. */ for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) {
psEnc->sCmn.pulses[ i ] = 0;
}
/* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
sEncCtrl.Gains[ i ] = pGains_Q16[ i ] / 65536.0f;
}
}
}
/* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate */ static OPUS_INLINE void silk_LBRR_encode_FLP(
silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ const silk_float xfw[], /* I Input signal */
opus_int condCoding /* I The type of conditional coding used so far for this frame */
)
{
opus_int k;
opus_int32 Gains_Q16[ MAX_NB_SUBFR ];
silk_float TempGains[ MAX_NB_SUBFR ];
SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFramesEncoded ];
VARDECL(silk_nsq_state, sNSQ_LBRR);
SAVE_STACK;
/*******************************************/ /* Control use of inband LBRR */ /*******************************************/ if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.speech_activity_Q8 > SILK_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) { /* Using ALLOC() instead of a regular stack allocation to minimize real stack use when using the pseudostack.
This is useful on some embedded systems. */
ALLOC(sNSQ_LBRR, 1, silk_nsq_state);
/* Decode to get gains in sync with decoder */
silk_gains_dequant( Gains_Q16, psIndices_LBRR->GainsIndices,
&psEnc->sCmn.LBRRprevLastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr );
/* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {
psEncCtrl->Gains[ k ] = Gains_Q16[ k ] * ( 1.0f / 65536.0f );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.