Example #1
0
int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
  return WebRtcNs_set_policy_core((NoiseSuppressionC*)NS_inst, mode);
}
Example #2
0
// Initialize state
int WebRtcNs_InitCore(NSinst_t* inst, WebRtc_UWord32 fs) {
  int i;
  //We only support 10ms frames

  //check for valid pointer
  if (inst == NULL) {
    return -1;
  }

  // Initialization of struct
  if (fs == 8000 || fs == 16000 || fs == 32000) {
    inst->fs = fs;
  } else {
    return -1;
  }
  inst->windShift = 0;
  if (fs == 8000) {
    // We only support 10ms frames
    inst->blockLen = 80;
    inst->blockLen10ms = 80;
    inst->anaLen = 128;
    inst->window = kBlocks80w128;
    inst->outLen = 0;
  } else if (fs == 16000) {
    // We only support 10ms frames
    inst->blockLen = 160;
    inst->blockLen10ms = 160;
    inst->anaLen = 256;
    inst->window = kBlocks160w256;
    inst->outLen = 0;
  } else if (fs == 32000) {
    // We only support 10ms frames
    inst->blockLen = 160;
    inst->blockLen10ms = 160;
    inst->anaLen = 256;
    inst->window = kBlocks160w256;
    inst->outLen = 0;
  }
  inst->magnLen = inst->anaLen / 2 + 1; // Number of frequency bins

  // Initialize fft work arrays.
  inst->ip[0] = 0; // Setting this triggers initialization.
  memset(inst->dataBuf, 0, sizeof(float) * ANAL_BLOCKL_MAX);
  WebRtc_rdft(inst->anaLen, 1, inst->dataBuf, inst->ip, inst->wfft);

  memset(inst->dataBuf, 0, sizeof(float) * ANAL_BLOCKL_MAX);
  memset(inst->syntBuf, 0, sizeof(float) * ANAL_BLOCKL_MAX);

  //for HB processing
  memset(inst->dataBufHB, 0, sizeof(float) * ANAL_BLOCKL_MAX);

  //for quantile noise estimation
  memset(inst->quantile, 0, sizeof(float) * HALF_ANAL_BLOCKL);
  for (i = 0; i < SIMULT * HALF_ANAL_BLOCKL; i++) {
    inst->lquantile[i] = (float)8.0;
    inst->density[i] = (float)0.3;
  }

  for (i = 0; i < SIMULT; i++) {
    inst->counter[i] = (int)floor((float)(END_STARTUP_LONG * (i + 1)) / (float)SIMULT);
  }

  inst->updates = 0;

  // Wiener filter initialization
  for (i = 0; i < HALF_ANAL_BLOCKL; i++) {
    inst->smooth[i] = (float)1.0;
  }

  // Set the aggressiveness: default
  inst->aggrMode = 0;

  //initialize variables for new method
  inst->priorSpeechProb = (float)0.5; //prior prob for speech/noise
  for (i = 0; i < HALF_ANAL_BLOCKL; i++) {
    inst->magnPrev[i]      = (float)0.0; //previous mag spectrum
    inst->noisePrev[i]     = (float)0.0; //previous noise-spectrum
    inst->logLrtTimeAvg[i] = LRT_FEATURE_THR; //smooth LR ratio (same as threshold)
    inst->magnAvgPause[i]  = (float)0.0; //conservative noise spectrum estimate
    inst->speechProbHB[i]  = (float)0.0; //for estimation of HB in second pass
    inst->initMagnEst[i]   = (float)0.0; //initial average mag spectrum
  }

  //feature quantities
  inst->featureData[0] = SF_FEATURE_THR;  //spectral flatness (start on threshold)
  inst->featureData[1] = (float)0.0;      //spectral entropy: not used in this version
  inst->featureData[2] = (float)0.0;      //spectral variance: not used in this version
  inst->featureData[3] = LRT_FEATURE_THR; //average lrt factor (start on threshold)
  inst->featureData[4] = SF_FEATURE_THR;  //spectral template diff (start on threshold)
  inst->featureData[5] = (float)0.0;      //normalization for spectral-diff
  inst->featureData[6] = (float)0.0;      //window time-average of input magnitude spectrum

  //histogram quantities: used to estimate/update thresholds for features
  for (i = 0; i < HIST_PAR_EST; i++) {
    inst->histLrt[i] = 0;
    inst->histSpecFlat[i] = 0;
    inst->histSpecDiff[i] = 0;
  }

  inst->blockInd = -1; //frame counter
  inst->priorModelPars[0] = LRT_FEATURE_THR; //default threshold for lrt feature
  inst->priorModelPars[1] = (float)0.5;      //threshold for spectral flatness:
  // determined on-line
  inst->priorModelPars[2] = (float)1.0;      //sgn_map par for spectral measure:
  // 1 for flatness measure
  inst->priorModelPars[3] = (float)0.5;      //threshold for template-difference feature:
  // determined on-line
  inst->priorModelPars[4] = (float)1.0;      //default weighting parameter for lrt feature
  inst->priorModelPars[5] = (float)0.0;      //default weighting parameter for
  // spectral flatness feature
  inst->priorModelPars[6] = (float)0.0;      //default weighting parameter for
  // spectral difference feature

  inst->modelUpdatePars[0] = 2;   //update flag for parameters:
  // 0 no update, 1=update once, 2=update every window
  inst->modelUpdatePars[1] = 500; //window for update
  inst->modelUpdatePars[2] = 0;   //counter for update of conservative noise spectrum
  //counter if the feature thresholds are updated during the sequence
  inst->modelUpdatePars[3] = inst->modelUpdatePars[1];

  inst->signalEnergy = 0.0;
  inst->sumMagn = 0.0;
  inst->whiteNoiseLevel = 0.0;
  inst->pinkNoiseNumerator = 0.0;
  inst->pinkNoiseExp = 0.0;

  WebRtcNs_set_feature_extraction_parameters(inst); // Set feature configuration

  //default mode
  WebRtcNs_set_policy_core(inst, 0);


  memset(inst->outBuf, 0, sizeof(float) * 3 * BLOCKL_MAX);

  inst->initFlag = 1;
  return 0;
}
Example #3
0
int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
  return WebRtcNs_set_policy_core((NSinst_t*) NS_inst, mode);
}