Update a ton of audio code to use size_t more correctly and in general reduce

use of int16_t/uint16_t.

This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.

This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002

The change is being landed as TBR to all the folks who reviewed the above.

BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher

Review URL: https://codereview.webrtc.org/1230503003 .

Cr-Commit-Position: refs/heads/master@{#9768}
This commit is contained in:
Peter Kasting
2015-08-24 14:52:23 -07:00
parent b594041ec8
commit dce40cf804
471 changed files with 3716 additions and 3499 deletions

View File

@ -11,6 +11,8 @@
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_
#include <stddef.h>
#include "webrtc/typedefs.h"
typedef struct NsHandleT NsHandle;
@ -92,7 +94,7 @@ void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe);
*/
void WebRtcNs_Process(NsHandle* NS_inst,
const float* const* spframe,
int num_bands,
size_t num_bands,
float* const* outframe);
/* Returns the internally used prior speech probability of the current frame.

View File

@ -41,7 +41,7 @@ void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe) {
void WebRtcNs_Process(NsHandle* NS_inst,
const float* const* spframe,
int num_bands,
size_t num_bands,
float* const* outframe) {
WebRtcNs_ProcessCore((NoiseSuppressionC*)NS_inst, spframe, num_bands,
outframe);

View File

@ -217,7 +217,7 @@ int WebRtcNs_InitCore(NoiseSuppressionC* self, uint32_t fs) {
static void NoiseEstimation(NoiseSuppressionC* self,
float* magn,
float* noise) {
int i, s, offset;
size_t i, s, offset;
float lmagn[HALF_ANAL_BLOCKL], delta;
if (self->updates < END_STARTUP_LONG) {
@ -522,8 +522,8 @@ static void FeatureParameterExtraction(NoiseSuppressionC* self, int flag) {
// Spectral flatness is returned in self->featureData[0].
static void ComputeSpectralFlatness(NoiseSuppressionC* self,
const float* magnIn) {
int i;
int shiftLP = 1; // Option to remove first bin(s) from spectral measures.
size_t i;
size_t shiftLP = 1; // Option to remove first bin(s) from spectral measures.
float avgSpectralFlatnessNum, avgSpectralFlatnessDen, spectralTmp;
// Compute spectral measures.
@ -568,7 +568,7 @@ static void ComputeSnr(const NoiseSuppressionC* self,
const float* noise,
float* snrLocPrior,
float* snrLocPost) {
int i;
size_t i;
for (i = 0; i < self->magnLen; i++) {
// Previous post SNR.
@ -596,7 +596,7 @@ static void ComputeSpectralDifference(NoiseSuppressionC* self,
const float* magnIn) {
// avgDiffNormMagn = var(magnIn) - cov(magnIn, magnAvgPause)^2 /
// var(magnAvgPause)
int i;
size_t i;
float avgPause, avgMagn, covMagnPause, varPause, varMagn, avgDiffNormMagn;
avgPause = 0.0;
@ -643,7 +643,8 @@ static void SpeechNoiseProb(NoiseSuppressionC* self,
float* probSpeechFinal,
const float* snrLocPrior,
const float* snrLocPost) {
int i, sgnMap;
size_t i;
int sgnMap;
float invLrt, gainPrior, indPrior;
float logLrtTimeAvgKsum, besselTmp;
float indicator0, indicator1, indicator2;
@ -802,7 +803,7 @@ static void UpdateNoiseEstimate(NoiseSuppressionC* self,
const float* snrLocPrior,
const float* snrLocPost,
float* noise) {
int i;
size_t i;
float probSpeech, probNonSpeech;
// Time-avg parameter for noise update.
float gammaNoiseTmp = NOISE_UPDATE;
@ -853,8 +854,8 @@ static void UpdateNoiseEstimate(NoiseSuppressionC* self,
// Output:
// * |buffer| is the updated buffer.
static void UpdateBuffer(const float* frame,
int frame_length,
int buffer_length,
size_t frame_length,
size_t buffer_length,
float* buffer) {
assert(buffer_length < 2 * frame_length);
@ -885,12 +886,12 @@ static void UpdateBuffer(const float* frame,
// * |magn| is the calculated signal magnitude in the frequency domain.
static void FFT(NoiseSuppressionC* self,
float* time_data,
int time_data_length,
int magnitude_length,
size_t time_data_length,
size_t magnitude_length,
float* real,
float* imag,
float* magn) {
int i;
size_t i;
assert(magnitude_length == time_data_length / 2 + 1);
@ -923,10 +924,10 @@ static void FFT(NoiseSuppressionC* self,
static void IFFT(NoiseSuppressionC* self,
const float* real,
const float* imag,
int magnitude_length,
int time_data_length,
size_t magnitude_length,
size_t time_data_length,
float* time_data) {
int i;
size_t i;
assert(time_data_length == 2 * (magnitude_length - 1));
@ -948,8 +949,8 @@ static void IFFT(NoiseSuppressionC* self,
// * |buffer| is the buffer over which the energy is calculated.
// * |length| is the length of the buffer.
// Returns the calculated energy.
static float Energy(const float* buffer, int length) {
int i;
static float Energy(const float* buffer, size_t length) {
size_t i;
float energy = 0.f;
for (i = 0; i < length; ++i) {
@ -968,9 +969,9 @@ static float Energy(const float* buffer, int length) {
// * |data_windowed| is the windowed data.
static void Windowing(const float* window,
const float* data,
int length,
size_t length,
float* data_windowed) {
int i;
size_t i;
for (i = 0; i < length; ++i) {
data_windowed[i] = window[i] * data[i];
@ -985,7 +986,7 @@ static void Windowing(const float* window,
static void ComputeDdBasedWienerFilter(const NoiseSuppressionC* self,
const float* magn,
float* theFilter) {
int i;
size_t i;
float snrPrior, previousEstimateStsa, currentEstimateStsa;
for (i = 0; i < self->magnLen; i++) {
@ -1041,8 +1042,8 @@ int WebRtcNs_set_policy_core(NoiseSuppressionC* self, int mode) {
}
void WebRtcNs_AnalyzeCore(NoiseSuppressionC* self, const float* speechFrame) {
int i;
const int kStartBand = 5; // Skip first frequency bins during estimation.
size_t i;
const size_t kStartBand = 5; // Skip first frequency bins during estimation.
int updateParsFlag;
float energy;
float signalEnergy = 0.f;
@ -1182,11 +1183,11 @@ void WebRtcNs_AnalyzeCore(NoiseSuppressionC* self, const float* speechFrame) {
void WebRtcNs_ProcessCore(NoiseSuppressionC* self,
const float* const* speechFrame,
int num_bands,
size_t num_bands,
float* const* outFrame) {
// Main routine for noise reduction.
int flagHB = 0;
int i, j;
size_t i, j;
float energy1, energy2, gain, factor, factor1, factor2;
float fout[BLOCKL_MAX];
@ -1210,7 +1211,7 @@ void WebRtcNs_ProcessCore(NoiseSuppressionC* self,
const float* const* speechFrameHB = NULL;
float* const* outFrameHB = NULL;
int num_high_bands = 0;
size_t num_high_bands = 0;
if (num_bands > 1) {
speechFrameHB = &speechFrame[1];
outFrameHB = &outFrame[1];

View File

@ -51,10 +51,10 @@ typedef struct NSParaExtract_ {
typedef struct NoiseSuppressionC_ {
uint32_t fs;
int blockLen;
int windShift;
int anaLen;
int magnLen;
size_t blockLen;
size_t windShift;
size_t anaLen;
size_t magnLen;
int aggrMode;
const float* window;
float analyzeBuf[ANAL_BLOCKL_MAX];
@ -74,7 +74,7 @@ typedef struct NoiseSuppressionC_ {
float denoiseBound;
int gainmap;
// FFT work arrays.
int ip[IP_LENGTH];
size_t ip[IP_LENGTH];
float wfft[W_LENGTH];
// Parameters for new method: some not needed, will reduce/cleanup later.
@ -181,7 +181,7 @@ void WebRtcNs_AnalyzeCore(NoiseSuppressionC* self, const float* speechFrame);
*/
void WebRtcNs_ProcessCore(NoiseSuppressionC* self,
const float* const* inFrame,
int num_bands,
size_t num_bands,
float* const* outFrame);
#ifdef __cplusplus

