From 01defb36f64d84d5ffb80ad4dcce37f486d2e93e Mon Sep 17 00:00:00 2001 From: jbuethe Date: Wed, 15 Feb 2023 12:43:03 +0000 Subject: added feature extraction --- silk/decode_core.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ silk/decode_parameters.c | 4 ++++ src/opus_demo.c | 2 ++ 3 files changed, 50 insertions(+) diff --git a/silk/decode_core.c b/silk/decode_core.c index 1c352a65..a2288b67 100644 --- a/silk/decode_core.c +++ b/silk/decode_core.c @@ -29,6 +29,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "config.h" #endif +#define FEATURES +#ifdef FEATURES +#include +#endif + #include "main.h" #include "stack_alloc.h" @@ -43,6 +48,17 @@ void silk_decode_core( int arch /* I Run-time architecture */ ) { + +#ifdef FEATURES + static FILE *flpc = NULL; + static FILE *fgain = NULL; + static FILE *fltp = NULL; + + if (flpc == NULL) {flpc = fopen("features_lpc.f32", "wb");} + if (fgain == NULL) {fgain = fopen("features_gain.f32", "wb");} + if (fltp == NULL) {fltp = fopen("features_ltp.f32", "wb");} + +#endif opus_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType; opus_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ]; VARDECL( opus_int16, sLTP ); @@ -106,6 +122,34 @@ void silk_decode_core( Gain_Q10 = silk_RSHIFT( psDecCtrl->Gains_Q16[ k ], 6 ); inv_gain_Q31 = silk_INVERSE32_varQ( psDecCtrl->Gains_Q16[ k ], 47 ); +#ifdef FEATURES + { + float tmp; + + /* gain */ + tmp = (float) psDecCtrl->Gains_Q16[k] / (1UL << 16); + fwrite(&tmp, sizeof(tmp), 1, fgain); + + /* LPC */ + if (k % 2 == 0) + { + for (i = 0; i < psDec->LPC_order; i++) + { + tmp = (float) A_Q12[i] / (1U << 12); + fwrite(&tmp, sizeof(tmp), 1, flpc); + } + } + + /* LTP */ + for (i = 0; i < 5; i++) + { + tmp = (float) B_Q14[i] / (1U << 14); + fwrite(&tmp, sizeof(tmp), 1, fltp); + } + + } +#endif + /* Calculate gain adjustment factor */ if( psDecCtrl->Gains_Q16[ k ] != psDec->prev_gain_Q16 ) { gain_adj_Q16 = silk_DIV32_varQ( psDec->prev_gain_Q16, psDecCtrl->Gains_Q16[ k ], 16 ); diff --git a/silk/decode_parameters.c b/silk/decode_parameters.c index a56a4098..76f4fd9a 100644 --- a/silk/decode_parameters.c +++ b/silk/decode_parameters.c @@ -46,6 +46,8 @@ void silk_decode_parameters( silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->indices.GainsIndices, &psDec->LastGainIndex, condCoding == CODE_CONDITIONALLY, psDec->nb_subfr ); + // FEATURES: gain + /****************/ /* Decode NLSFs */ /****************/ @@ -54,6 +56,8 @@ void silk_decode_parameters( /* Convert NLSF parameters to AR prediction filter coefficients */ silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order, psDec->arch ); + // FEATURES: LPC on 20ms frame + /* If just reset, e.g., because internal Fs changed, do not allow interpolation */ /* improves the case of packet loss in the first frame after a switch */ if( psDec->first_frame_after_reset == 1 ) { diff --git a/src/opus_demo.c b/src/opus_demo.c index 4cc26a6c..d79a46c0 100644 --- a/src/opus_demo.c +++ b/src/opus_demo.c @@ -265,6 +265,8 @@ int main(int argc, char *argv[]) int delayed_decision=0; int ret = EXIT_FAILURE; + OPUS_SET_FORCE_MODE(MODE_SILK_ONLY); + if (argc < 5 ) { print_usage( argv ); -- cgit v1.2.1