# 舒适生成算法CNG(comfort noise generation)

舒适噪声应用在实时语音通信（VoIP，电话等）场景中，主要解决两个问题，第一个是减小传输数据量，进而减小传输带宽的要求，这是因为50%的时间是没有语音的，第二个是让人感觉语音通信是持续连接的。

## 随机数生成

$$x_{i+1} = a \cdot x_i (modM), \Sigma_{i+1}= \frac{x_{i+1}}{M}, i=1,2,\cdots$$

### RANDU随机数产生器有IBM提出



static uint32_t IncreaseSeed(uint32_t* seed)  {
seed[0] = (seed[0] * ((int32_t)69069) + 1) & (kMaxSeedUsed - 1);
return seed[0];
}

int16_t WebRtcSpl_RandU(uint32_t* seed) {
return (int16_t)(IncreaseSeed(seed) >> 16);
}

int16_t WebRtcSpl_RandN(uint32_t* seed) {
return kRandNTable[IncreaseSeed(seed) >> 23];
}

// Creates an array of uniformly distributed variables.
int16_t WebRtcSpl_RandUArray(int16_t* vector,
int16_t vector_length,
uint32_t* seed) {
int i;
for (i = 0; i < vector_length; i++) {
vector[i] = WebRtcSpl_RandU(seed);
}
return vector_length;
}



## 舒适噪声生成实现

1.首先生成随机数，调用前面的随机数生成算法，并将其归一化到正负一之间。



// Generate a uniform random array on [0 1]
WebRtcSpl_RandUArray(randW16, PART_LEN, &aec->seed);
for (i = 0; i < PART_LEN; i++) {
rand[i] = ((float)randW16[i]) / 32768;
}



2.生成噪声



// Reject LF noise
u[0][0] = 0;
u[0][1] = 0;
for (i = 1; i < PART_LEN1; i++) {
tmp = pi2 * rand[i - 1];

noise = sqrtf(noisePow[i]);
u[i][0] = noise * cosf(tmp);
u[i][1] = -noise * sinf(tmp);
}
u[PART_LEN][1] = 0;



3.对分量值进行相乘



for (i = 0; i < PART_LEN1; i++) {
// This is the proper weighting to match the background noise power
tmp = sqrtf(WEBRTC_SPL_MAX(1 - lambda[i] * lambda[i], 0));
// tmp = 1 - lambda[i];
efw[0][i] += tmp * u[i][0];
efw[1][i] += tmp * u[i][1];
}



06-04
12-25

05-15 2754
07-04 5388
05-07 1万+
07-04 1万+
07-15 3280
07-29 6421
03-05 3497