View File

@ -68,7 +68,7 @@ static const int16_t WebRtcNsx_kLogTableFrac[256] = {
#endif // WEBRTC_DETECT_NEON || WEBRTC_HAS_NEON
// Skip first frequency bins during estimation. (0 <= value < 64)
static const int kStartBand = 5;
static const size_t kStartBand = 5;
// hybrib Hanning & flat window
static const int16_t kBlocks80w128x[128] = {
@ -306,7 +306,7 @@ static void UpdateNoiseEstimate(NoiseSuppressionFixedC* inst, int offset) {
int16_t tmp16 = 0;
const int16_t kExp2Const = 11819; // Q13
int i = 0;
size_t i = 0;
tmp16 = WebRtcSpl_MaxValueW16(inst->noiseEstLogQuantile + offset,
inst->magnLen);
@ -341,7 +341,7 @@ static void NoiseEstimationC(NoiseSuppressionFixedC* inst,
const int16_t log2_const = 22713; // Q15
const int16_t width_factor = 21845;
int i, s, offset;
size_t i, s, offset;
tabind = inst->stages - inst->normData;
assert(tabind < 9);
@ -454,7 +454,7 @@ static void NoiseEstimationC(NoiseSuppressionFixedC* inst,
// Filter the data in the frequency domain, and create spectrum.
static void PrepareSpectrumC(NoiseSuppressionFixedC* inst, int16_t* freq_buf) {
int i = 0, j = 0;
size_t i = 0, j = 0;
for (i = 0; i < inst->magnLen; i++) {
inst->real[i] = (int16_t)((inst->real[i] *
@ -477,7 +477,7 @@ static void PrepareSpectrumC(NoiseSuppressionFixedC* inst, int16_t* freq_buf) {
static void DenormalizeC(NoiseSuppressionFixedC* inst,
int16_t* in,
int factor) {
int i = 0;
size_t i = 0;
int32_t tmp32 = 0;
for (i = 0; i < inst->anaLen; i += 1) {
tmp32 = WEBRTC_SPL_SHIFT_W32((int32_t)in[i],
@ -491,7 +491,7 @@ static void DenormalizeC(NoiseSuppressionFixedC* inst,
static void SynthesisUpdateC(NoiseSuppressionFixedC* inst,
int16_t* out_frame,
int16_t gain_factor) {
int i = 0;
size_t i = 0;
int16_t tmp16a = 0;
int16_t tmp16b = 0;
int32_t tmp32 = 0;
@ -523,7 +523,7 @@ static void SynthesisUpdateC(NoiseSuppressionFixedC* inst,
static void AnalysisUpdateC(NoiseSuppressionFixedC* inst,
int16_t* out,
int16_t* new_speech) {
int i = 0;
size_t i = 0;
// For lower band update analysis buffer.
memcpy(inst->analysisBuffer, inst->analysisBuffer + inst->blockLen10ms,
@ -542,7 +542,7 @@ static void AnalysisUpdateC(NoiseSuppressionFixedC* inst,
static void NormalizeRealBufferC(NoiseSuppressionFixedC* inst,
const int16_t* in,
int16_t* out) {
int i = 0;
size_t i = 0;
assert(inst->normData >= 0);
for (i = 0; i < inst->anaLen; ++i) {
out[i] = in[i] << inst->normData; // Q(normData)
@ -1026,7 +1026,7 @@ void WebRtcNsx_ComputeSpectralFlatness(NoiseSuppressionFixedC* inst,
int16_t zeros, frac, intPart;
int i;
size_t i;
// for flatness
avgSpectralFlatnessNum = 0;
@ -1099,7 +1099,8 @@ void WebRtcNsx_ComputeSpectralDifference(NoiseSuppressionFixedC* inst,
int16_t tmp16no1;
int i, norm32, nShifts;
size_t i;
int norm32, nShifts;
avgPauseFX = 0;
maxPause = 0;
@ -1198,7 +1199,7 @@ void WebRtcNsx_DataAnalysis(NoiseSuppressionFixedC* inst,
int16_t matrix_determinant = 0;
int16_t maxWinData;
int i, j;
size_t i, j;
int zeros;
int net_norm = 0;
int right_shifts_in_magnU16 = 0;
@ -1430,7 +1431,7 @@ void WebRtcNsx_DataSynthesis(NoiseSuppressionFixedC* inst, short* outFrame) {
int16_t energyRatio;
int16_t gainFactor, gainFactor1, gainFactor2;
int i;
size_t i;
int outCIFFT;
int scaleEnergyOut = 0;
@ -1531,7 +1532,7 @@ void WebRtcNsx_ProcessCore(NoiseSuppressionFixedC* inst,
int16_t avgProbSpeechHB, gainModHB, avgFilterGainHB, gainTimeDomainHB;
int16_t pink_noise_exp_avg = 0;
int i, j;
size_t i, j;
int nShifts, postShifts;
int norm32no1, norm32no2;
int flag, sign;
@ -1559,11 +1560,11 @@ void WebRtcNsx_ProcessCore(NoiseSuppressionFixedC* inst,
const short* const* speechFrameHB = NULL;
short* const* outFrameHB = NULL;
int num_high_bands = 0;
size_t num_high_bands = 0;
if (num_bands > 1) {
speechFrameHB = &speechFrame[1];
outFrameHB = &outFrame[1];
num_high_bands = num_bands - 1;
num_high_bands = (size_t)(num_bands - 1);
}
// Store speechFrame and transform to frequency domain

View File

@ -34,9 +34,9 @@ typedef struct NoiseSuppressionFixedC_ {
int16_t noiseEstCounter[SIMULT];
int16_t noiseEstQuantile[HALF_ANAL_BLOCKL];
int anaLen;
int anaLen2;
int magnLen;
size_t anaLen;
size_t anaLen2;
size_t magnLen;
int aggrMode;
int stages;
int initFlag;
@ -98,7 +98,7 @@ typedef struct NoiseSuppressionFixedC_ {
int qNoise;
int prevQNoise;
int prevQMagn;
int blockLen10ms;
size_t blockLen10ms;
int16_t real[ANAL_BLOCKL_MAX];
int16_t imag[ANAL_BLOCKL_MAX];

View File

@ -33,7 +33,8 @@ void WebRtcNsx_SpeechNoiseProb(NoiseSuppressionFixedC* inst,
int32_t logLrtTimeAvgKsumFX;
int16_t indPriorFX16;
int16_t tmp16, tmp16no1, tmp16no2, tmpIndFX, tableIndex, frac, intPart;
int i, normTmp, normTmp2, nShifts;
size_t i;
int normTmp, normTmp2, nShifts;
// compute feature based on average LR factor
// this is the average over all frequencies of the smooth log LRT

View File

@ -32,7 +32,8 @@ void WebRtcNsx_SpeechNoiseProb(NoiseSuppressionFixedC* inst,
int32_t logLrtTimeAvgKsumFX;
int16_t indPriorFX16;
int16_t tmp16, tmp16no1, tmp16no2, tmpIndFX, tableIndex, frac;
int i, normTmp, nShifts;
size_t i;
int normTmp, nShifts;
int32_t r0, r1, r2, r3, r4, r5, r6, r7, r8, r9;
int32_t const_max = 0x7fffffff;
@ -331,7 +332,7 @@ void WebRtcNsx_AnalysisUpdate_mips(NoiseSuppressionFixedC* inst,
int16_t* out,
int16_t* new_speech) {
int iters, after;
int anaLen = inst->anaLen;
int anaLen = (int)inst->anaLen;
int *window = (int*)inst->window;
int *anaBuf = (int*)inst->analysisBuffer;
int *outBuf = (int*)out;
@ -504,7 +505,7 @@ void WebRtcNsx_AnalysisUpdate_mips(NoiseSuppressionFixedC* inst,
void WebRtcNsx_SynthesisUpdate_mips(NoiseSuppressionFixedC* inst,
int16_t* out_frame,
int16_t gain_factor) {
int iters = inst->blockLen10ms >> 2;
int iters = (int)inst->blockLen10ms >> 2;
int after = inst->blockLen10ms & 3;
int r0, r1, r2, r3, r4, r5, r6, r7;
int16_t *window = (int16_t*)inst->window;
@ -861,7 +862,7 @@ void WebRtcNsx_Denormalize_mips(NoiseSuppressionFixedC* inst,
int16_t* in,
int factor) {
int32_t r0, r1, r2, r3, t0;
int len = inst->anaLen;
int len = (int)inst->anaLen;
int16_t *out = &inst->real[0];
int shift = factor - inst->normData;
@ -951,7 +952,7 @@ void WebRtcNsx_NormalizeRealBuffer_mips(NoiseSuppressionFixedC* inst,
const int16_t* in,
int16_t* out) {
int32_t r0, r1, r2, r3, t0;
int len = inst->anaLen;
int len = (int)inst->anaLen;
int shift = inst->normData;
__asm __volatile (

View File

@ -141,7 +141,7 @@ void WebRtcNsx_NoiseEstimationNeon(NoiseSuppressionFixedC* inst,
const int16_t log2_const = 22713;
const int16_t width_factor = 21845;
int i, s, offset;
size_t i, s, offset;
tabind = inst->stages - inst->normData;
assert(tabind < 9);