pure sdk for main

This commit is contained in:
divadiow
2025-08-27 09:51:58 +01:00
parent f0d033f1c9
commit 0571416e7c
3283 changed files with 1577720 additions and 1 deletions
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_DEFINES_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_DEFINES_H_
//#define PROCESS_FLOW_0 // Use the traditional method.
//#define PROCESS_FLOW_1 // Use traditional with DD estimate of prior SNR.
#define PROCESS_FLOW_2 // Use the new method of speech/noise classification.
#define BLOCKL_MAX 160 // max processing block length: 160
#define ANAL_BLOCKL_MAX 256 // max analysis block length: 256
#define HALF_ANAL_BLOCKL 129 // half max analysis block length + 1
#define QUANTILE (float)0.25
#define SIMULT 3
#define END_STARTUP_LONG 200
#define END_STARTUP_SHORT 50
#define FACTOR (float)40.0
#define WIDTH (float)0.01
#define SMOOTH (float)0.75 // filter smoothing
// Length of fft work arrays.
#define IP_LENGTH (ANAL_BLOCKL_MAX >> 1) // must be at least ceil(2 + sqrt(ANAL_BLOCKL_MAX/2))
#define W_LENGTH (ANAL_BLOCKL_MAX >> 1)
//PARAMETERS FOR NEW METHOD
#define DD_PR_SNR (float)0.98 // DD update of prior SNR
#define LRT_TAVG (float)0.50 // tavg parameter for LRT (previously 0.90)
#define SPECT_FL_TAVG (float)0.30 // tavg parameter for spectral flatness measure
#define SPECT_DIFF_TAVG (float)0.30 // tavg parameter for spectral difference measure
#define PRIOR_UPDATE (float)0.10 // update parameter of prior model
#define NOISE_UPDATE (float)0.90 // update parameter for noise
#define SPEECH_UPDATE (float)0.99 // update parameter when likely speech
#define WIDTH_PR_MAP (float)4.0 // width parameter in sigmoid map for prior model
#define LRT_FEATURE_THR (float)0.5 // default threshold for LRT feature
#define SF_FEATURE_THR (float)0.5 // default threshold for Spectral Flatness feature
#define SD_FEATURE_THR (float)0.5 // default threshold for Spectral Difference feature
#define PROB_RANGE (float)0.20 // probability threshold for noise state in
// speech/noise likelihood
#define HIST_PAR_EST 1000 // histogram size for estimation of parameters
#define GAMMA_PAUSE (float)0.05 // update for conservative noise estimate
//
#define B_LIM (float)0.5 // threshold in final energy gain factor calculation
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_DEFINES_H_
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "noise_suppression_x.h"
#include "common_audio/signal_processing/include/real_fft.h"
#include "nsx_core.h"
#include "nsx_defines.h"
//NoiseSuppressionFixedC noise_suppression_ctl;
NsxHandle* WebRtcNsx_Create()
{
NoiseSuppressionFixedC *noise_suppression_ctl = (NoiseSuppressionFixedC*)webrtc_zalloc(sizeof(NoiseSuppressionFixedC));
return (NsxHandle*)noise_suppression_ctl;
}
int WebRtcNsx_Init(NsxHandle* nsxInst, u32 fs)
{
return WebRtcNsx_InitCore((NoiseSuppressionFixedC*) nsxInst);
}
//int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode)
//{
// return WebRtcNsx_set_policy_core((NoiseSuppressionFixedC*) nsxInst, mode);
//}
void WebRtcNsx_Process(NsxHandle* nsxInst,
short* speechFrame,
int num_bands,
short* outFrame)
{
WebRtcNsx_ProcessCore((NoiseSuppressionFixedC*) nsxInst, speechFrame,
num_bands, outFrame);
}
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_X_H_
#define MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_X_H_
#include "typedefs.h" // NOLINT(build/include)
typedef struct NsxHandleT NsxHandle;
/*
* This function creates an instance of the fixed point Noise Suppression.
*/
NsxHandle* WebRtcNsx_Create();
/*
* This function initializes a NS instance
*
* Input:
* - nsxInst : Instance that should be initialized
* - fs : sampling frequency
*
* Output:
* - nsxInst : Initialized instance
*
* Return value : 0 - Ok
* -1 - Error
*/
int WebRtcNsx_Init(NsxHandle* nsxInst, u32 fs);
/*
* This changes the aggressiveness of the noise suppression method.
*
* Input:
* - nsxInst : Instance that should be initialized
* - mode : 0: Mild, 1: Medium , 2: Aggressive
*
* Output:
* - nsxInst : Initialized instance
*
* Return value : 0 - Ok
* -1 - Error
*/
int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode);
/*
* This functions does noise suppression for the inserted speech frame. The
* input and output signals should always be 10ms (80 or 160 samples).
*
* Input
* - nsxInst : NSx instance. Needs to be initiated before call.
* - speechFrame : Pointer to speech frame buffer for each band
* - num_bands : Number of bands
*
* Output:
* - nsxInst : Updated NSx instance
* - outFrame : Pointer to output frame for each band
*/
void WebRtcNsx_Process(NsxHandle* nsxInst,
short* speechFrame,
int num_bands,
short* outFrame);
#endif // MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_X_H_
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,210 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_CORE_H_
#define MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_CORE_H_
#include "common_audio/signal_processing/include/signal_processing_library.h"
#include "nsx_defines.h"
#include "typedefs.h" // NOLINT(build/include)
typedef struct NoiseSuppressionFixedC_ {
//u32 fs;
// const s16* window;
s16 analysisBuffer[ANAL_BLOCKL_MAX];
s16 synthesisBuffer[ANAL_BLOCKL_MAX];
u16 noiseSupFilter[HALF_ANAL_BLOCKL];
// u16 overdrive; /* Q8 */
// u16 denoiseBound; /* Q14 */
// const s16* factor2Table;
s16 noiseEstLogQuantile[SIMULT* HALF_ANAL_BLOCKL];
s16 noiseEstDensity[SIMULT* HALF_ANAL_BLOCKL];
s16 noiseEstCounter[SIMULT];
s16 noiseEstQuantile[HALF_ANAL_BLOCKL];
// uint anaLen;
// uint anaLen2;
// uint magnLen;
// int aggrMode;
// int stages;
// int initFlag;
// int gainMap;
// s32 maxLrt;
// s32 minLrt;
// Log LRT factor with time-smoothing in Q8.
s32 logLrtTimeAvgW32[HALF_ANAL_BLOCKL];
s32 featureLogLrt;
s32 thresholdLogLrt;
s16 weightLogLrt;
u32 featureSpecDiff;
u32 thresholdSpecDiff;
s16 weightSpecDiff;
u32 featureSpecFlat;
u32 thresholdSpecFlat;
s16 weightSpecFlat;
// Conservative estimate of noise spectrum.
s32 avgMagnPause[HALF_ANAL_BLOCKL];
u32 magnEnergy;
u32 sumMagn;
u32 curAvgMagnEnergy;
u32 timeAvgMagnEnergy;
u32 timeAvgMagnEnergyTmp;
u32 whiteNoiseLevel; // Initial noise estimate.
// Initial magnitude spectrum estimate.
u32 initMagnEst[HALF_ANAL_BLOCKL];
// Pink noise parameters:
s32 pinkNoiseNumerator; // Numerator.
s32 pinkNoiseExp; // Power of freq.
int minNorm; // Smallest normalization factor.
int zeroInputSignal; // Zero input signal flag.
// Noise spectrum from previous frame.
u32 prevNoiseU32[HALF_ANAL_BLOCKL];
// Magnitude spectrum from previous frame.
u16 prevMagnU16[HALF_ANAL_BLOCKL];
// Prior speech/noise probability in Q14.
s16 priorNonSpeechProb;
int blockIndex; // Frame index counter.
// Parameter for updating or estimating thresholds/weights for prior model.
// int modelUpdate;
int cntThresUpdate;
// Histograms for parameter estimation.
s16 histLrt[HIST_PAR_EST];
s16 histSpecFlat[HIST_PAR_EST];
s16 histSpecDiff[HIST_PAR_EST];
// Quantities for high band estimate.
// s16 dataBufHBFX[NUM_HIGH_BANDS_MAX][ANAL_BLOCKL_MAX];
int qNoise;
int prevQNoise;
int prevQMagn;
// uint blockLen10ms;
s16 real[ANAL_BLOCKL_MAX];
s16 imag[ANAL_BLOCKL_MAX];
s32 energyIn;
int scaleEnergyIn;
int normData;
struct RealFFT* real_fft;
} NoiseSuppressionFixedC;
/****************************************************************************
* WebRtcNsx_InitCore(...)
*
* This function initializes a noise suppression instance
*
* Input:
* - inst : Instance that should be initialized
* - fs : Sampling frequency
*
* Output:
* - inst : Initialized instance
*
* Return value : 0 - Ok
* -1 - Error
*/
s32 WebRtcNsx_InitCore(NoiseSuppressionFixedC* inst);
/****************************************************************************
* WebRtcNsx_set_policy_core(...)
*
* This changes the aggressiveness of the noise suppression method.
*
* Input:
* - inst : Instance that should be initialized
* - mode : 0: Mild (6 dB), 1: Medium (10 dB), 2: Aggressive (15 dB)
*
* Output:
* - inst : Initialized instance
*
* Return value : 0 - Ok
* -1 - Error
*/
//int WebRtcNsx_set_policy_core(NoiseSuppressionFixedC* inst, int mode);
/****************************************************************************
* WebRtcNsx_ProcessCore
*
* Do noise suppression.
*
* Input:
* - inst : Instance that should be initialized
* - inFrame : Input speech frame for each band
* - num_bands : Number of bands
*
* Output:
* - inst : Updated instance
* - outFrame : Output speech frame for each band
*/
void WebRtcNsx_ProcessCore(NoiseSuppressionFixedC* inst,
short* inFrame,
int num_bands,
short* outFrame);
/****************************************************************************
* Some function pointers, for internal functions shared by ARM NEON and
* generic C code.
*/
// Noise Estimation.
//typedef void (*NoiseEstimation)(NoiseSuppressionFixedC* inst,
// u16* magn,
// u32* noise,
// s16* q_noise);
//extern NoiseEstimation WebRtcNsx_NoiseEstimation;
// Filter the data in the frequency domain, and create spectrum.
//typedef void (*PrepareSpectrum)(NoiseSuppressionFixedC* inst,
// s16 * freq_buff);
//extern PrepareSpectrum WebRtcNsx_PrepareSpectrum;
// For the noise supression process, synthesis, read out fully processed
// segment, and update synthesis buffer.
//typedef void (*SynthesisUpdate)(NoiseSuppressionFixedC* inst,
// s16 * out_frame,
// s16 gain_factor);
//extern SynthesisUpdate WebRtcNsx_SynthesisUpdate;
// Update analysis buffer for lower band, and window data before FFT.
//typedef void (*AnalysisUpdate)(NoiseSuppressionFixedC* inst,
// s16 * out,
// s16 * new_speech);
//extern AnalysisUpdate WebRtcNsx_AnalysisUpdate;
// Denormalize the real-valued signal |in|, the output from inverse FFT.
//typedef void (*Denormalize)(NoiseSuppressionFixedC* inst,
// s16 * in,
// int factor);
//extern Denormalize WebRtcNsx_Denormalize;
// Normalize the real-valued signal |in|, the input to forward FFT.
//typedef void (*NormalizeRealBuffer)(NoiseSuppressionFixedC* inst,
// const s16 * in,
// s16 * out);
//extern NormalizeRealBuffer WebRtcNsx_NormalizeRealBuffer;
// Compute speech/noise probability.
// Intended to be private.
extern void WebRtcNsx_SpeechNoiseProb(NoiseSuppressionFixedC* inst,
u16* nonSpeechProbFinal,
u32* priorLocSnr,
u32* postLocSnr);
#endif // MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_CORE_H_
@@ -0,0 +1,258 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "noise_suppression_x.h"
#include "nsx_core.h"
#include "nsx_defines.h"
static const s16 kIndicatorTable[17] =
{
0, 2017, 3809, 5227, 6258, 6963, 7424, 7718,
7901, 8014, 8084, 8126, 8152, 8168, 8177, 8183, 8187
};
// Compute speech/noise probability
// speech/noise probability is returned in: probSpeechFinal
//snrLocPrior is the prior SNR for each frequency (in Q11)
//snrLocPost is the post SNR for each frequency (in Q11)
void WebRtcNsx_SpeechNoiseProb(NoiseSuppressionFixedC* inst,
u16* nonSpeechProbFinal,
u32* priorLocSnr,
u32* postLocSnr)
{
u32 zeros, num, den, tmpU32no1, tmpU32no2, tmpU32no3;
s32 invLrtFX, indPriorFX, tmp32, tmp32no1, tmp32no2, besselTmpFX32;
s32 frac32, logTmp;
s32 logLrtTimeAvgKsumFX;
s16 indPriorFX16;
s16 tmp16, tmp16no1, tmp16no2, tmpIndFX, tableIndex, frac, intPart;
uint i;
int normTmp, normTmp2, nShifts;
// compute feature based on average LR factor
// this is the average over all frequencies of the smooth log LRT
logLrtTimeAvgKsumFX = 0;
for (i = 0; i < NR_MAGNLEN; i++) {
besselTmpFX32 = (s32) postLocSnr[i]; // Q11
normTmp = WebRtcSpl_NormU32(postLocSnr[i]);
num = postLocSnr[i] << normTmp; // Q(11+normTmp)
if (normTmp > 10) {
den = priorLocSnr[i] << (normTmp - 11); // Q(normTmp)
} else {
den = priorLocSnr[i] >> (11 - normTmp); // Q(normTmp)
}
if (den > 0) {
besselTmpFX32 -= num / den; // Q11
} else {
besselTmpFX32 = 0;
}
// inst->logLrtTimeAvg[i] += LRT_TAVG * (besselTmp - log(snrLocPrior)
// - inst->logLrtTimeAvg[i]);
// Here, LRT_TAVG = 0.5
zeros = WebRtcSpl_NormU32(priorLocSnr[i]);
frac32 = (s32) (((priorLocSnr[i] << zeros) & 0x7FFFFFFF) >> 19);
tmp32 = (frac32 * frac32 * -43) >> 19;
tmp32 += ((s16) frac32 * 5412) >> 12;
frac32 = tmp32 + 37;
// tmp32 = log2(priorLocSnr[i])
tmp32 = (s32) (((31 - zeros) << 12) + frac32) - (11 << 12); // Q12
logTmp = (tmp32 * 178) >> 8; // log2(priorLocSnr[i])*log(2)
// tmp32no1 = LRT_TAVG * (log(snrLocPrior) + inst->logLrtTimeAvg[i]) in Q12.
tmp32no1 = (logTmp + inst->logLrtTimeAvgW32[i]) / 2;
inst->logLrtTimeAvgW32[i] += (besselTmpFX32 - tmp32no1); // Q12
logLrtTimeAvgKsumFX += inst->logLrtTimeAvgW32[i]; // Q12
}
inst->featureLogLrt = (logLrtTimeAvgKsumFX * BIN_SIZE_LRT) >> (NR_STAGES + 11);
// done with computation of LR factor
//
//compute the indicator functions
//
// average LRT feature
// FLOAT code
// indicator0 = 0.5 * (tanh(widthPrior *
// (logLrtTimeAvgKsum - threshPrior0)) + 1.0);
tmpIndFX = 16384; // Q14(1.0)
tmp32no1 = logLrtTimeAvgKsumFX - inst->thresholdLogLrt; // Q12
nShifts = 7 - NR_STAGES; // WIDTH_PR_MAP_SHIFT - inst->stages + 5;
//use larger width in tanh map for pause regions
if (tmp32no1 < 0) {
tmpIndFX = 0;
tmp32no1 = -tmp32no1;
//widthPrior = widthPrior * 2.0;
nShifts++;
}
tmp32no1 = WEBRTC_SPL_SHIFT_W32(tmp32no1, nShifts); // Q14
// compute indicator function: sigmoid map
if (tmp32no1 < (16 << 14) && tmp32no1 >= 0) {
tableIndex = (s16) (tmp32no1 >> 14);
tmp16no2 = kIndicatorTable[tableIndex];
tmp16no1 = kIndicatorTable[tableIndex + 1] - kIndicatorTable[tableIndex];
frac = (s16) (tmp32no1 & 0x00003fff); // Q14
tmp16no2 += (s16) ((tmp16no1 * frac) >> 14);
if (tmpIndFX == 0) {
tmpIndFX = 8192 - tmp16no2; // Q14
} else {
tmpIndFX = 8192 + tmp16no2; // Q14
}
}
indPriorFX = inst->weightLogLrt * tmpIndFX; // 6*Q14
//spectral flatness feature
if (inst->weightSpecFlat) {
tmpU32no1 = WEBRTC_SPL_UMUL(inst->featureSpecFlat, 400); // Q10
tmpIndFX = 16384; // Q14(1.0)
//use larger width in tanh map for pause regions
tmpU32no2 = inst->thresholdSpecFlat - tmpU32no1; //Q10
nShifts = 4;
if (inst->thresholdSpecFlat < tmpU32no1) {
tmpIndFX = 0;
tmpU32no2 = tmpU32no1 - inst->thresholdSpecFlat;
//widthPrior = widthPrior * 2.0;
nShifts++;
}
tmpU32no1 = WebRtcSpl_DivU32U16(tmpU32no2 << nShifts, 25); // Q14
// compute indicator function: sigmoid map
// FLOAT code
// indicator1 = 0.5 * (tanh(sgnMap * widthPrior *
// (threshPrior1 - tmpFloat1)) + 1.0);
if (tmpU32no1 < (16 << 14)) {
tableIndex = (s16) (tmpU32no1 >> 14);
tmp16no2 = kIndicatorTable[tableIndex];
tmp16no1 = kIndicatorTable[tableIndex + 1] - kIndicatorTable[tableIndex];
frac = (s16) (tmpU32no1 & 0x00003fff); // Q14
tmp16no2 += (s16) ((tmp16no1 * frac) >> 14);
if (tmpIndFX) {
tmpIndFX = 8192 + tmp16no2; // Q14
} else {
tmpIndFX = 8192 - tmp16no2; // Q14
}
}
indPriorFX += inst->weightSpecFlat * tmpIndFX; // 6*Q14
}
//for template spectral-difference
if (inst->weightSpecDiff) {
tmpU32no1 = 0;
if (inst->featureSpecDiff) {
normTmp = WEBRTC_SPL_MIN(20 - NR_STAGES,
WebRtcSpl_NormU32(inst->featureSpecDiff));
tmpU32no1 = inst->featureSpecDiff << normTmp; // Q(normTmp-2*stages)
tmpU32no2 = inst->timeAvgMagnEnergy >> (20 - NR_STAGES - normTmp);
if (tmpU32no2 > 0) {
// Q(20 - inst->stages)
tmpU32no1 /= tmpU32no2;
} else {
tmpU32no1 = (u32) (0x7fffffff);
}
}
tmpU32no3 = (inst->thresholdSpecDiff << 17) / 25;
tmpU32no2 = tmpU32no1 - tmpU32no3;
nShifts = 1;
tmpIndFX = 16384; // Q14(1.0)
//use larger width in tanh map for pause regions
if (tmpU32no2 & 0x80000000) {
tmpIndFX = 0;
tmpU32no2 = tmpU32no3 - tmpU32no1;
//widthPrior = widthPrior * 2.0;
nShifts--;
}
tmpU32no1 = tmpU32no2 >> nShifts;
// compute indicator function: sigmoid map
/* FLOAT code
indicator2 = 0.5 * (tanh(widthPrior * (tmpFloat1 - threshPrior2)) + 1.0);
*/
if (tmpU32no1 < (16 << 14)) {
tableIndex = (s16) (tmpU32no1 >> 14);
tmp16no2 = kIndicatorTable[tableIndex];
tmp16no1 = kIndicatorTable[tableIndex + 1] - kIndicatorTable[tableIndex];
frac = (s16) (tmpU32no1 & 0x00003fff); // Q14
tmp16no2 += (s16) WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(
tmp16no1, frac, 14);
if (tmpIndFX) {
tmpIndFX = 8192 + tmp16no2;
} else {
tmpIndFX = 8192 - tmp16no2;
}
}
indPriorFX += inst->weightSpecDiff * tmpIndFX; // 6*Q14
}
//combine the indicator function with the feature weights
// FLOAT code
// indPrior = 1 - (weightIndPrior0 * indicator0 + weightIndPrior1 *
// indicator1 + weightIndPrior2 * indicator2);
indPriorFX16 = WebRtcSpl_DivW32W16ResW16(98307 - indPriorFX, 6); // Q14
// done with computing indicator function
//compute the prior probability
// FLOAT code
// inst->priorNonSpeechProb += PRIOR_UPDATE *
// (indPriorNonSpeech - inst->priorNonSpeechProb);
tmp16 = indPriorFX16 - inst->priorNonSpeechProb; // Q14
inst->priorNonSpeechProb += (s16) ((PRIOR_UPDATE_Q14 * tmp16) >> 14);
//final speech probability: combine prior model with LR factor:
memset(nonSpeechProbFinal, 0, sizeof (u16) * NR_MAGNLEN);
if (inst->priorNonSpeechProb > 0) {
for (i = 0; i < NR_MAGNLEN; i++) {
// FLOAT code
// invLrt = exp(inst->logLrtTimeAvg[i]);
// invLrt = inst->priorSpeechProb * invLrt;
// nonSpeechProbFinal[i] = (1.0 - inst->priorSpeechProb) /
// (1.0 - inst->priorSpeechProb + invLrt);
// invLrt = (1.0 - inst->priorNonSpeechProb) * invLrt;
// nonSpeechProbFinal[i] = inst->priorNonSpeechProb /
// (inst->priorNonSpeechProb + invLrt);
if (inst->logLrtTimeAvgW32[i] < 65300) {
tmp32no1 = (inst->logLrtTimeAvgW32[i] * 23637) >> 14; // Q12
intPart = (s16) (tmp32no1 >> 12);
if (intPart < -8) {
intPart = -8;
}
frac = (s16) (tmp32no1 & 0x00000fff); // Q12
// Quadratic approximation of 2^frac
tmp32no2 = (frac * frac * 44) >> 19; // Q12.
tmp32no2 += (frac * 84) >> 7; // Q12
invLrtFX = (1 << (8 + intPart)) +
WEBRTC_SPL_SHIFT_W32(tmp32no2, intPart - 4); // Q8
normTmp = WebRtcSpl_NormW32(invLrtFX);
normTmp2 = WebRtcSpl_NormW16((16384 - inst->priorNonSpeechProb));
if (normTmp + normTmp2 >= 7) {
if (normTmp + normTmp2 < 15) {
invLrtFX >>= 15 - normTmp2 - normTmp;
// Q(normTmp+normTmp2-7)
tmp32no1 = invLrtFX * (16384 - inst->priorNonSpeechProb);
// Q(normTmp+normTmp2+7)
invLrtFX = WEBRTC_SPL_SHIFT_W32(tmp32no1, 7 - normTmp - normTmp2);
// Q14
} else {
tmp32no1 = invLrtFX * (16384 - inst->priorNonSpeechProb);
// Q22
invLrtFX = tmp32no1 >> 8; // Q14.
}
tmp32no1 = (s32) inst->priorNonSpeechProb << 8; // Q22
nonSpeechProbFinal[i] = tmp32no1 /
(inst->priorNonSpeechProb + invLrtFX); // Q8
}
}
}
}
}
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_DEFINES_H_
#define MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_DEFINES_H_
#define ANAL_BLOCKL_MAX 128 /* Max analysis block length,8K采样率只需要128*/
#define HALF_ANAL_BLOCKL (ANAL_BLOCKL_MAX/2+1) /* Half max analysis block length + 1 */
//#define NUM_HIGH_BANDS_MAX 2 /* Max number of high bands */
#define SIMULT 3
#define END_STARTUP_LONG 200
#define END_STARTUP_SHORT 50
#define FACTOR_Q16 2621440 /* 40 in Q16 */
#define FACTOR_Q7 5120 /* 40 in Q7 */
#define FACTOR_Q7_STARTUP 1024 /* 8 in Q7 */
#define WIDTH_Q8 3 /* 0.01 in Q8 (or 25 ) */
/* PARAMETERS FOR NEW METHOD */
#define DD_PR_SNR_Q11 2007 /* ~= Q11(0.98) DD update of prior SNR */
#define ONE_MINUS_DD_PR_SNR_Q11 41 /* DD update of prior SNR */
#define SPECT_FLAT_TAVG_Q14 4915 /* (0.30) tavg parameter for spectral flatness measure */
#define SPECT_DIFF_TAVG_Q8 77 /* (0.30) tavg parameter for spectral flatness measure */
#define PRIOR_UPDATE_Q14 1638 /* Q14(0.1) Update parameter of prior model */
#define NOISE_UPDATE_Q8 26 /* 26 ~= Q8(0.1) Update parameter for noise */
/* Probability threshold for noise state in speech/noise likelihood. */
#define ONE_MINUS_PROB_RANGE_Q8 205 /* 205 ~= Q8(0.8) */
#define HIST_PAR_EST 1000 /* Histogram size for estimation of parameters */
/* FEATURE EXTRACTION CONFIG */
/* Bin size of histogram */
#define BIN_SIZE_LRT 10
/* Scale parameters: multiply dominant peaks of the histograms by scale factor to obtain. */
/* Thresholds for prior model */
#define FACTOR_1_LRT_DIFF 6 /* For LRT and spectral difference (5 times bigger) */
/* For spectral_flatness: used when noise is flatter than speech (10 times bigger). */
#define FACTOR_2_FLAT_Q10 922
/* Peak limit for spectral flatness (varies between 0 and 1) */
#define THRES_PEAK_FLAT 24 /* * 2 * BIN_SIZE_FLAT_FX */
/* Limit on spacing of two highest peaks in histogram: spacing determined by bin size. */
#define LIM_PEAK_SPACE_FLAT_DIFF 4 /* * 2 * BIN_SIZE_DIFF_FX */
/* Limit on relevance of second peak */
#define LIM_PEAK_WEIGHT_FLAT_DIFF 2
#define THRES_FLUCT_LRT 10240 /* = 20 * inst->modelUpdate; fluctuation limit of LRT feat. */
/* Limit on the max and min values for the feature thresholds */
#define MAX_FLAT_Q10 38912 /* * 2 * BIN_SIZE_FLAT_FX */
#define MIN_FLAT_Q10 4096 /* * 2 * BIN_SIZE_FLAT_FX */
#define MAX_DIFF 100 /* * 2 * BIN_SIZE_DIFF_FX */
#define MIN_DIFF 16 /* * 2 * BIN_SIZE_DIFF_FX */
/* Criteria of weight of histogram peak to accept/reject feature */
#define THRES_WEIGHT_FLAT_DIFF 154 /*(int)(0.3*(inst->modelUpdate)) for flatness and difference */
#define STAT_UPDATES 9 /* Update every 512 = 1 << 9 block */
#define ONE_MINUS_GAMMA_PAUSE_Q8 13 /* ~= Q8(0.05) Update for conservative noise estimate */
#define GAMMA_NOISE_TRANS_AND_SPEECH_Q8 3 /* ~= Q8(0.01) Update for transition and noise region */
//使用宏代替一些不会改的变量。只针对8k采样率有用
#define NR_BLOCKLEN10MS 80
#define NR_ANALEN 128
#define NR_ANALEN2 (NR_ANALEN / 2)
#define NR_MAGNLEN (NR_ANALEN2 + 1)
#define NR_STAGES 7
#define NR_MAXLRT 0x0040000
#define NR_MINLRT 52429
#define NR_MODELUPDATE (1 << STAT_UPDATES)
#define NR_HANNING_WINDOW kBlocks80w128x
//凤噪抑制等级参数
#define NSLEVEL 3 //0-3
#if NSLEVEL == 0
#define NR_GAINMAP 0
#define NR_OVERDRIVE 256
#define NR_DENOISEBOUND 8192
#elif NSLEVEL == 1
#define NR_GAINMAP 1
#define NR_OVERDRIVE 256
#define NR_DENOISEBOUND 4096
#define NR_FACTOR2TABLE kFactor2Aggressiveness1
#elif NSLEVEL == 2
#define NR_GAINMAP 1
#define NR_OVERDRIVE 282
#define NR_DENOISEBOUND 2048
#define NR_FACTOR2TABLE kFactor2Aggressiveness2
#elif NSLEVEL == 3
#define NR_GAINMAP 1
#define NR_OVERDRIVE 320
#define NR_DENOISEBOUND 1475
#define NR_FACTOR2TABLE kFactor2Aggressiveness3
#endif
// Skip first frequency bins during estimation. (0 <= value < 64)
#define NR_KSTARTBAND 5
#endif /* MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_DEFINES_H_ */
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This file contains platform-specific typedefs and defines.
// Much of it is derived from Chromium's build/build_config.h.
#ifndef TYPEDEFS_H_
#define TYPEDEFS_H_
#include <stdint.h>
typedef int16_t s16, S16;
typedef uint16_t u16, U16;
typedef int32_t s32, S32;
typedef uint32_t uint, u32, U32;
#define ALIGNED(n) __aligned(n)
#endif // TYPEDEFS_H_