int WebRtc_CreateDelayEstimator(void** handle,
                                int spectrum_size,
                                int max_delay,
                                int lookahead) {
  DelayEstimator_t *self = NULL;

  // Check if the sub band used in the delay estimation is small enough to
  // fit the binary spectra in a uint32.
  assert(kBandLast - kBandFirst < 32);

  if (handle == NULL) {
    return -1;
  }
  if (spectrum_size < kBandLast) {
    return -1;
  }

  self = malloc(sizeof(DelayEstimator_t));
  *handle = self;
  if (self == NULL) {
    return -1;
  }

  self->mean_far_spectrum = NULL;
  self->mean_near_spectrum = NULL;

  // Create binary delay estimator.
  if (WebRtc_CreateBinaryDelayEstimator(&self->binary_handle,
                                        max_delay,
                                        lookahead) != 0) {
    WebRtc_FreeDelayEstimator(self);
    self = NULL;
    return -1;
  }
  // Allocate memory for spectrum buffers
  self->mean_far_spectrum = malloc(spectrum_size * sizeof(SpectrumType_t));
  if (self->mean_far_spectrum == NULL) {
    WebRtc_FreeDelayEstimator(self);
    self = NULL;
    return -1;
  }
  self->mean_near_spectrum = malloc(spectrum_size * sizeof(SpectrumType_t));
  if (self->mean_near_spectrum == NULL) {
    WebRtc_FreeDelayEstimator(self);
    self = NULL;
    return -1;
  }

  self->spectrum_size = spectrum_size;

  return 0;
}
示例#2
0
int WebRtcAec_FreeAec(aec_t *aec)
{
    if (aec == NULL) {
        return -1;
    }

    WebRtc_FreeBuffer(aec->nearFrBuf);
    WebRtc_FreeBuffer(aec->outFrBuf);

    WebRtc_FreeBuffer(aec->nearFrBufH);
    WebRtc_FreeBuffer(aec->outFrBufH);

    WebRtc_FreeBuffer(aec->far_buf);
    WebRtc_FreeBuffer(aec->far_buf_windowed);
#ifdef WEBRTC_AEC_DEBUG_DUMP
    WebRtc_FreeBuffer(aec->far_time_buf);
#endif
    WebRtc_FreeDelayEstimator(aec->delay_estimator);

    free(aec);
    return 0;
}