From 28b54671cbb066b9b82301a015441491f6c95318 Mon Sep 17 00:00:00 2001
From: "aluebs@webrtc.org" <aluebs@webrtc.org>
Date: Tue, 28 Oct 2014 20:56:53 +0000
Subject: [PATCH] Make all comments whole sentences in ns_core

This is done to make the code more readable.
It generates bit-exact output.

BUG=webrtc:3811
R=bjornv@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/23199004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7547 4adac7df-926f-26a2-2b94-8c16560cd09d
---
 webrtc/modules/audio_processing/ns/ns_core.c | 510 +++++++++----------
 webrtc/modules/audio_processing/ns/ns_core.h |  84 +--
 2 files changed, 292 insertions(+), 302 deletions(-)

diff --git a/webrtc/modules/audio_processing/ns/ns_core.c b/webrtc/modules/audio_processing/ns/ns_core.c
index 590313196..fa728bd8d 100644
--- a/webrtc/modules/audio_processing/ns/ns_core.c
+++ b/webrtc/modules/audio_processing/ns/ns_core.c
@@ -19,42 +19,41 @@
 #include "webrtc/modules/audio_processing/ns/windows_private.h"
 #include "webrtc/modules/audio_processing/utility/fft4g.h"
 
-// Set Feature Extraction Parameters
+// Set Feature Extraction Parameters.
 void WebRtcNs_set_feature_extraction_parameters(NSinst_t* inst) {
-  // bin size of histogram
+  // Bin size of histogram.
   inst->featureExtractionParams.binSizeLrt = 0.1f;
   inst->featureExtractionParams.binSizeSpecFlat = 0.05f;
   inst->featureExtractionParams.binSizeSpecDiff = 0.1f;
 
-  // range of histogram over which lrt threshold is computed
+  // Range of histogram over which LRT threshold is computed.
   inst->featureExtractionParams.rangeAvgHistLrt = 1.f;
 
-  // scale parameters: multiply dominant peaks of the histograms by scale factor
-  // to obtain thresholds for prior model
-  inst->featureExtractionParams.factor1ModelPars =
-      1.2f;  // for lrt and spectral diff
-  inst->featureExtractionParams.factor2ModelPars =
-      0.9f;  // for spectral_flatness:
-  // used when noise is flatter than speech
+  // Scale parameters: multiply dominant peaks of the histograms by scale factor
+  // to obtain thresholds for prior model.
+  // For LRT and spectral difference.
+  inst->featureExtractionParams.factor1ModelPars = 1.2f;
+  // For spectral_flatness: used when noise is flatter than speech.
+  inst->featureExtractionParams.factor2ModelPars = 0.9f;
 
-  // peak limit for spectral flatness (varies between 0 and 1)
+  // Peak limit for spectral flatness (varies between 0 and 1).
   inst->featureExtractionParams.thresPosSpecFlat = 0.6f;
 
-  // limit on spacing of two highest peaks in histogram: spacing determined by
-  // bin size
+  // Limit on spacing of two highest peaks in histogram: spacing determined by
+  // bin size.
   inst->featureExtractionParams.limitPeakSpacingSpecFlat =
       2 * inst->featureExtractionParams.binSizeSpecFlat;
   inst->featureExtractionParams.limitPeakSpacingSpecDiff =
       2 * inst->featureExtractionParams.binSizeSpecDiff;
 
-  // limit on relevance of second peak:
+  // Limit on relevance of second peak.
   inst->featureExtractionParams.limitPeakWeightsSpecFlat = 0.5f;
   inst->featureExtractionParams.limitPeakWeightsSpecDiff = 0.5f;
 
-  // fluctuation limit of lrt feature
+  // Fluctuation limit of LRT feature.
   inst->featureExtractionParams.thresFluctLrt = 0.05f;
 
-  // limit on the max and min values for the feature thresholds
+  // Limit on the max and min values for the feature thresholds.
   inst->featureExtractionParams.maxLrt = 1.f;
   inst->featureExtractionParams.minLrt = 0.2f;
 
@@ -64,24 +63,22 @@ void WebRtcNs_set_feature_extraction_parameters(NSinst_t* inst) {
   inst->featureExtractionParams.maxSpecDiff = 1.f;
   inst->featureExtractionParams.minSpecDiff = 0.16f;
 
-  // criteria of weight of histogram peak  to accept/reject feature
+  // Criteria of weight of histogram peak to accept/reject feature.
   inst->featureExtractionParams.thresWeightSpecFlat =
-      (int)(0.3 * (inst->modelUpdatePars[1]));  // for spectral flatness
+      (int)(0.3 * (inst->modelUpdatePars[1]));  // For spectral flatness.
   inst->featureExtractionParams.thresWeightSpecDiff =
-      (int)(0.3 * (inst->modelUpdatePars[1]));  // for spectral difference
+      (int)(0.3 * (inst->modelUpdatePars[1]));  // For spectral difference.
 }
 
-// Initialize state
+// Initialize state.
 int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
   int i;
-  // We only support 10ms frames
-
-  // check for valid pointer
+  // Check for valid pointer.
   if (inst == NULL) {
     return -1;
   }
 
-  // Initialization of struct
+  // Initialization of struct.
   if (fs == 8000 || fs == 16000 || fs == 32000) {
     inst->fs = fs;
   } else {
@@ -89,24 +86,24 @@ int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
   }
   inst->windShift = 0;
   if (fs == 8000) {
-    // We only support 10ms frames
+    // We only support 10ms frames.
     inst->blockLen = 80;
     inst->anaLen = 128;
     inst->window = kBlocks80w128;
   } else if (fs == 16000) {
-    // We only support 10ms frames
+    // We only support 10ms frames.
     inst->blockLen = 160;
     inst->anaLen = 256;
     inst->window = kBlocks160w256;
   } else if (fs == 32000) {
-    // We only support 10ms frames
+    // We only support 10ms frames.
     inst->blockLen = 160;
     inst->anaLen = 256;
     inst->window = kBlocks160w256;
   }
-  inst->magnLen = inst->anaLen / 2 + 1;  // Number of frequency bins
+  inst->magnLen = inst->anaLen / 2 + 1;  // Number of frequency bins.
 
-  // Initialize fft work arrays.
+  // 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);
@@ -115,10 +112,10 @@ int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
   memset(inst->dataBuf, 0, sizeof(float) * ANAL_BLOCKL_MAX);
   memset(inst->syntBuf, 0, sizeof(float) * ANAL_BLOCKL_MAX);
 
-  // for HB processing
+  // For HB processing.
   memset(inst->dataBufHB, 0, sizeof(float) * ANAL_BLOCKL_MAX);
 
-  // for quantile noise estimation
+  // 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] = 8.f;
@@ -132,75 +129,77 @@ int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
 
   inst->updates = 0;
 
-  // Wiener filter initialization
+  // Wiener filter initialization.
   for (i = 0; i < HALF_ANAL_BLOCKL; i++) {
     inst->smooth[i] = 1.f;
   }
 
-  // Set the aggressiveness: default
+  // Set the aggressiveness: default.
   inst->aggrMode = 0;
 
-  // initialize variables for new method
-  inst->priorSpeechProb = 0.5f;  // prior prob for speech/noise
-  // previous analyze mag spectrum
+  // Initialize variables for new method.
+  inst->priorSpeechProb = 0.5f;  // Prior prob for speech/noise.
+  // Previous analyze mag spectrum.
   memset(inst->magnPrevAnalyze, 0, sizeof(float) * HALF_ANAL_BLOCKL);
-  // previous process mag spectrum
+  // Previous process mag spectrum.
   memset(inst->magnPrevProcess, 0, sizeof(float) * HALF_ANAL_BLOCKL);
-  // current noise-spectrum
+  // Current noise-spectrum.
   memset(inst->noise, 0, sizeof(float) * HALF_ANAL_BLOCKL);
-  // previous noise-spectrum
+  // Previous noise-spectrum.
   memset(inst->noisePrev, 0, sizeof(float) * HALF_ANAL_BLOCKL);
-  // conservative noise spectrum estimate
+  // Conservative noise spectrum estimate.
   memset(inst->magnAvgPause, 0, sizeof(float) * HALF_ANAL_BLOCKL);
-  // for estimation of HB in second pass
+  // For estimation of HB in second pass.
   memset(inst->speechProb, 0, sizeof(float) * HALF_ANAL_BLOCKL);
-  // initial average mag spectrum
+  // Initial average magnitude spectrum.
   memset(inst->initMagnEst, 0, sizeof(float) * HALF_ANAL_BLOCKL);
   for (i = 0; i < HALF_ANAL_BLOCKL; i++) {
-    inst->logLrtTimeAvg[i] =
-        LRT_FEATURE_THR;                 // smooth LR ratio (same as threshold)
+    // Smooth LR (same as threshold).
+    inst->logLrtTimeAvg[i] = LRT_FEATURE_THR;
   }
 
-  // feature quantities
-  inst->featureData[0] =
-      SF_FEATURE_THR;  // spectral flatness (start on threshold)
-  inst->featureData[1] = 0.f;  // spectral entropy: not used in this version
-  inst->featureData[2] = 0.f;  // 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] = 0.f;  // normalization for spectral-diff
-  inst->featureData[6] =
-      0.f;  // window time-average of input magnitude spectrum
+  // Feature quantities.
+  // Spectral flatness (start on threshold).
+  inst->featureData[0] = SF_FEATURE_THR;
+  inst->featureData[1] = 0.f;  // Spectral entropy: not used in this version.
+  inst->featureData[2] = 0.f;  // Spectral variance: not used in this version.
+  // Average LRT factor (start on threshold).
+  inst->featureData[3] = LRT_FEATURE_THR;
+  // Spectral template diff (start on threshold).
+  inst->featureData[4] = SF_FEATURE_THR;
+  inst->featureData[5] = 0.f;  // Normalization for spectral difference.
+  // Window time-average of input magnitude spectrum.
+  inst->featureData[6] = 0.f;
 
-  // histogram quantities: used to estimate/update thresholds for features
+  // Histogram quantities: used to estimate/update thresholds for features.
   memset(inst->histLrt, 0, sizeof(int) * HIST_PAR_EST);
   memset(inst->histSpecFlat, 0, sizeof(int) * HIST_PAR_EST);
   memset(inst->histSpecDiff, 0, sizeof(int) * HIST_PAR_EST);
 
 
-  inst->blockInd = -1;  // frame counter
-  inst->priorModelPars[0] =
-      LRT_FEATURE_THR;             // default threshold for lrt feature
-  inst->priorModelPars[1] = 0.5f;  // threshold for spectral flatness:
-  // determined on-line
-  inst->priorModelPars[2] = 1.f;  // sgn_map par for spectral measure:
-  // 1 for flatness measure
-  inst->priorModelPars[3] = 0.5f;  // threshold for template-difference feature:
-  // determined on-line
-  inst->priorModelPars[4] = 1.f;  // default weighting parameter for lrt feature
-  inst->priorModelPars[5] = 0.f;  // default weighting parameter for
-  // spectral flatness feature
-  inst->priorModelPars[6] = 0.f;  // default weighting parameter for
-  // spectral difference feature
+  inst->blockInd = -1;  // Frame counter.
+  // Default threshold for LRT feature.
+  inst->priorModelPars[0] = LRT_FEATURE_THR;
+  // Threshold for spectral flatness: determined on-line.
+  inst->priorModelPars[1] = 0.5f;
+  // sgn_map par for spectral measure: 1 for flatness measure.
+  inst->priorModelPars[2] = 1.f;
+  // Threshold for template-difference feature: determined on-line.
+  inst->priorModelPars[3] = 0.5f;
+  // Default weighting parameter for LRT feature.
+  inst->priorModelPars[4] = 1.f;
+  // Default weighting parameter for spectral flatness feature.
+  inst->priorModelPars[5] = 0.f;
+  // Default weighting parameter for spectral difference feature.
+  inst->priorModelPars[6] = 0.f;
 
-  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
+  // Update flag for parameters:
+  // 0 no update, 1 = update once, 2 = update every window.
+  inst->modelUpdatePars[0] = 2;
+  inst->modelUpdatePars[1] = 500;  // Window for update.
+  // Counter for update of conservative noise spectrum.
+  inst->modelUpdatePars[2] = 0;
+  // Counter if the feature thresholds are updated during the sequence.
   inst->modelUpdatePars[3] = inst->modelUpdatePars[1];
 
   inst->signalEnergy = 0.0;
@@ -211,7 +210,7 @@ int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
 
   WebRtcNs_set_feature_extraction_parameters(inst);
 
-  // default mode
+  // Default mode.
   WebRtcNs_set_policy_core(inst, 0);
 
   inst->initFlag = 1;
@@ -219,7 +218,7 @@ int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
 }
 
 int WebRtcNs_set_policy_core(NSinst_t* inst, int mode) {
-  // allow for modes:0,1,2,3
+  // Allow for modes: 0, 1, 2, 3.
   if (mode < 0 || mode > 3) {
     return (-1);
   }
@@ -248,7 +247,7 @@ int WebRtcNs_set_policy_core(NSinst_t* inst, int mode) {
   return 0;
 }
 
-// Estimate noise
+// Estimate noise.
 void WebRtcNs_NoiseEstimation(NSinst_t* inst, float* magn, float* noise) {
   int i, s, offset;
   float lmagn[HALF_ANAL_BLOCKL], delta;
@@ -261,20 +260,20 @@ void WebRtcNs_NoiseEstimation(NSinst_t* inst, float* magn, float* noise) {
     lmagn[i] = (float)log(magn[i]);
   }
 
-  // loop over simultaneous estimates
+  // Loop over simultaneous estimates.
   for (s = 0; s < SIMULT; s++) {
     offset = s * inst->magnLen;
 
     // newquantest(...)
     for (i = 0; i < inst->magnLen; i++) {
-      // compute delta
+      // Compute delta.
       if (inst->density[offset + i] > 1.0) {
         delta = FACTOR * 1.f / inst->density[offset + i];
       } else {
         delta = FACTOR;
       }
 
-      // update log quantile estimate
+      // Update log quantile estimate.
       if (lmagn[i] > inst->lquantile[offset + i]) {
         inst->lquantile[offset + i] +=
             QUANTILE * delta / (float)(inst->counter[s] + 1);
@@ -283,14 +282,14 @@ void WebRtcNs_NoiseEstimation(NSinst_t* inst, float* magn, float* noise) {
             (1.f - QUANTILE) * delta / (float)(inst->counter[s] + 1);
       }
 
-      // update density estimate
+      // Update density estimate.
       if (fabs(lmagn[i] - inst->lquantile[offset + i]) < WIDTH) {
         inst->density[offset + i] =
             ((float)inst->counter[s] * inst->density[offset + i] +
              1.f / (2.f * WIDTH)) /
             (float)(inst->counter[s] + 1);
       }
-    }  // end loop over magnitude spectrum
+    }  // End loop over magnitude spectrum.
 
     if (inst->counter[s] >= END_STARTUP_LONG) {
       inst->counter[s] = 0;
@@ -302,9 +301,9 @@ void WebRtcNs_NoiseEstimation(NSinst_t* inst, float* magn, float* noise) {
     }
 
     inst->counter[s]++;
-  }  // end loop over simultaneous estimates
+  }  // End loop over simultaneous estimates.
 
-  // Sequentially update the noise during startup
+  // Sequentially update the noise during startup.
   if (inst->updates < END_STARTUP_LONG) {
     // Use the last "s" to get noise during startup that differ from zero.
     for (i = 0; i < inst->magnLen; i++) {
@@ -317,13 +316,12 @@ void WebRtcNs_NoiseEstimation(NSinst_t* inst, float* magn, float* noise) {
   }
 }
 
-// Extract thresholds for feature parameters
-// histograms are computed over some window_size (given by
-// inst->modelUpdatePars[1])
-// thresholds and weights are extracted every window
-// flag 0 means update histogram only, flag 1 means compute the
-// thresholds/weights
-// threshold and weights are returned in: inst->priorModelPars
+// Extract thresholds for feature parameters.
+// Histograms are computed over some window size (given by
+// inst->modelUpdatePars[1]).
+// Thresholds and weights are extracted every window.
+// |flag| = 0 updates histogram only, |flag| = 1 computes the threshold/weights.
+// Threshold and weights are returned in: inst->priorModelPars.
 static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
   int i, useFeatureSpecFlat, useFeatureSpecDiff, numHistLrt;
   int maxPeak1, maxPeak2;
@@ -334,12 +332,12 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
   float posPeak1SpecFlat, posPeak2SpecFlat, posPeak1SpecDiff, posPeak2SpecDiff;
   float fluctLrt, avgHistLrt, avgSquareHistLrt, avgHistLrtCompl;
 
-  // 3 features: lrt, flatness, difference
+  // 3 features: LRT, flatness, difference.
   // lrt_feature = self->featureData[3];
   // flat_feature = self->featureData[0];
   // diff_feature = self->featureData[4];
 
-  // update histograms
+  // Update histograms.
   if (flag == 0) {
     // LRT
     if ((self->featureData[3] <
@@ -349,7 +347,7 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
                 self->featureExtractionParams.binSizeLrt);
       self->histLrt[i]++;
     }
-    // Spectral flatness
+    // Spectral flatness.
     if ((self->featureData[0] <
          HIST_PAR_EST * self->featureExtractionParams.binSizeSpecFlat) &&
         (self->featureData[0] >= 0.0)) {
@@ -357,7 +355,7 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
                 self->featureExtractionParams.binSizeSpecFlat);
       self->histSpecFlat[i]++;
     }
-    // Spectral difference
+    // Spectral difference.
     if ((self->featureData[4] <
          HIST_PAR_EST * self->featureExtractionParams.binSizeSpecDiff) &&
         (self->featureData[4] >= 0.0)) {
@@ -367,10 +365,10 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
     }
   }
 
-  // extract parameters for speech/noise probability
+  // Extract parameters for speech/noise probability.
   if (flag == 1) {
-    // lrt feature: compute the average over
-    // self->featureExtractionParams.rangeAvgHistLrt
+    // LRT feature: compute the average over
+    // self->featureExtractionParams.rangeAvgHistLrt.
     avgHistLrt = 0.0;
     avgHistLrtCompl = 0.0;
     avgSquareHistLrt = 0.0;
@@ -390,14 +388,14 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
     avgHistLrtCompl = avgHistLrtCompl / ((float)self->modelUpdatePars[1]);
     avgSquareHistLrt = avgSquareHistLrt / ((float)self->modelUpdatePars[1]);
     fluctLrt = avgSquareHistLrt - avgHistLrt * avgHistLrtCompl;
-    // get threshold for lrt feature:
+    // Get threshold for LRT feature.
     if (fluctLrt < self->featureExtractionParams.thresFluctLrt) {
-      // very low fluct, so likely noise
+      // Very low fluctuation, so likely noise.
       self->priorModelPars[0] = self->featureExtractionParams.maxLrt;
     } else {
       self->priorModelPars[0] =
           self->featureExtractionParams.factor1ModelPars * avgHistLrt;
-      // check if value is within min/max range
+      // Check if value is within min/max range.
       if (self->priorModelPars[0] < self->featureExtractionParams.minLrt) {
         self->priorModelPars[0] = self->featureExtractionParams.minLrt;
       }
@@ -405,10 +403,10 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
         self->priorModelPars[0] = self->featureExtractionParams.maxLrt;
       }
     }
-    // done with lrt feature
+    // Done with LRT feature.
 
-    // for spectral flatness and spectral difference: compute the main peaks of
-    // histogram
+    // For spectral flatness and spectral difference: compute the main peaks of
+    // histogram.
     maxPeak1 = 0;
     maxPeak2 = 0;
     posPeak1SpecFlat = 0.0;
@@ -416,12 +414,12 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
     weightPeak1SpecFlat = 0;
     weightPeak2SpecFlat = 0;
 
-    // peaks for flatness
+    // Peaks for flatness.
     for (i = 0; i < HIST_PAR_EST; i++) {
       binMid =
           (i + 0.5f) * self->featureExtractionParams.binSizeSpecFlat;
       if (self->histSpecFlat[i] > maxPeak1) {
-        // Found new "first" peak
+        // Found new "first" peak.
         maxPeak2 = maxPeak1;
         weightPeak2SpecFlat = weightPeak1SpecFlat;
         posPeak2SpecFlat = posPeak1SpecFlat;
@@ -430,26 +428,26 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
         weightPeak1SpecFlat = self->histSpecFlat[i];
         posPeak1SpecFlat = binMid;
       } else if (self->histSpecFlat[i] > maxPeak2) {
-        // Found new "second" peak
+        // Found new "second" peak.
         maxPeak2 = self->histSpecFlat[i];
         weightPeak2SpecFlat = self->histSpecFlat[i];
         posPeak2SpecFlat = binMid;
       }
     }
 
-    // compute two peaks for spectral difference
+    // Compute two peaks for spectral difference.
     maxPeak1 = 0;
     maxPeak2 = 0;
     posPeak1SpecDiff = 0.0;
     posPeak2SpecDiff = 0.0;
     weightPeak1SpecDiff = 0;
     weightPeak2SpecDiff = 0;
-    // peaks for spectral difference
+    // Peaks for spectral difference.
     for (i = 0; i < HIST_PAR_EST; i++) {
       binMid =
           ((float)i + 0.5f) * self->featureExtractionParams.binSizeSpecDiff;
       if (self->histSpecDiff[i] > maxPeak1) {
-        // Found new "first" peak
+        // Found new "first" peak.
         maxPeak2 = maxPeak1;
         weightPeak2SpecDiff = weightPeak1SpecDiff;
         posPeak2SpecDiff = posPeak1SpecDiff;
@@ -458,16 +456,16 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
         weightPeak1SpecDiff = self->histSpecDiff[i];
         posPeak1SpecDiff = binMid;
       } else if (self->histSpecDiff[i] > maxPeak2) {
-        // Found new "second" peak
+        // Found new "second" peak.
         maxPeak2 = self->histSpecDiff[i];
         weightPeak2SpecDiff = self->histSpecDiff[i];
         posPeak2SpecDiff = binMid;
       }
     }
 
-    // for spectrum flatness feature
+    // For spectrum flatness feature.
     useFeatureSpecFlat = 1;
-    // merge the two peaks if they are close
+    // Merge the two peaks if they are close.
     if ((fabs(posPeak2SpecFlat - posPeak1SpecFlat) <
          self->featureExtractionParams.limitPeakSpacingSpecFlat) &&
         (weightPeak2SpecFlat >
@@ -476,18 +474,18 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
       weightPeak1SpecFlat += weightPeak2SpecFlat;
       posPeak1SpecFlat = 0.5f * (posPeak1SpecFlat + posPeak2SpecFlat);
     }
-    // reject if weight of peaks is not large enough, or peak value too small
+    // Reject if weight of peaks is not large enough, or peak value too small.
     if (weightPeak1SpecFlat <
             self->featureExtractionParams.thresWeightSpecFlat ||
         posPeak1SpecFlat < self->featureExtractionParams.thresPosSpecFlat) {
       useFeatureSpecFlat = 0;
     }
-    // if selected, get the threshold
+    // If selected, get the threshold.
     if (useFeatureSpecFlat == 1) {
-      // compute the threshold
+      // Compute the threshold.
       self->priorModelPars[1] =
           self->featureExtractionParams.factor2ModelPars * posPeak1SpecFlat;
-      // check if value is within min/max range
+      // Check if value is within min/max range.
       if (self->priorModelPars[1] < self->featureExtractionParams.minSpecFlat) {
         self->priorModelPars[1] = self->featureExtractionParams.minSpecFlat;
       }
@@ -495,11 +493,11 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
         self->priorModelPars[1] = self->featureExtractionParams.maxSpecFlat;
       }
     }
-    // done with flatness feature
+    // Done with flatness feature.
 
-    // for template feature
+    // For template feature.
     useFeatureSpecDiff = 1;
-    // merge the two peaks if they are close
+    // Merge the two peaks if they are close.
     if ((fabs(posPeak2SpecDiff - posPeak1SpecDiff) <
          self->featureExtractionParams.limitPeakSpacingSpecDiff) &&
         (weightPeak2SpecDiff >
@@ -508,39 +506,39 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
       weightPeak1SpecDiff += weightPeak2SpecDiff;
       posPeak1SpecDiff = 0.5f * (posPeak1SpecDiff + posPeak2SpecDiff);
     }
-    // get the threshold value
+    // Get the threshold value.
     self->priorModelPars[3] =
         self->featureExtractionParams.factor1ModelPars * posPeak1SpecDiff;
-    // reject if weight of peaks is not large enough
+    // Reject if weight of peaks is not large enough.
     if (weightPeak1SpecDiff <
         self->featureExtractionParams.thresWeightSpecDiff) {
       useFeatureSpecDiff = 0;
     }
-    // check if value is within min/max range
+    // Check if value is within min/max range.
     if (self->priorModelPars[3] < self->featureExtractionParams.minSpecDiff) {
       self->priorModelPars[3] = self->featureExtractionParams.minSpecDiff;
     }
     if (self->priorModelPars[3] > self->featureExtractionParams.maxSpecDiff) {
       self->priorModelPars[3] = self->featureExtractionParams.maxSpecDiff;
     }
-    // done with spectral difference feature
+    // Done with spectral difference feature.
 
-    // don't use template feature if fluctuation of lrt feature is very low:
-    //  most likely just noise state
+    // Don't use template feature if fluctuation of LRT feature is very low:
+    // most likely just noise state.
     if (fluctLrt < self->featureExtractionParams.thresFluctLrt) {
       useFeatureSpecDiff = 0;
     }
 
-    // select the weights between the features
-    // self->priorModelPars[4] is weight for lrt: always selected
-    // self->priorModelPars[5] is weight for spectral flatness
-    // self->priorModelPars[6] is weight for spectral difference
+    // Select the weights between the features.
+    // self->priorModelPars[4] is weight for LRT: always selected.
+    // self->priorModelPars[5] is weight for spectral flatness.
+    // self->priorModelPars[6] is weight for spectral difference.
     featureSum = (float)(1 + useFeatureSpecFlat + useFeatureSpecDiff);
     self->priorModelPars[4] = 1.f / featureSum;
     self->priorModelPars[5] = ((float)useFeatureSpecFlat) / featureSum;
     self->priorModelPars[6] = ((float)useFeatureSpecDiff) / featureSum;
 
-    // set hists to zero for next update
+    // Set hists to zero for next update.
     if (self->modelUpdatePars[0] >= 1) {
       for (i = 0; i < HIST_PAR_EST; i++) {
         self->histLrt[i] = 0;
@@ -548,26 +546,26 @@ static void FeatureParameterExtraction(NSinst_t* const self, int flag) {
         self->histSpecDiff[i] = 0;
       }
     }
-  }  // end of flag == 1
+  }  // End of flag == 1.
 }
 
-// Compute spectral flatness on input spectrum
-// magnIn is the magnitude spectrum
-// spectral flatness is returned in inst->featureData[0]
+// Compute spectral flatness on input spectrum.
+// |magnIn| is the magnitude spectrum.
+// Spectral flatness is returned in inst->featureData[0].
 static void ComputeSpectralFlatness(NSinst_t* const self, const float* magnIn) {
   int i;
-  int shiftLP = 1;  // option to remove first bin(s) from spectral measures
+  int shiftLP = 1;  // Option to remove first bin(s) from spectral measures.
   float avgSpectralFlatnessNum, avgSpectralFlatnessDen, spectralTmp;
 
-  // comute spectral measures
-  // for flatness
+  // Compute spectral measures.
+  // For flatness.
   avgSpectralFlatnessNum = 0.0;
   avgSpectralFlatnessDen = self->sumMagn;
   for (i = 0; i < shiftLP; i++) {
     avgSpectralFlatnessDen -= magnIn[i];
   }
-  // compute log of ratio of the geometric to arithmetic mean: check for log(0)
-  // case
+  // Compute log of ratio of the geometric to arithmetic mean: check for log(0)
+  // case.
   for (i = shiftLP; i < self->magnLen; i++) {
     if (magnIn[i] > 0.0) {
       avgSpectralFlatnessNum += (float)log(magnIn[i]);
@@ -576,19 +574,19 @@ static void ComputeSpectralFlatness(NSinst_t* const self, const float* magnIn) {
       return;
     }
   }
-  // normalize
+  // Normalize.
   avgSpectralFlatnessDen = avgSpectralFlatnessDen / self->magnLen;
   avgSpectralFlatnessNum = avgSpectralFlatnessNum / self->magnLen;
 
-  // ratio and inverse log: check for case of log(0)
+  // Ratio and inverse log: check for case of log(0).
   spectralTmp = (float)exp(avgSpectralFlatnessNum) / avgSpectralFlatnessDen;
 
-  // time-avg update of spectral flatness feature
+  // Time-avg update of spectral flatness feature.
   self->featureData[0] += SPECT_FL_TAVG * (spectralTmp - self->featureData[0]);
-  // done with flatness feature
+  // Done with flatness feature.
 }
 
-// Compute prior and post snr based on quantile noise estimation.
+// Compute prior and post SNR based on quantile noise estimation.
 // Compute DD estimate of prior SNR.
 // Inputs:
 //   * |magn| is the signal magnitude spectrum estimate.
@@ -613,18 +611,18 @@ static void ComputeSnr(const NSinst_t* const self,
     if (magn[i] > noise[i]) {
       snrLocPost[i] = magn[i] / (noise[i] + 0.0001f) - 1.f;
     }
-    // DD estimate is sum of two terms: current estimate and previous estimate
-    // directed decision update of snrPrior.
+    // DD estimate is sum of two terms: current estimate and previous estimate.
+    // Directed decision update of snrPrior.
     snrLocPrior[i] =
         DD_PR_SNR * previousEstimateStsa + (1.f - DD_PR_SNR) * snrLocPost[i];
   }  // End of loop over frequencies.
 }
 
 // Compute the difference measure between input spectrum and a template/learned
-// noise spectrum
-// magnIn is the input spectrum
-// the reference/template spectrum is inst->magnAvgPause[i]
-// returns (normalized) spectral difference in inst->featureData[4]
+// noise spectrum.
+// |magnIn| is the input spectrum.
+// The reference/template spectrum is inst->magnAvgPause[i].
+// Returns (normalized) spectral difference in inst->featureData[4].
 static void ComputeSpectralDifference(NSinst_t* const self,
                                       const float* magnIn) {
   // avgDiffNormMagn = var(magnIn) - cov(magnIn, magnAvgPause)^2 /
@@ -634,9 +632,9 @@ static void ComputeSpectralDifference(NSinst_t* const self,
 
   avgPause = 0.0;
   avgMagn = self->sumMagn;
-  // compute average quantities
+  // Compute average quantities.
   for (i = 0; i < self->magnLen; i++) {
-    // conservative smooth noise spectrum from pause frames
+    // Conservative smooth noise spectrum from pause frames.
     avgPause += self->magnAvgPause[i];
   }
   avgPause = avgPause / ((float)self->magnLen);
@@ -645,7 +643,7 @@ static void ComputeSpectralDifference(NSinst_t* const self,
   covMagnPause = 0.0;
   varPause = 0.0;
   varMagn = 0.0;
-  // compute variance and covariance quantities
+  // Compute variance and covariance quantities.
   for (i = 0; i < self->magnLen; i++) {
     covMagnPause += (magnIn[i] - avgMagn) * (self->magnAvgPause[i] - avgPause);
     varPause +=
@@ -655,23 +653,23 @@ static void ComputeSpectralDifference(NSinst_t* const self,
   covMagnPause = covMagnPause / ((float)self->magnLen);
   varPause = varPause / ((float)self->magnLen);
   varMagn = varMagn / ((float)self->magnLen);
-  // update of average magnitude spectrum
+  // Update of average magnitude spectrum.
   self->featureData[6] += self->signalEnergy;
 
   avgDiffNormMagn =
       varMagn - (covMagnPause * covMagnPause) / (varPause + 0.0001f);
-  // normalize and compute time-avg update of difference feature
+  // Normalize and compute time-avg update of difference feature.
   avgDiffNormMagn = (float)(avgDiffNormMagn / (self->featureData[5] + 0.0001f));
   self->featureData[4] +=
       SPECT_DIFF_TAVG * (avgDiffNormMagn - self->featureData[4]);
 }
 
-// Compute speech/noise probability
-// speech/noise probability is returned in: probSpeechFinal
-// magn is the input magnitude spectrum
-// noise is the noise spectrum
-// snrLocPrior is the prior snr for each freq.
-// snr loc_post is the post snr for each freq.
+// Compute speech/noise probability.
+// Speech/noise probability is returned in |probSpeechFinal|.
+// |magn| is the input magnitude spectrum.
+// |noise| is the noise spectrum.
+// |snrLocPrior| is the prior SNR for each frequency.
+// |snrLocPost| is the post SNR for each frequency.
 static void SpeechNoiseProb(NSinst_t* const self,
                             float* probSpeechFinal,
                             const float* snrLocPrior,
@@ -686,25 +684,25 @@ static void SpeechNoiseProb(NSinst_t* const self,
   float widthPrior, widthPrior0, widthPrior1, widthPrior2;
 
   widthPrior0 = WIDTH_PR_MAP;
-  widthPrior1 = 2.f * WIDTH_PR_MAP;  // width for pause region:
-  // lower range, so increase width in tanh map
-  widthPrior2 = 2.f * WIDTH_PR_MAP;  // for spectral-difference measure
+  // Width for pause region: lower range, so increase width in tanh map.
+  widthPrior1 = 2.f * WIDTH_PR_MAP;
+  widthPrior2 = 2.f * WIDTH_PR_MAP;  // For spectral-difference measure.
 
-  // threshold parameters for features
+  // Threshold parameters for features.
   threshPrior0 = self->priorModelPars[0];
   threshPrior1 = self->priorModelPars[1];
   threshPrior2 = self->priorModelPars[3];
 
-  // sign for flatness feature
+  // Sign for flatness feature.
   sgnMap = (int)(self->priorModelPars[2]);
 
-  // weight parameters for features
+  // Weight parameters for features.
   weightIndPrior0 = self->priorModelPars[4];
   weightIndPrior1 = self->priorModelPars[5];
   weightIndPrior2 = self->priorModelPars[6];
 
-  // compute feature based on average LR factor
-  // this is the average over all frequencies of the smooth log lrt
+  // Compute feature based on average LR factor.
+  // This is the average over all frequencies of the smooth log LRT.
   logLrtTimeAvgKsum = 0.0;
   for (i = 0; i < self->magnLen; i++) {
     tmpFloat1 = 1.f + 2.f * snrLocPrior[i];
@@ -716,58 +714,55 @@ static void SpeechNoiseProb(NSinst_t* const self,
   }
   logLrtTimeAvgKsum = (float)logLrtTimeAvgKsum / (self->magnLen);
   self->featureData[3] = logLrtTimeAvgKsum;
-  // done with computation of LR factor
+  // Done with computation of LR factor.
 
-  //
-  // compute the indicator functions
-  //
-
-  // average lrt feature
+  // Compute the indicator functions.
+  // Average LRT feature.
   widthPrior = widthPrior0;
-  // use larger width in tanh map for pause regions
+  // Use larger width in tanh map for pause regions.
   if (logLrtTimeAvgKsum < threshPrior0) {
     widthPrior = widthPrior1;
   }
-  // compute indicator function: sigmoid map
+  // Compute indicator function: sigmoid map.
   indicator0 =
       0.5f *
       ((float)tanh(widthPrior * (logLrtTimeAvgKsum - threshPrior0)) + 1.f);
 
-  // spectral flatness feature
+  // Spectral flatness feature.
   tmpFloat1 = self->featureData[0];
   widthPrior = widthPrior0;
-  // use larger width in tanh map for pause regions
+  // Use larger width in tanh map for pause regions.
   if (sgnMap == 1 && (tmpFloat1 > threshPrior1)) {
     widthPrior = widthPrior1;
   }
   if (sgnMap == -1 && (tmpFloat1 < threshPrior1)) {
     widthPrior = widthPrior1;
   }
-  // compute indicator function: sigmoid map
+  // Compute indicator function: sigmoid map.
   indicator1 =
       0.5f *
       ((float)tanh((float)sgnMap * widthPrior * (threshPrior1 - tmpFloat1)) +
        1.f);
 
-  // for template spectrum-difference
+  // For template spectrum-difference.
   tmpFloat1 = self->featureData[4];
   widthPrior = widthPrior0;
-  // use larger width in tanh map for pause regions
+  // Use larger width in tanh map for pause regions.
   if (tmpFloat1 < threshPrior2) {
     widthPrior = widthPrior2;
   }
-  // compute indicator function: sigmoid map
+  // Compute indicator function: sigmoid map.
   indicator2 =
       0.5f * ((float)tanh(widthPrior * (tmpFloat1 - threshPrior2)) + 1.f);
 
-  // combine the indicator function with the feature weights
+  // Combine the indicator function with the feature weights.
   indPrior = weightIndPrior0 * indicator0 + weightIndPrior1 * indicator1 +
              weightIndPrior2 * indicator2;
-  // done with computing indicator function
+  // Done with computing indicator function.
 
-  // compute the prior probability
+  // Compute the prior probability.
   self->priorSpeechProb += PRIOR_UPDATE * (indPrior - self->priorSpeechProb);
-  // make sure probabilities are within range: keep floor to 0.01
+  // Make sure probabilities are within range: keep floor to 0.01.
   if (self->priorSpeechProb > 1.f) {
     self->priorSpeechProb = 1.f;
   }
@@ -775,7 +770,7 @@ static void SpeechNoiseProb(NSinst_t* const self,
     self->priorSpeechProb = 0.01f;
   }
 
-  // final speech probability: combine prior model with LR factor:
+  // Final speech probability: combine prior model with LR factor:.
   gainPrior = (1.f - self->priorSpeechProb) / (self->priorSpeechProb + 0.0001f);
   for (i = 0; i < self->magnLen; i++) {
     invLrt = (float)exp(-self->logLrtTimeAvg[i]);
@@ -853,7 +848,6 @@ static void UpdateNoiseEstimate(NSinst_t* const self,
     noiseUpdateTmp = gammaNoiseTmp * self->noisePrev[i] +
                      (1.f - gammaNoiseTmp) * (probNonSpeech * magn[i] +
                                               probSpeech * self->noisePrev[i]);
-    //
     // Time-constant based on speech/noise state.
     gammaNoiseOld = gammaNoiseTmp;
     gammaNoiseTmp = NOISE_UPDATE;
@@ -1055,7 +1049,7 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
   float magn[HALF_ANAL_BLOCKL], noise[HALF_ANAL_BLOCKL];
   float snrLocPost[HALF_ANAL_BLOCKL], snrLocPrior[HALF_ANAL_BLOCKL];
   float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL];
-  // Variables during startup
+  // Variables during startup.
   float sum_log_i = 0.0;
   float sum_log_i_square = 0.0;
   float sum_log_magn = 0.0;
@@ -1063,22 +1057,19 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
   float parametric_exp = 0.0;
   float parametric_num = 0.0;
 
-  // Check that initiation has been done
+  // Check that initiation has been done.
   if (inst->initFlag != 1) {
     return (-1);
   }
-  //
   updateParsFlag = inst->modelUpdatePars[0];
-  //
 
-  // update analysis buffer for L band
+  // Update analysis buffer for L band.
   UpdateBuffer(speechFrame, inst->blockLen, inst->anaLen, inst->analyzeBuf);
 
-  // windowing
   Windowing(inst->window, inst->analyzeBuf, inst->anaLen, winData);
   energy = Energy(winData, inst->anaLen);
   if (energy == 0.0) {
-    // we want to avoid updating statistics in this case:
+    // We want to avoid updating statistics in this case:
     // Updating feature statistics when we have zeros only will cause
     // thresholds to move towards zero signal situations. This in turn has the
     // effect that once the signal is "turned on" (non-zero values) everything
@@ -1089,9 +1080,8 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
     return 0;
   }
 
-  //
   inst->blockInd++;  // Update the block index only when we process a block.
-  // FFT
+
   FFT(inst, winData, inst->anaLen, inst->magnLen, real, imag, magn);
 
   for (i = 0; i < inst->magnLen; i++) {
@@ -1112,19 +1102,19 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
   inst->signalEnergy = signalEnergy;
   inst->sumMagn = sumMagn;
 
-  // quantile noise estimate
+  // Quantile noise estimate.
   WebRtcNs_NoiseEstimation(inst, magn, noise);
-  // compute simplified noise model during startup
+  // Compute simplified noise model during startup.
   if (inst->blockInd < END_STARTUP_SHORT) {
-    // Estimate White noise
+    // Estimate White noise.
     inst->whiteNoiseLevel += sumMagn / ((float)inst->magnLen) * inst->overdrive;
-    // Estimate Pink noise parameters
+    // Estimate Pink noise parameters.
     tmpFloat1 = sum_log_i_square * ((float)(inst->magnLen - kStartBand));
     tmpFloat1 -= (sum_log_i * sum_log_i);
     tmpFloat2 =
         (sum_log_i_square * sum_log_magn - sum_log_i * sum_log_i_log_magn);
     tmpFloat3 = tmpFloat2 / tmpFloat1;
-    // Constrain the estimated spectrum to be positive
+    // Constrain the estimated spectrum to be positive.
     if (tmpFloat3 < 0.f) {
       tmpFloat3 = 0.f;
     }
@@ -1132,7 +1122,7 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
     tmpFloat2 = (sum_log_i * sum_log_magn);
     tmpFloat2 -= ((float)(inst->magnLen - kStartBand)) * sum_log_i_log_magn;
     tmpFloat3 = tmpFloat2 / tmpFloat1;
-    // Constrain the pink noise power to be in the interval [0, 1];
+    // Constrain the pink noise power to be in the interval [0, 1].
     if (tmpFloat3 < 0.f) {
       tmpFloat3 = 0.f;
     }
@@ -1143,7 +1133,7 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
 
     // Calculate frequency independent parts of parametric noise estimate.
     if (inst->pinkNoiseExp > 0.f) {
-      // Use pink noise estimate
+      // Use pink noise estimate.
       parametric_num =
           exp(inst->pinkNoiseNumerator / (float)(inst->blockInd + 1));
       parametric_num *= (float)(inst->blockInd + 1);
@@ -1151,17 +1141,17 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
     }
     for (i = 0; i < inst->magnLen; i++) {
       // Estimate the background noise using the white and pink noise
-      // parameters
+      // parameters.
       if (inst->pinkNoiseExp == 0.f) {
-        // Use white noise estimate
+        // Use white noise estimate.
         inst->parametricNoise[i] = inst->whiteNoiseLevel;
       } else {
-        // Use pink noise estimate
+        // Use pink noise estimate.
         float use_band = (float)(i < kStartBand ? kStartBand : i);
         inst->parametricNoise[i] =
             parametric_num / pow(use_band, parametric_exp);
       }
-      // Weight quantile noise with modeled noise
+      // Weight quantile noise with modeled noise.
       noise[i] *= (inst->blockInd);
       tmpFloat2 =
           inst->parametricNoise[i] * (END_STARTUP_SHORT - inst->blockInd);
@@ -1169,22 +1159,22 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
       noise[i] /= END_STARTUP_SHORT;
     }
   }
-  // compute average signal during END_STARTUP_LONG time:
-  // used to normalize spectral difference measure
+  // Compute average signal during END_STARTUP_LONG time:
+  // used to normalize spectral difference measure.
   if (inst->blockInd < END_STARTUP_LONG) {
     inst->featureData[5] *= inst->blockInd;
     inst->featureData[5] += signalEnergy;
     inst->featureData[5] /= (inst->blockInd + 1);
   }
 
-  // Post and prior SNR needed for WebRtcNs_SpeechNoiseProb.
+  // Post and prior SNR needed for SpeechNoiseProb.
   ComputeSnr(inst, magn, noise, snrLocPrior, snrLocPost);
 
   FeatureUpdate(inst, magn, updateParsFlag);
   SpeechNoiseProb(inst, inst->speechProb, snrLocPrior, snrLocPost);
   UpdateNoiseEstimate(inst, magn, snrLocPrior, snrLocPost, noise);
 
-  // keep track of noise spectrum for next frame
+  // Keep track of noise spectrum for next frame.
   memcpy(inst->noise, noise, sizeof(*noise) * inst->magnLen);
   memcpy(inst->magnPrevAnalyze, magn, sizeof(*magn) * inst->magnLen);
 
@@ -1196,7 +1186,7 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
                          float* speechFrameHB,
                          float* outFrame,
                          float* outFrameHB) {
-  // main routine for noise reduction
+  // Main routine for noise reduction.
   int flagHB = 0;
   int i;
 
@@ -1207,7 +1197,7 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
   float theFilter[HALF_ANAL_BLOCKL], theFilterTmp[HALF_ANAL_BLOCKL];
   float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL];
 
-  // SWB variables
+  // SWB variables.
   int deltaBweHB = 1;
   int deltaGainHB = 1;
   float decayBweHB = 1.0;
@@ -1216,46 +1206,45 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
   float avgProbSpeechHB, avgProbSpeechHBTmp, avgFilterGainHB, gainModHB;
   float sumMagnAnalyze, sumMagnProcess;
 
-  // Check that initiation has been done
+  // Check that initiation has been done.
   if (inst->initFlag != 1) {
     return (-1);
   }
-  // Check for valid pointers based on sampling rate
+  // Check for valid pointers based on sampling rate.
   if (inst->fs == 32000) {
     if (speechFrameHB == NULL) {
       return -1;
     }
     flagHB = 1;
-    // range for averaging low band quantities for H band gain
+    // Range for averaging low band quantities for H band gain.
     deltaBweHB = (int)inst->magnLen / 4;
     deltaGainHB = deltaBweHB;
   }
 
-  // update analysis buffer for L band
+  // Update analysis buffer for L band.
   UpdateBuffer(speechFrame, inst->blockLen, inst->anaLen, inst->dataBuf);
 
   if (flagHB == 1) {
-    // update analysis buffer for H band
+    // Update analysis buffer for H band.
     UpdateBuffer(speechFrameHB, inst->blockLen, inst->anaLen, inst->dataBufHB);
   }
 
-  // windowing
   Windowing(inst->window, inst->dataBuf, inst->anaLen, winData);
   energy1 = Energy(winData, inst->anaLen);
   if (energy1 == 0.0) {
-    // synthesize the special case of zero input
-    // read out fully processed segment
+    // Synthesize the special case of zero input.
+    // Read out fully processed segment.
     for (i = inst->windShift; i < inst->blockLen + inst->windShift; i++) {
       fout[i - inst->windShift] = inst->syntBuf[i];
     }
-    // update synthesis buffer
+    // Update synthesis buffer.
     UpdateBuffer(NULL, inst->blockLen, inst->anaLen, inst->syntBuf);
 
     for (i = 0; i < inst->blockLen; ++i)
       outFrame[i] =
           WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
 
-    // for time-domain gain of HB
+    // For time-domain gain of HB.
     if (flagHB == 1)
       for (i = 0; i < inst->blockLen; ++i)
         outFrameHB[i] = WEBRTC_SPL_SAT(
@@ -1263,7 +1252,7 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
 
     return 0;
   }
-  // FFT
+
   FFT(inst, winData, inst->anaLen, inst->magnLen, real, imag, magn);
 
   if (inst->blockInd < END_STARTUP_SHORT) {
@@ -1275,11 +1264,11 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
   ComputeDdBasedWienerFilter(inst, magn, theFilter);
 
   for (i = 0; i < inst->magnLen; i++) {
-    // flooring bottom
+    // Flooring bottom.
     if (theFilter[i] < inst->denoiseBound) {
       theFilter[i] = inst->denoiseBound;
     }
-    // flooring top
+    // Flooring top.
     if (theFilter[i] > 1.f) {
       theFilter[i] = 1.f;
     }
@@ -1287,32 +1276,32 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
       theFilterTmp[i] =
           (inst->initMagnEst[i] - inst->overdrive * inst->parametricNoise[i]);
       theFilterTmp[i] /= (inst->initMagnEst[i] + 0.0001f);
-      // flooring bottom
+      // Flooring bottom.
       if (theFilterTmp[i] < inst->denoiseBound) {
         theFilterTmp[i] = inst->denoiseBound;
       }
-      // flooring top
+      // Flooring top.
       if (theFilterTmp[i] > 1.f) {
         theFilterTmp[i] = 1.f;
       }
-      // Weight the two suppression filters
+      // Weight the two suppression filters.
       theFilter[i] *= (inst->blockInd);
       theFilterTmp[i] *= (END_STARTUP_SHORT - inst->blockInd);
       theFilter[i] += theFilterTmp[i];
       theFilter[i] /= (END_STARTUP_SHORT);
     }
-    // smoothing
+
     inst->smooth[i] = theFilter[i];
     real[i] *= inst->smooth[i];
     imag[i] *= inst->smooth[i];
   }
-  // keep track of magn spectrum for next frame
+  // Keep track of |magn| spectrum for next frame.
   memcpy(inst->magnPrevProcess, magn, sizeof(*magn) * inst->magnLen);
   memcpy(inst->noisePrev, inst->noise, sizeof(inst->noise[0]) * inst->magnLen);
-  // back to time domain
+  // Back to time domain.
   IFFT(inst, real, imag, inst->magnLen, inst->anaLen, winData);
 
-  // scale factor: only do it after END_STARTUP_LONG time
+  // Scale factor: only do it after END_STARTUP_LONG time.
   factor = 1.f;
   if (inst->gainmap == 1 && inst->blockInd > END_STARTUP_LONG) {
     factor1 = 1.f;
@@ -1321,7 +1310,7 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
     energy2 = Energy(winData, inst->anaLen);
     gain = (float)sqrt(energy2 / (energy1 + 1.f));
 
-    // scaling for new version
+    // Scaling for new version.
     if (gain > B_LIM) {
       factor1 = 1.f + 1.3f * (gain - B_LIM);
       if (gain * factor1 > 1.f) {
@@ -1329,40 +1318,40 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
       }
     }
     if (gain < B_LIM) {
-      // don't reduce scale too much for pause regions:
-      // attenuation here should be controlled by flooring
+      // Don't reduce scale too much for pause regions:
+      // attenuation here should be controlled by flooring.
       if (gain <= inst->denoiseBound) {
         gain = inst->denoiseBound;
       }
       factor2 = 1.f - 0.3f * (B_LIM - gain);
     }
-    // combine both scales with speech/noise prob:
-    // note prior (priorSpeechProb) is not frequency dependent
+    // Combine both scales with speech/noise prob:
+    // note prior (priorSpeechProb) is not frequency dependent.
     factor = inst->priorSpeechProb * factor1 +
              (1.f - inst->priorSpeechProb) * factor2;
-  }  // out of inst->gainmap==1
+  }  // Out of inst->gainmap == 1.
 
   Windowing(inst->window, winData, inst->anaLen, winData);
 
-  // synthesis
+  // Synthesis.
   for (i = 0; i < inst->anaLen; i++) {
     inst->syntBuf[i] += factor * winData[i];
   }
-  // read out fully processed segment
+  // Read out fully processed segment.
   for (i = inst->windShift; i < inst->blockLen + inst->windShift; i++) {
     fout[i - inst->windShift] = inst->syntBuf[i];
   }
-  // update synthesis buffer
+  // Update synthesis buffer.
   UpdateBuffer(NULL, inst->blockLen, inst->anaLen, inst->syntBuf);
 
   for (i = 0; i < inst->blockLen; ++i)
     outFrame[i] =
         WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
 
-  // for time-domain gain of HB
+  // For time-domain gain of HB.
   if (flagHB == 1) {
-    // average speech prob from low band
-    // avg over second half (i.e., 4->8kHz) of freq. spectrum
+    // Average speech prob from low band.
+    // Average over second half (i.e., 4->8kHz) of frequencies spectrum.
     avgProbSpeechHB = 0.0;
     for (i = inst->magnLen - deltaBweHB - 1; i < inst->magnLen - 1; i++) {
       avgProbSpeechHB += inst->speechProb[i];
@@ -1378,39 +1367,38 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
       sumMagnProcess += inst->magnPrevProcess[i];
     }
     avgProbSpeechHB *= sumMagnProcess / sumMagnAnalyze;
-    // average filter gain from low band
-    // average over second half (i.e., 4->8kHz) of freq. spectrum
+    // Average filter gain from low band.
+    // Average over second half (i.e., 4->8kHz) of frequencies spectrum.
     avgFilterGainHB = 0.0;
     for (i = inst->magnLen - deltaGainHB - 1; i < inst->magnLen - 1; i++) {
       avgFilterGainHB += inst->smooth[i];
     }
     avgFilterGainHB = avgFilterGainHB / ((float)(deltaGainHB));
     avgProbSpeechHBTmp = 2.f * avgProbSpeechHB - 1.f;
-    // gain based on speech prob:
+    // Gain based on speech probability.
     gainModHB = 0.5f * (1.f + (float)tanh(gainMapParHB * avgProbSpeechHBTmp));
-    // combine gain with low band gain
+    // Combine gain with low band gain.
     gainTimeDomainHB = 0.5f * gainModHB + 0.5f * avgFilterGainHB;
     if (avgProbSpeechHB >= 0.5f) {
       gainTimeDomainHB = 0.25f * gainModHB + 0.75f * avgFilterGainHB;
     }
     gainTimeDomainHB = gainTimeDomainHB * decayBweHB;
-    // make sure gain is within flooring range
-    // flooring bottom
+    // Make sure gain is within flooring range.
+    // Flooring bottom.
     if (gainTimeDomainHB < inst->denoiseBound) {
       gainTimeDomainHB = inst->denoiseBound;
     }
-    // flooring top
+    // Flooring top.
     if (gainTimeDomainHB > 1.f) {
       gainTimeDomainHB = 1.f;
     }
-    // apply gain
+    // Apply gain.
     for (i = 0; i < inst->blockLen; i++) {
       float o = gainTimeDomainHB * inst->dataBufHB[i];
       outFrameHB[i] =
           WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, o, WEBRTC_SPL_WORD16_MIN);
     }
-  }  // end of H band gain computation
-  //
+  }  // End of H band gain computation.
 
   return 0;
 }
diff --git a/webrtc/modules/audio_processing/ns/ns_core.h b/webrtc/modules/audio_processing/ns/ns_core.h
index a4718fb3d..601f40ba6 100644
--- a/webrtc/modules/audio_processing/ns/ns_core.h
+++ b/webrtc/modules/audio_processing/ns/ns_core.h
@@ -14,36 +14,36 @@
 #include "webrtc/modules/audio_processing/ns/defines.h"
 
 typedef struct NSParaExtract_t_ {
-  // bin size of histogram
+  // Bin size of histogram.
   float binSizeLrt;
   float binSizeSpecFlat;
   float binSizeSpecDiff;
-  // range of histogram over which lrt threshold is computed
+  // Range of histogram over which LRT threshold is computed.
   float rangeAvgHistLrt;
-  // scale parameters: multiply dominant peaks of the histograms by scale factor
-  // to obtain thresholds for prior model
-  float factor1ModelPars;  // for lrt and spectral difference
-  float factor2ModelPars;  // for spectral_flatness: used when noise is flatter
-                           // than speech
-  // peak limit for spectral flatness (varies between 0 and 1)
+  // Scale parameters: multiply dominant peaks of the histograms by scale factor
+  // to obtain thresholds for prior model.
+  float factor1ModelPars;  // For LRT and spectral difference.
+  float factor2ModelPars;  // For spectral_flatness: used when noise is flatter
+                           // than speech.
+  // Peak limit for spectral flatness (varies between 0 and 1).
   float thresPosSpecFlat;
-  // limit on spacing of two highest peaks in histogram: spacing determined by
-  // bin size
+  // Limit on spacing of two highest peaks in histogram: spacing determined by
+  // bin size.
   float limitPeakSpacingSpecFlat;
   float limitPeakSpacingSpecDiff;
-  // limit on relevance of second peak:
+  // Limit on relevance of second peak.
   float limitPeakWeightsSpecFlat;
   float limitPeakWeightsSpecDiff;
-  // limit on fluctuation of lrt feature
+  // Limit on fluctuation of LRT feature.
   float thresFluctLrt;
-  // limit on the max and min values for the feature thresholds
+  // Limit on the max and min values for the feature thresholds.
   float maxLrt;
   float minLrt;
   float maxSpecFlat;
   float minSpecFlat;
   float maxSpecDiff;
   float minSpecDiff;
-  // criteria of weight of histogram peak  to accept/reject feature
+  // Criteria of weight of histogram peak to accept/reject feature.
   int thresWeightSpecFlat;
   int thresWeightSpecDiff;
 
@@ -62,51 +62,53 @@ typedef struct NSinst_t_ {
   float syntBuf[ANAL_BLOCKL_MAX];
 
   int initFlag;
-  // parameters for quantile noise estimation
+  // Parameters for quantile noise estimation.
   float density[SIMULT * HALF_ANAL_BLOCKL];
   float lquantile[SIMULT * HALF_ANAL_BLOCKL];
   float quantile[HALF_ANAL_BLOCKL];
   int counter[SIMULT];
   int updates;
-  // parameters for Wiener filter
+  // Parameters for Wiener filter.
   float smooth[HALF_ANAL_BLOCKL];
   float overdrive;
   float denoiseBound;
   int gainmap;
-  // fft work arrays.
+  // FFT work arrays.
   int ip[IP_LENGTH];
   float wfft[W_LENGTH];
 
-  // parameters for new method: some not needed, will reduce/cleanup later
-  int32_t blockInd;  // frame index counter
-  int modelUpdatePars[4];  // parameters for updating or estimating
-  // thresholds/weights for prior model
-  float priorModelPars[7];  // parameters for prior model
-  float noise[HALF_ANAL_BLOCKL];      // noise spectrum from current frame
-  float noisePrev[HALF_ANAL_BLOCKL];  // noise spectrum from previous frame
-  // magnitude spectrum of previous analyze frame
+  // Parameters for new method: some not needed, will reduce/cleanup later.
+  int32_t blockInd;  // Frame index counter.
+  int modelUpdatePars[4];  // Parameters for updating or estimating.
+  // Thresholds/weights for prior model.
+  float priorModelPars[7];  // Parameters for prior model.
+  float noise[HALF_ANAL_BLOCKL];  // Noise spectrum from current frame.
+  float noisePrev[HALF_ANAL_BLOCKL];  // Noise spectrum from previous frame.
+  // Magnitude spectrum of previous analyze frame.
   float magnPrevAnalyze[HALF_ANAL_BLOCKL];
-  // magnitude spectrum of previous process frame
+  // Magnitude spectrum of previous process frame.
   float magnPrevProcess[HALF_ANAL_BLOCKL];
-  float logLrtTimeAvg[HALF_ANAL_BLOCKL];  // log lrt factor with time-smoothing
-  float priorSpeechProb;  // prior speech/noise probability
-  float featureData[7];  // data for features
-  float magnAvgPause[HALF_ANAL_BLOCKL];  // conservative noise spectrum estimate
-  float signalEnergy;  // energy of magn
-  float sumMagn;  // sum of magn
-  float whiteNoiseLevel;  // initial noise estimate
-  float initMagnEst[HALF_ANAL_BLOCKL];  // initial magnitude spectrum estimate
-  float pinkNoiseNumerator;  // pink noise parameter: numerator
-  float pinkNoiseExp;  // pink noise parameter: power of freq
+  float logLrtTimeAvg[HALF_ANAL_BLOCKL];  // Log LRT factor with time-smoothing.
+  float priorSpeechProb;  // Prior speech/noise probability.
+  float featureData[7];
+  // Conservative noise spectrum estimate.
+  float magnAvgPause[HALF_ANAL_BLOCKL];
+  float signalEnergy;  // Energy of |magn|.
+  float sumMagn;
+  float whiteNoiseLevel;  // Initial noise estimate.
+  float initMagnEst[HALF_ANAL_BLOCKL];  // Initial magnitude spectrum estimate.
+  float pinkNoiseNumerator;  // Pink noise parameter: numerator.
+  float pinkNoiseExp;  // Pink noise parameter: power of frequencies.
   float parametricNoise[HALF_ANAL_BLOCKL];
-  NSParaExtract_t featureExtractionParams;  // parameters for feature extraction
-  // histograms for parameter estimation
+  // Parameters for feature extraction.
+  NSParaExtract_t featureExtractionParams;
+  // Histograms for parameter estimation.
   int histLrt[HIST_PAR_EST];
   int histSpecFlat[HIST_PAR_EST];
   int histSpecDiff[HIST_PAR_EST];
-  // quantities for high band estimate
-  float speechProb[HALF_ANAL_BLOCKL];  // final speech/noise prob: prior + LRT
-  float dataBufHB[ANAL_BLOCKL_MAX];  // buffering data for HB
+  // Quantities for high band estimate.
+  float speechProb[HALF_ANAL_BLOCKL];  // Final speech/noise prob: prior + LRT.
+  float dataBufHB[ANAL_BLOCKL_MAX];  // Buffering data for HB.
 
 } NSinst_t;