int32_t WebRtcAec_Create(void **aecInst) { aecpc_t *aecpc; if (aecInst == NULL) { return -1; } aecpc = malloc(sizeof(aecpc_t)); *aecInst = aecpc; if (aecpc == NULL) { return -1; } if (WebRtcAec_CreateAec(&aecpc->aec) == -1) { WebRtcAec_Free(aecpc); aecpc = NULL; return -1; } if (WebRtcAec_CreateResampler(&aecpc->resampler) == -1) { WebRtcAec_Free(aecpc); aecpc = NULL; return -1; } // Create far-end pre-buffer. The buffer size has to be large enough for // largest possible drift compensation (kResamplerBufferSize) + "almost" an // FFT buffer (PART_LEN2 - 1). aecpc->far_pre_buf = WebRtc_CreateBuffer(PART_LEN2 + kResamplerBufferSize, sizeof(float)); if (!aecpc->far_pre_buf) { WebRtcAec_Free(aecpc); aecpc = NULL; return -1; } aecpc->initFlag = 0; aecpc->lastError = 0; #ifdef WEBRTC_AEC_DEBUG_DUMP aecpc->far_pre_buf_s16 = WebRtc_CreateBuffer( PART_LEN2 + kResamplerBufferSize, sizeof(int16_t)); if (!aecpc->far_pre_buf_s16) { WebRtcAec_Free(aecpc); aecpc = NULL; return -1; } { char filename[64]; sprintf(filename, "aec_buf%d.dat", webrtc_aec_instance_count); aecpc->bufFile = fopen(filename, "wb"); sprintf(filename, "aec_skew%d.dat", webrtc_aec_instance_count); aecpc->skewFile = fopen(filename, "wb"); sprintf(filename, "aec_delay%d.dat", webrtc_aec_instance_count); aecpc->delayFile = fopen(filename, "wb"); webrtc_aec_instance_count++; } #endif return 0; }
void* WebRtcAec_Create() { Aec* aecpc = malloc(sizeof(Aec)); if (!aecpc) { return NULL; } aecpc->aec = WebRtcAec_CreateAec(); if (!aecpc->aec) { WebRtcAec_Free(aecpc); return NULL; } aecpc->resampler = WebRtcAec_CreateResampler(); if (!aecpc->resampler) { WebRtcAec_Free(aecpc); return NULL; } // Create far-end pre-buffer. The buffer size has to be large enough for // largest possible drift compensation (kResamplerBufferSize) + "almost" an // FFT buffer (PART_LEN2 - 1). aecpc->far_pre_buf = WebRtc_CreateBuffer(PART_LEN2 + kResamplerBufferSize, sizeof(float)); if (!aecpc->far_pre_buf) { WebRtcAec_Free(aecpc); return NULL; } aecpc->initFlag = 0; #ifdef WEBRTC_AEC_DEBUG_DUMP aecpc->bufFile = aecpc->skewFile = aecpc->delayFile = NULL; OpenDebugFiles(aecpc, &webrtc_aec_instance_count); #endif return aecpc; }
int WebRtcAec_CreateAec(aec_t **aecInst) { aec_t *aec = malloc(sizeof(aec_t)); *aecInst = aec; if (aec == NULL) { return -1; } if (WebRtc_CreateBuffer(&aec->nearFrBuf, FRAME_LEN + PART_LEN, sizeof(int16_t)) == -1) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } if (WebRtc_CreateBuffer(&aec->outFrBuf, FRAME_LEN + PART_LEN, sizeof(int16_t)) == -1) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } if (WebRtc_CreateBuffer(&aec->nearFrBufH, FRAME_LEN + PART_LEN, sizeof(int16_t)) == -1) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } if (WebRtc_CreateBuffer(&aec->outFrBufH, FRAME_LEN + PART_LEN, sizeof(int16_t)) == -1) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } // Create far-end buffers. if (WebRtc_CreateBuffer(&aec->far_buf, kBufSizePartitions, sizeof(float) * 2 * PART_LEN1) == -1) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } if (WebRtc_CreateBuffer(&aec->far_buf_windowed, kBufSizePartitions, sizeof(float) * 2 * PART_LEN1) == -1) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } #ifdef WEBRTC_AEC_DEBUG_DUMP if (WebRtc_CreateBuffer(&aec->far_time_buf, kBufSizePartitions, sizeof(int16_t) * PART_LEN) == -1) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } #endif aec->delay_estimator = WebRtc_CreateDelayEstimator(PART_LEN1, kMaxDelayBlocks, kLookaheadBlocks); if (aec->delay_estimator == NULL) { WebRtcAec_FreeAec(aec); aec = NULL; return -1; } return 0; }