Replace calls to assert() with RTC_DCHECK_*() in .c code
We have RTC_CHECK and RTC_DCHECK for C now, so we should use it. It's one fewer difference between our C and C++ code. NOPRESUBMIT=true Review-Url: https://codereview.webrtc.org/2274083002 Cr-Commit-Position: refs/heads/master@{#13930}
This commit is contained in:
@ -8,11 +8,11 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/common_audio/fft4g.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "webrtc/modules/audio_processing/ns/noise_suppression.h"
|
||||
@ -857,7 +857,7 @@ static void UpdateBuffer(const float* frame,
|
||||
size_t frame_length,
|
||||
size_t buffer_length,
|
||||
float* buffer) {
|
||||
assert(buffer_length < 2 * frame_length);
|
||||
RTC_DCHECK_LT(buffer_length, 2 * frame_length);
|
||||
|
||||
memcpy(buffer,
|
||||
buffer + frame_length,
|
||||
@ -893,7 +893,7 @@ static void FFT(NoiseSuppressionC* self,
|
||||
float* magn) {
|
||||
size_t i;
|
||||
|
||||
assert(magnitude_length == time_data_length / 2 + 1);
|
||||
RTC_DCHECK_EQ(magnitude_length, time_data_length / 2 + 1);
|
||||
|
||||
WebRtc_rdft(time_data_length, 1, time_data, self->ip, self->wfft);
|
||||
|
||||
@ -929,7 +929,7 @@ static void IFFT(NoiseSuppressionC* self,
|
||||
float* time_data) {
|
||||
size_t i;
|
||||
|
||||
assert(time_data_length == 2 * (magnitude_length - 1));
|
||||
RTC_DCHECK_EQ(time_data_length, 2 * (magnitude_length - 1));
|
||||
|
||||
time_data[0] = real[0];
|
||||
time_data[1] = real[magnitude_length - 1];
|
||||
@ -1062,7 +1062,7 @@ void WebRtcNs_AnalyzeCore(NoiseSuppressionC* self, const float* speechFrame) {
|
||||
float parametric_num = 0.0;
|
||||
|
||||
// Check that initiation has been done.
|
||||
assert(self->initFlag == 1);
|
||||
RTC_DCHECK_EQ(1, self->initFlag);
|
||||
updateParsFlag = self->modelUpdatePars[0];
|
||||
|
||||
// Update analysis buffer for L band.
|
||||
@ -1206,8 +1206,8 @@ void WebRtcNs_ProcessCore(NoiseSuppressionC* self,
|
||||
float sumMagnAnalyze, sumMagnProcess;
|
||||
|
||||
// Check that initiation has been done.
|
||||
assert(self->initFlag == 1);
|
||||
assert((num_bands - 1) <= NUM_HIGH_BANDS_MAX);
|
||||
RTC_DCHECK_EQ(1, self->initFlag);
|
||||
RTC_DCHECK_LE(num_bands - 1, NUM_HIGH_BANDS_MAX);
|
||||
|
||||
const float* const* speechFrameHB = NULL;
|
||||
float* const* outFrameHB = NULL;
|
||||
|
||||
@ -10,11 +10,11 @@
|
||||
|
||||
#include "webrtc/modules/audio_processing/ns/noise_suppression_x.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/real_fft.h"
|
||||
#include "webrtc/modules/audio_processing/ns/nsx_core.h"
|
||||
#include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
|
||||
@ -344,8 +344,8 @@ static void NoiseEstimationC(NoiseSuppressionFixedC* inst,
|
||||
size_t i, s, offset;
|
||||
|
||||
tabind = inst->stages - inst->normData;
|
||||
assert(tabind < 9);
|
||||
assert(tabind > -9);
|
||||
RTC_DCHECK_LT(tabind, 9);
|
||||
RTC_DCHECK_GT(tabind, -9);
|
||||
if (tabind < 0) {
|
||||
logval = -WebRtcNsx_kLogTable[-tabind];
|
||||
} else {
|
||||
@ -362,7 +362,7 @@ static void NoiseEstimationC(NoiseSuppressionFixedC* inst,
|
||||
frac = (int16_t)((((uint32_t)magn[i] << zeros)
|
||||
& 0x7FFFFFFF) >> 23);
|
||||
// log2(magn(i))
|
||||
assert(frac < 256);
|
||||
RTC_DCHECK_LT(frac, 256);
|
||||
log2 = (int16_t)(((31 - zeros) << 8)
|
||||
+ WebRtcNsx_kLogTableFrac[frac]);
|
||||
// log2(magn(i))*log(2)
|
||||
@ -380,7 +380,7 @@ static void NoiseEstimationC(NoiseSuppressionFixedC* inst,
|
||||
|
||||
// Get counter values from state
|
||||
counter = inst->noiseEstCounter[s];
|
||||
assert(counter < 201);
|
||||
RTC_DCHECK_LT(counter, 201);
|
||||
countDiv = WebRtcNsx_kCounterDiv[counter];
|
||||
countProd = (int16_t)(counter * countDiv);
|
||||
|
||||
@ -543,7 +543,7 @@ static void NormalizeRealBufferC(NoiseSuppressionFixedC* inst,
|
||||
const int16_t* in,
|
||||
int16_t* out) {
|
||||
size_t i = 0;
|
||||
assert(inst->normData >= 0);
|
||||
RTC_DCHECK_GE(inst->normData, 0);
|
||||
for (i = 0; i < inst->anaLen; ++i) {
|
||||
out[i] = in[i] << inst->normData; // Q(normData)
|
||||
}
|
||||
@ -594,8 +594,8 @@ void WebRtcNsx_CalcParametricNoiseEstimate(NoiseSuppressionFixedC* inst,
|
||||
|
||||
// Use pink noise estimate
|
||||
// noise_estimate = 2^(pinkNoiseNumerator + pinkNoiseExp * log2(j))
|
||||
assert(freq_index >= 0);
|
||||
assert(freq_index < 129);
|
||||
RTC_DCHECK_GE(freq_index, 0);
|
||||
RTC_DCHECK_LT(freq_index, 129);
|
||||
tmp32no2 = (pink_noise_exp_avg * kLogIndex[freq_index]) >> 15; // Q11
|
||||
tmp32no1 = pink_noise_num_avg - tmp32no2; // Q11
|
||||
|
||||
@ -1038,7 +1038,7 @@ void WebRtcNsx_ComputeSpectralFlatness(NoiseSuppressionFixedC* inst,
|
||||
frac = (int16_t)(((uint32_t)((uint32_t)(magn[i]) << zeros)
|
||||
& 0x7FFFFFFF) >> 23);
|
||||
// log2(magn(i))
|
||||
assert(frac < 256);
|
||||
RTC_DCHECK_LT(frac, 256);
|
||||
tmpU32 = (uint32_t)(((31 - zeros) << 8)
|
||||
+ WebRtcNsx_kLogTableFrac[frac]); // Q8
|
||||
avgSpectralFlatnessNum += tmpU32; // Q8
|
||||
@ -1053,7 +1053,7 @@ void WebRtcNsx_ComputeSpectralFlatness(NoiseSuppressionFixedC* inst,
|
||||
zeros = WebRtcSpl_NormU32(avgSpectralFlatnessDen);
|
||||
frac = (int16_t)(((avgSpectralFlatnessDen << zeros) & 0x7FFFFFFF) >> 23);
|
||||
// log2(avgSpectralFlatnessDen)
|
||||
assert(frac < 256);
|
||||
RTC_DCHECK_LT(frac, 256);
|
||||
tmp32 = (int32_t)(((31 - zeros) << 8) + WebRtcNsx_kLogTableFrac[frac]); // Q8
|
||||
logCurSpectralFlatness = (int32_t)avgSpectralFlatnessNum;
|
||||
logCurSpectralFlatness += ((int32_t)(inst->stages - 1) << (inst->stages + 7)); // Q(8+stages-1)
|
||||
@ -1286,7 +1286,7 @@ void WebRtcNsx_DataAnalysis(NoiseSuppressionFixedC* inst,
|
||||
frac = (int16_t)((((uint32_t)magnU16[inst->anaLen2] << zeros) &
|
||||
0x7FFFFFFF) >> 23); // Q8
|
||||
// log2(magnU16(i)) in Q8
|
||||
assert(frac < 256);
|
||||
RTC_DCHECK_LT(frac, 256);
|
||||
log2 = (int16_t)(((31 - zeros) << 8) + WebRtcNsx_kLogTableFrac[frac]);
|
||||
}
|
||||
|
||||
@ -1320,7 +1320,7 @@ void WebRtcNsx_DataAnalysis(NoiseSuppressionFixedC* inst,
|
||||
frac = (int16_t)((((uint32_t)magnU16[i] << zeros) &
|
||||
0x7FFFFFFF) >> 23);
|
||||
// log2(magnU16(i)) in Q8
|
||||
assert(frac < 256);
|
||||
RTC_DCHECK_LT(frac, 256);
|
||||
log2 = (int16_t)(((31 - zeros) << 8)
|
||||
+ WebRtcNsx_kLogTableFrac[frac]);
|
||||
}
|
||||
@ -1347,14 +1347,14 @@ void WebRtcNsx_DataAnalysis(NoiseSuppressionFixedC* inst,
|
||||
// Shift to same Q-domain as whiteNoiseLevel
|
||||
tmpU32no1 >>= right_shifts_in_magnU16;
|
||||
// This operation is safe from wrap around as long as END_STARTUP_SHORT < 128
|
||||
assert(END_STARTUP_SHORT < 128);
|
||||
RTC_DCHECK_LT(END_STARTUP_SHORT, 128);
|
||||
inst->whiteNoiseLevel += tmpU32no1; // Q(minNorm-stages)
|
||||
|
||||
// Estimate Pink noise parameters
|
||||
// Denominator used in both parameter estimates.
|
||||
// The value is only dependent on the size of the frequency band (kStartBand)
|
||||
// and to reduce computational complexity stored in a table (kDeterminantEstMatrix[])
|
||||
assert(kStartBand < 66);
|
||||
RTC_DCHECK_LT(kStartBand, 66);
|
||||
matrix_determinant = kDeterminantEstMatrix[kStartBand]; // Q0
|
||||
sum_log_i = kSumLogIndex[kStartBand]; // Q5
|
||||
sum_log_i_square = kSumSquareLogIndex[kStartBand]; // Q2
|
||||
@ -1469,13 +1469,13 @@ void WebRtcNsx_DataSynthesis(NoiseSuppressionFixedC* inst, short* outFrame) {
|
||||
inst->energyIn >>= 8 + scaleEnergyOut - inst->scaleEnergyIn;
|
||||
}
|
||||
|
||||
assert(inst->energyIn > 0);
|
||||
RTC_DCHECK_GT(inst->energyIn, 0);
|
||||
energyRatio = (energyOut + inst->energyIn / 2) / inst->energyIn; // Q8
|
||||
// Limit the ratio to [0, 1] in Q8, i.e., [0, 256]
|
||||
energyRatio = WEBRTC_SPL_SAT(256, energyRatio, 0);
|
||||
|
||||
// all done in lookup tables now
|
||||
assert(energyRatio < 257);
|
||||
RTC_DCHECK_LT(energyRatio, 257);
|
||||
gainFactor1 = kFactor1Table[energyRatio]; // Q8
|
||||
gainFactor2 = inst->factor2Table[energyRatio]; // Q8
|
||||
|
||||
@ -1534,24 +1534,24 @@ void WebRtcNsx_ProcessCore(NoiseSuppressionFixedC* inst,
|
||||
int q_domain_to_use = 0;
|
||||
|
||||
// Code for ARMv7-Neon platform assumes the following:
|
||||
assert(inst->anaLen > 0);
|
||||
assert(inst->anaLen2 > 0);
|
||||
assert(inst->anaLen % 16 == 0);
|
||||
assert(inst->anaLen2 % 8 == 0);
|
||||
assert(inst->blockLen10ms > 0);
|
||||
assert(inst->blockLen10ms % 16 == 0);
|
||||
assert(inst->magnLen == inst->anaLen2 + 1);
|
||||
RTC_DCHECK_GT(inst->anaLen, 0);
|
||||
RTC_DCHECK_GT(inst->anaLen2, 0);
|
||||
RTC_DCHECK_EQ(0, inst->anaLen % 16);
|
||||
RTC_DCHECK_EQ(0, inst->anaLen2 % 8);
|
||||
RTC_DCHECK_GT(inst->blockLen10ms, 0);
|
||||
RTC_DCHECK_EQ(0, inst->blockLen10ms % 16);
|
||||
RTC_DCHECK_EQ(inst->magnLen, inst->anaLen2 + 1);
|
||||
|
||||
#ifdef NS_FILEDEBUG
|
||||
if (fwrite(spframe, sizeof(short),
|
||||
inst->blockLen10ms, inst->infile) != inst->blockLen10ms) {
|
||||
assert(false);
|
||||
RTC_DCHECK(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check that initialization has been done
|
||||
assert(inst->initFlag == 1);
|
||||
assert((num_bands - 1) <= NUM_HIGH_BANDS_MAX);
|
||||
RTC_DCHECK_EQ(1, inst->initFlag);
|
||||
RTC_DCHECK_LE(num_bands - 1, NUM_HIGH_BANDS_MAX);
|
||||
|
||||
const short* const* speechFrameHB = NULL;
|
||||
short* const* outFrameHB = NULL;
|
||||
@ -1989,7 +1989,7 @@ void WebRtcNsx_ProcessCore(NoiseSuppressionFixedC* inst,
|
||||
|
||||
//gain filter
|
||||
tmpU32no1 = inst->overdrive + ((priorSnr + 8192) >> 14); // Q8
|
||||
assert(inst->overdrive > 0);
|
||||
RTC_DCHECK_GT(inst->overdrive, 0);
|
||||
tmpU16no1 = (priorSnr + tmpU32no1 / 2) / tmpU32no1; // Q14
|
||||
inst->noiseSupFilter[i] = WEBRTC_SPL_SAT(16384, tmpU16no1, inst->denoiseBound); // 16384 = Q14(1.0) // Q14
|
||||
|
||||
@ -2025,7 +2025,7 @@ void WebRtcNsx_ProcessCore(NoiseSuppressionFixedC* inst,
|
||||
#ifdef NS_FILEDEBUG
|
||||
if (fwrite(outframe, sizeof(short),
|
||||
inst->blockLen10ms, inst->outfile) != inst->blockLen10ms) {
|
||||
assert(false);
|
||||
RTC_DCHECK(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2052,7 +2052,7 @@ void WebRtcNsx_ProcessCore(NoiseSuppressionFixedC* inst,
|
||||
tmpU16no1 += nonSpeechProbFinal[i]; // Q8
|
||||
tmpU32no1 += (uint32_t)(inst->noiseSupFilter[i]); // Q14
|
||||
}
|
||||
assert(inst->stages >= 7);
|
||||
RTC_DCHECK_GE(inst->stages, 7);
|
||||
avgProbSpeechHB = (4096 - (tmpU16no1 >> (inst->stages - 7))); // Q12
|
||||
avgFilterGainHB = (int16_t)(tmpU32no1 >> (inst->stages - 3)); // Q14
|
||||
|
||||
|
||||
@ -8,8 +8,7 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/modules/audio_processing/ns/noise_suppression_x.h"
|
||||
#include "webrtc/modules/audio_processing/ns/nsx_core.h"
|
||||
#include "webrtc/modules/audio_processing/ns/nsx_defines.h"
|
||||
@ -149,7 +148,7 @@ void WebRtcNsx_SpeechNoiseProb(NoiseSuppressionFixedC* inst,
|
||||
if (inst->featureSpecDiff) {
|
||||
normTmp = WEBRTC_SPL_MIN(20 - inst->stages,
|
||||
WebRtcSpl_NormU32(inst->featureSpecDiff));
|
||||
assert(normTmp >= 0);
|
||||
RTC_DCHECK_GE(normTmp, 0);
|
||||
tmpU32no1 = inst->featureSpecDiff << normTmp; // Q(normTmp-2*stages)
|
||||
tmpU32no2 = inst->timeAvgMagnEnergy >> (20 - inst->stages - normTmp);
|
||||
if (tmpU32no2 > 0) {
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/modules/audio_processing/ns/noise_suppression_x.h"
|
||||
#include "webrtc/modules/audio_processing/ns/nsx_core.h"
|
||||
|
||||
@ -184,7 +184,7 @@ void WebRtcNsx_SpeechNoiseProb(NoiseSuppressionFixedC* inst,
|
||||
if (inst->featureSpecDiff) {
|
||||
normTmp = WEBRTC_SPL_MIN(20 - inst->stages,
|
||||
WebRtcSpl_NormU32(inst->featureSpecDiff));
|
||||
assert(normTmp >= 0);
|
||||
RTC_DCHECK_GE(normTmp, 0);
|
||||
tmpU32no1 = inst->featureSpecDiff << normTmp; // Q(normTmp-2*stages)
|
||||
tmpU32no2 = inst->timeAvgMagnEnergy >> (20 - inst->stages - normTmp);
|
||||
if (tmpU32no2 > 0) {
|
||||
|
||||
@ -11,7 +11,8 @@
|
||||
#include "webrtc/modules/audio_processing/ns/nsx_core.h"
|
||||
|
||||
#include <arm_neon.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
|
||||
// Constants to compensate for shifting signal log(2^shifts).
|
||||
const int16_t WebRtcNsx_kLogTable[9] = {
|
||||
@ -144,8 +145,8 @@ void WebRtcNsx_NoiseEstimationNeon(NoiseSuppressionFixedC* inst,
|
||||
size_t i, s, offset;
|
||||
|
||||
tabind = inst->stages - inst->normData;
|
||||
assert(tabind < 9);
|
||||
assert(tabind > -9);
|
||||
RTC_DCHECK_LT(tabind, 9);
|
||||
RTC_DCHECK_GT(tabind, -9);
|
||||
if (tabind < 0) {
|
||||
logval = -WebRtcNsx_kLogTable[-tabind];
|
||||
} else {
|
||||
@ -163,7 +164,7 @@ void WebRtcNsx_NoiseEstimationNeon(NoiseSuppressionFixedC* inst,
|
||||
zeros = WebRtcSpl_NormU32((uint32_t)magn[i]);
|
||||
frac = (int16_t)((((uint32_t)magn[i] << zeros)
|
||||
& 0x7FFFFFFF) >> 23);
|
||||
assert(frac < 256);
|
||||
RTC_DCHECK_LT(frac, 256);
|
||||
// log2(magn(i))
|
||||
log2 = (int16_t)(((31 - zeros) << 8)
|
||||
+ WebRtcNsx_kLogTableFrac[frac]);
|
||||
@ -190,7 +191,7 @@ void WebRtcNsx_NoiseEstimationNeon(NoiseSuppressionFixedC* inst,
|
||||
|
||||
// Get counter values from state
|
||||
counter = inst->noiseEstCounter[s];
|
||||
assert(counter < 201);
|
||||
RTC_DCHECK_LT(counter, 201);
|
||||
countDiv = WebRtcNsx_kCounterDiv[counter];
|
||||
countProd = (int16_t)(counter * countDiv);
|
||||
|
||||
@ -354,8 +355,8 @@ void WebRtcNsx_NoiseEstimationNeon(NoiseSuppressionFixedC* inst,
|
||||
// Filter the data in the frequency domain, and create spectrum.
|
||||
void WebRtcNsx_PrepareSpectrumNeon(NoiseSuppressionFixedC* inst,
|
||||
int16_t* freq_buf) {
|
||||
assert(inst->magnLen % 8 == 1);
|
||||
assert(inst->anaLen2 % 16 == 0);
|
||||
RTC_DCHECK_EQ(1, inst->magnLen % 8);
|
||||
RTC_DCHECK_EQ(0, inst->anaLen2 % 16);
|
||||
|
||||
// (1) Filtering.
|
||||
|
||||
@ -445,8 +446,8 @@ void WebRtcNsx_PrepareSpectrumNeon(NoiseSuppressionFixedC* inst,
|
||||
void WebRtcNsx_SynthesisUpdateNeon(NoiseSuppressionFixedC* inst,
|
||||
int16_t* out_frame,
|
||||
int16_t gain_factor) {
|
||||
assert(inst->anaLen % 16 == 0);
|
||||
assert(inst->blockLen10ms % 16 == 0);
|
||||
RTC_DCHECK_EQ(0, inst->anaLen % 16);
|
||||
RTC_DCHECK_EQ(0, inst->blockLen10ms % 16);
|
||||
|
||||
int16_t* preal_start = inst->real;
|
||||
const int16_t* pwindow = inst->window;
|
||||
@ -537,8 +538,8 @@ void WebRtcNsx_SynthesisUpdateNeon(NoiseSuppressionFixedC* inst,
|
||||
void WebRtcNsx_AnalysisUpdateNeon(NoiseSuppressionFixedC* inst,
|
||||
int16_t* out,
|
||||
int16_t* new_speech) {
|
||||
assert(inst->blockLen10ms % 16 == 0);
|
||||
assert(inst->anaLen % 16 == 0);
|
||||
RTC_DCHECK_EQ(0, inst->blockLen10ms % 16);
|
||||
RTC_DCHECK_EQ(0, inst->anaLen % 16);
|
||||
|
||||
// For lower band update analysis buffer.
|
||||
// memcpy(inst->analysisBuffer, inst->analysisBuffer + inst->blockLen10ms,
|
||||
|
||||
Reference in New Issue
Block a user