Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# VNR

## VNR API Functions

group VNR API functions

  Functions

  void vnr_state_init(vnr_state_t *vnr)

    Initialise the VNR state.

    This function should be called once at device startup.

    Parameters:

      - vnr – [inout] pointer to the VNR state structure

  void vnr_process_frame(
    vnr_state_t *vnr,
    float_s32_t *output,
    int32_t input[VNR_FRAME_ADVANCE],
  )

    Calculate the Voice to Noise Ratio estimation from a frame of input data.

    This function takes a frame of new samples, converts them to features and passes those to the inference engine. The VNR output is a single value ranging between 0 and 1 returned in float_s32_t format, with 0 being the lowest SNR and 1 being the strongest possible SNR in speech compared to noise.

    Parameters:

      - vnr – [inout] VNR state structure

      - output – [out] Pointer to return the resulting ratio

      - input – [in] Array of frame data on which to perform the VNR

group VNR feature extraction API functions

  Functions

  void vnr_input_state_init(vnr_input_state_t *input_state)

    Initialise previous frame samples buffer that is used when creating an input frame for processing through the VNR estimator.

    This function should be called once at device startup.

    Parameters:

      - input_state – [inout] pointer to the VNR input state structure

  void vnr_form_input_frame(
    vnr_input_state_t *input_state,
    bfp_complex_s32_t *X,
    complex_s32_t X_data[VNR_FD_FRAME_LENGTH],
    const int32_t new_x_frame[VNR_FRAME_ADVANCE],
  )

    Create the input frame for processing through the VNR estimator.

    This function takes in VNR_FRAME_ADVANCE new samples, combines them with previous frame’s samples to form a VNR_PROC_FRAME_LENGTH samples input frame of time domain data, and outputs the DFT spectrum of the input frame. The DFT spectrum is output in the BFP structure and data memory provided by the user.

    The frequency spectrum output from this function is processed through the VNR feature extraction stage.

    If sharing the DFT spectrum calculated in some other module, vnr_form_input_frame() is not needed.

    Example

          #include "vnr_features_api.h"
          complex_s32_t DWORD_ALIGNED input_frame[VNR_FD_FRAME_LENGTH];
          bfp_complex_s32_t X;
          vnr_form_input_frame(&vnr_input_state, &X, input_frame, new_data);

    Parameters:

      - input_state – [inout] pointer to the VNR input state structure

      - X – [out] pointer to a variable of type bfp_complex_s32_t that the user allocates. The user doesn’t need to initialise this bfp variable. After this function, X is updated to point to the DFT output spectrum and can be passed as input to the feature extraction stage.

      - X_data – [out] pointer to VNR_FD_FRAME_LENGTH values of type complex_s32_t that the user allocates. After this function, the DFT spectrum values are written to this array, and `X->data` points to X_data memory.

      - new_x_frame – [in] Pointer to VNR_FRAME_ADVANCE new time domain samples

  void vnr_feature_state_init(vnr_feature_state_t *feature_state)

    Initialise the state structure for the VNR feature extraction stage.

    This function is called once at device startup.

    Parameters:

      - feature_state – [inout] pointer to the VNR feature extraction state structure

  void vnr_extract_features(
    vnr_feature_state_t *vnr_feature_state,
    bfp_s32_t *feature_patch,
    int32_t feature_patch_data[VNR_PATCH_WIDTH * VNR_MEL_FILTERS],
    const bfp_complex_s32_t *X,
  )

    Extract features.

    This function takes in DFT spectrum of the VNR input frame and does the feature extraction. The features are written to the feature_patch BFP structure and feature_patch_data memory provided by the user. The feature output from this function are passed as input to the VNR inference engine.

    Parameters:

      - vnr_feature_state – [inout] Pointer to the VNR feature extraction state structure

      - feature_patch – [out] Pointer to the bfp_s32_t structure allocated by the user. The user doesn’t need to initialise this BFP structure before passing it to this function. After this function call feature_patch will be updated and will point to the extracted features. It can then be passed to the inference stage.

      - feature_patch_data – [out] Pointer to the VNR_PATCH_WIDTH * VNR_MEL_FILTERS int32_t values allocated by the user. The extracted features will be written to the feature_patch_data array and the BFP structure’s `feature_patch->data` will point to this array.

group VNR inference API functions

  Functions

  int32_t vnr_inference_init()

    Initialise the inference_engine object and load the VNR model into the inference engine.

    This function calls lib_tflite_micro functions to initialise the inference engine and load the VNR model into it. It is called once at startup. The memory required for the inference engine object as well as the tensor arena size required for inference is statically allocated as global buffers in the VNR module. The VNR model is compiled as part of the VNR module.

  void vnr_inference(float_s32_t *vnr_output, bfp_s32_t *features)

    Run model prediction on a feature patch.

    This function invokes the inference engine. It takes in a set of features corresponding to an input frame of data and outputs the VNR prediction value. The VNR output is a single value ranging between 0 and 1 returned in float_s32_t format, with 0 being the lowest SNR and 1 being the strongest possible SNR in speech compared to noise.

    Parameters:

      - vnr_output – [out] VNR prediction value.

      - features – [in] Input feature vector. Note that this is not passed as a const pointer and the feature memory is overwritten as part of the inference computation.

## VNR Defines

group VNR #define constants common to both feature extraction and inference

  Defines

  VNR_PROC_FRAME_LENGTH

    Time domain samples block length used internally in VNR DFT computation. NOT USER MODIFIABLE.

  VNR_FRAME_ADVANCE

    VNR new samples frame size This is the number of samples of new data that the VNR processes every frame. 240 samples at 16kHz is 15msec. NOT USER MODIFIABLE.

  VNR_FD_FRAME_LENGTH

    Number of bins of spectrum data computed when doing a DFT of a VNR_PROC_FRAME_LENGTH length time domain vector. The VNR_FD_FRAME_LENGTH spectrum values represent the bins from DC to Nyquist. NOT USER MODIFIABLE.

  VNR_MEL_FILTERS

    Number of filters in the MEL filterbank used in the VNR feature extraction.

  VNR_PATCH_WIDTH

    Number of frames that make up a full set of features for the inference to run on.

## VNR Data structures and Enums

group VNR data structure definitions
  struct vnr_input_state_t
    #include <vnr_state.h>

    VNR form_input state structure.

    Public Members

    int32_t prev_input_samples[VNR_PROC_FRAME_LENGTH - VNR_FRAME_ADVANCE]

      Previous frame time domain input samples which are combined with VNR_FRAME_ADVANCE new samples to form the VNR input frame.

  struct vnr_feature_config_t
    #include <vnr_state.h>

    VNR feature extraction config structure.

    Public Members

    int32_t enable_highpass

      Enable highpass filtering of VNR MEL filter output. Disabled by default

  struct vnr_feature_state_t
    #include <vnr_state.h>

    State structure used in VNR feature extraction.

    Public Members

    int32_t feature_buffers[VNR_PATCH_WIDTH][VNR_MEL_FILTERS]

      Feature buffer containing the most recent VNR_MEL_FILTERS frames’ MEL frequency spectrum.

  struct vnr_state_t
    #include <vnr_state.h>

    State structure used for the VNR.

    Public Members

    vnr_input_state_t input_state

      VNR Input state

    vnr_feature_state_t feature_state

      VNR Feature state