Some code style changes in audio_processing/ns/main/source/ by Astyle,

with a little manual modification.
Review URL: http://webrtc-codereview.appspot.com/201002

git-svn-id: http://webrtc.googlecode.com/svn/trunk@698 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kma@webrtc.org 2011-10-05 23:36:01 +00:00
parent fa41d807a8
commit af57de006a
10 changed files with 4045 additions and 4439 deletions

View File

@ -15,10 +15,9 @@
#include "ns_core.h" #include "ns_core.h"
#include "defines.h" #include "defines.h"
int WebRtcNs_get_version(char *versionStr, short length) int WebRtcNs_get_version(char* versionStr, short length) {
{
const char version[] = "NS 2.2.0"; const char version[] = "NS 2.2.0";
const short versionLen = (short)strlen(version) + 1; // +1 for null-termination const short versionLen = (short)strlen(version) + 1; // +1: null-termination
if (versionStr == NULL) { if (versionStr == NULL) {
return -1; return -1;
@ -33,8 +32,7 @@ int WebRtcNs_get_version(char *versionStr, short length)
return 0; return 0;
} }
int WebRtcNs_Create(NsHandle **NS_inst) int WebRtcNs_Create(NsHandle** NS_inst) {
{
*NS_inst = (NsHandle*) malloc(sizeof(NSinst_t)); *NS_inst = (NsHandle*) malloc(sizeof(NSinst_t));
if (*NS_inst != NULL) { if (*NS_inst != NULL) {
(*(NSinst_t**)NS_inst)->initFlag = 0; (*(NSinst_t**)NS_inst)->initFlag = 0;
@ -45,25 +43,23 @@ int WebRtcNs_Create(NsHandle **NS_inst)
} }
int WebRtcNs_Free(NsHandle *NS_inst) int WebRtcNs_Free(NsHandle* NS_inst) {
{
free(NS_inst); free(NS_inst);
return 0; return 0;
} }
int WebRtcNs_Init(NsHandle *NS_inst, WebRtc_UWord32 fs) int WebRtcNs_Init(NsHandle* NS_inst, WebRtc_UWord32 fs) {
{
return WebRtcNs_InitCore((NSinst_t*) NS_inst, fs); return WebRtcNs_InitCore((NSinst_t*) NS_inst, fs);
} }
int WebRtcNs_set_policy(NsHandle *NS_inst, int mode) int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
{
return WebRtcNs_set_policy_core((NSinst_t*) NS_inst, mode); return WebRtcNs_set_policy_core((NSinst_t*) NS_inst, mode);
} }
int WebRtcNs_Process(NsHandle *NS_inst, short *spframe, short *spframe_H, short *outframe, short *outframe_H) int WebRtcNs_Process(NsHandle* NS_inst, short* spframe, short* spframe_H,
{ short* outframe, short* outframe_H) {
return WebRtcNs_ProcessCore((NSinst_t*) NS_inst, spframe, spframe_H, outframe, outframe_H); return WebRtcNs_ProcessCore(
(NSinst_t*) NS_inst, spframe, spframe_H, outframe, outframe_H);
} }

View File

@ -15,18 +15,15 @@
#include "nsx_core.h" #include "nsx_core.h"
#include "nsx_defines.h" #include "nsx_defines.h"
int WebRtcNsx_get_version(char *versionStr, short length) int WebRtcNsx_get_version(char* versionStr, short length) {
{
const char version[] = "NS\t3.1.0"; const char version[] = "NS\t3.1.0";
const short versionLen = (short)strlen(version) + 1; // +1 for null-termination const short versionLen = (short)strlen(version) + 1; // +1: null-termination
if (versionStr == NULL) if (versionStr == NULL) {
{
return -1; return -1;
} }
if (versionLen > length) if (versionLen > length) {
{
return -1; return -1;
} }
@ -35,40 +32,34 @@ int WebRtcNsx_get_version(char *versionStr, short length)
return 0; return 0;
} }
int WebRtcNsx_Create(NsxHandle **nsxInst) int WebRtcNsx_Create(NsxHandle** nsxInst) {
{
*nsxInst = (NsxHandle*)malloc(sizeof(NsxInst_t)); *nsxInst = (NsxHandle*)malloc(sizeof(NsxInst_t));
if (*nsxInst != NULL) if (*nsxInst != NULL) {
{
(*(NsxInst_t**)nsxInst)->initFlag = 0; (*(NsxInst_t**)nsxInst)->initFlag = 0;
return 0; return 0;
} else } else {
{
return -1; return -1;
} }
} }
int WebRtcNsx_Free(NsxHandle *nsxInst) int WebRtcNsx_Free(NsxHandle* nsxInst) {
{
free(nsxInst); free(nsxInst);
return 0; return 0;
} }
int WebRtcNsx_Init(NsxHandle *nsxInst, WebRtc_UWord32 fs) int WebRtcNsx_Init(NsxHandle* nsxInst, WebRtc_UWord32 fs) {
{
return WebRtcNsx_InitCore((NsxInst_t*)nsxInst, fs); return WebRtcNsx_InitCore((NsxInst_t*)nsxInst, fs);
} }
int WebRtcNsx_set_policy(NsxHandle *nsxInst, int mode) int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode) {
{
return WebRtcNsx_set_policy_core((NsxInst_t*)nsxInst, mode); return WebRtcNsx_set_policy_core((NsxInst_t*)nsxInst, mode);
} }
int WebRtcNsx_Process(NsxHandle *nsxInst, short *speechFrame, short *speechFrameHB, int WebRtcNsx_Process(NsxHandle* nsxInst, short* speechFrame,
short *outFrame, short *outFrameHB) short* speechFrameHB, short* outFrame,
{ short* outFrameHB) {
return WebRtcNsx_ProcessCore((NsxInst_t*)nsxInst, speechFrame, speechFrameHB, outFrame, return WebRtcNsx_ProcessCore(
outFrameHB); (NsxInst_t*)nsxInst, speechFrame, speechFrameHB, outFrame, outFrameHB);
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,7 @@
#include <stdio.h> #include <stdio.h>
#endif #endif
typedef struct NsxInst_t_ typedef struct NsxInst_t_ {
{
WebRtc_UWord32 fs; WebRtc_UWord32 fs;
const WebRtc_Word16* window; const WebRtc_Word16* window;

View File

@ -16,8 +16,7 @@
#include <assert.h> #include <assert.h>
void WebRtcNsx_NoiseEstimation(NsxInst_t* inst, WebRtc_UWord16* magn, WebRtc_UWord32* noise, void WebRtcNsx_NoiseEstimation(NsxInst_t* inst, WebRtc_UWord16* magn, WebRtc_UWord32* noise,
WebRtc_Word16 *qNoise) WebRtc_Word16* qNoise) {
{
WebRtc_Word32 numerator; WebRtc_Word32 numerator;
WebRtc_Word16 lmagn[HALF_ANAL_BLOCKL], counter, countDiv, countProd, delta, zeros, frac; WebRtc_Word16 lmagn[HALF_ANAL_BLOCKL], counter, countDiv, countProd, delta, zeros, frac;
@ -32,11 +31,9 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
tabind = inst->stages - inst->normData; tabind = inst->stages - inst->normData;
assert(tabind < 9); assert(tabind < 9);
assert(tabind > -9); assert(tabind > -9);
if (tabind < 0) if (tabind < 0) {
{
logval = -WebRtcNsx_kLogTable[-tabind]; logval = -WebRtcNsx_kLogTable[-tabind];
} else } else {
{
logval = WebRtcNsx_kLogTable[tabind]; logval = WebRtcNsx_kLogTable[tabind];
} }
@ -46,10 +43,8 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
// magn is in Q(-stages), and the real lmagn values are: // magn is in Q(-stages), and the real lmagn values are:
// real_lmagn(i)=log(magn(i)*2^stages)=log(magn(i))+log(2^stages) // real_lmagn(i)=log(magn(i)*2^stages)=log(magn(i))+log(2^stages)
// lmagn in Q8 // lmagn in Q8
for (i = 0; i < inst->magnLen; i++) for (i = 0; i < inst->magnLen; i++) {
{ if (magn[i]) {
if (magn[i])
{
zeros = WebRtcSpl_NormU32((WebRtc_UWord32)magn[i]); zeros = WebRtcSpl_NormU32((WebRtc_UWord32)magn[i]);
frac = (WebRtc_Word16)((((WebRtc_UWord32)magn[i] << zeros) & 0x7FFFFFFF) >> 23); frac = (WebRtc_Word16)((((WebRtc_UWord32)magn[i] << zeros) & 0x7FFFFFFF) >> 23);
assert(frac < 256); assert(frac < 256);
@ -59,8 +54,7 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
lmagn[i] = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(log2, log2Const, 15); lmagn[i] = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(log2, log2Const, 15);
// + log(2^stages) // + log(2^stages)
lmagn[i] += logval; lmagn[i] += logval;
} else } else {
{
lmagn[i] = logval; lmagn[i] = logval;
} }
} }
@ -74,8 +68,7 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
factor = FACTOR_Q7_STARTUP; factor = FACTOR_Q7_STARTUP;
// Loop over simultaneous estimates // Loop over simultaneous estimates
for (s = 0; s < SIMULT; s++) for (s = 0; s < SIMULT; s++) {
{
offset = s * inst->magnLen; offset = s * inst->magnLen;
// Get counter values from state // Get counter values from state
@ -108,9 +101,10 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
int j; int j;
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
if (inst->noiseEstDensity[offset + i + j] > 512) if (inst->noiseEstDensity[offset + i + j] > 512) {
deltaBuff[j] = WebRtcSpl_DivW32W16ResW16(numerator, deltaBuff[j] = WebRtcSpl_DivW32W16ResW16(
inst->noiseEstDensity[offset + i + j]); numerator, inst->noiseEstDensity[offset + i + j]);
}
} }
// Update log quantile estimate // Update log quantile estimate
@ -175,15 +169,12 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
vst1q_s16(&inst->noiseEstDensity[offset + i], tmp16x8_1); vst1q_s16(&inst->noiseEstDensity[offset + i], tmp16x8_1);
} // End loop over magnitude spectrum } // End loop over magnitude spectrum
for (; i < inst->magnLen; i++) for (; i < inst->magnLen; i++) {
{
// compute delta // compute delta
if (inst->noiseEstDensity[offset + i] > 512) if (inst->noiseEstDensity[offset + i] > 512) {
{
delta = WebRtcSpl_DivW32W16ResW16(numerator, delta = WebRtcSpl_DivW32W16ResW16(numerator,
inst->noiseEstDensity[offset + i]); inst->noiseEstDensity[offset + i]);
} else } else {
{
delta = FACTOR_Q7; delta = FACTOR_Q7;
if (inst->blockIndex < END_STARTUP_LONG) { if (inst->blockIndex < END_STARTUP_LONG) {
// Smaller step size during startup. This prevents from using // Smaller step size during startup. This prevents from using
@ -194,15 +185,13 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
// update log quantile estimate // update log quantile estimate
tmp16 = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(delta, countDiv, 14); tmp16 = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(delta, countDiv, 14);
if (lmagn[i] > inst->noiseEstLogQuantile[offset + i]) if (lmagn[i] > inst->noiseEstLogQuantile[offset + i]) {
{
// +=QUANTILE*delta/(inst->counter[s]+1) QUANTILE=0.25, =1 in Q2 // +=QUANTILE*delta/(inst->counter[s]+1) QUANTILE=0.25, =1 in Q2
// CounterDiv=1/(inst->counter[s]+1) in Q15 // CounterDiv=1/(inst->counter[s]+1) in Q15
tmp16 += 2; tmp16 += 2;
tmp16no1 = WEBRTC_SPL_RSHIFT_W16(tmp16, 2); tmp16no1 = WEBRTC_SPL_RSHIFT_W16(tmp16, 2);
inst->noiseEstLogQuantile[offset + i] += tmp16no1; inst->noiseEstLogQuantile[offset + i] += tmp16no1;
} else } else {
{
tmp16 += 1; tmp16 += 1;
tmp16no1 = WEBRTC_SPL_RSHIFT_W16(tmp16, 1); tmp16no1 = WEBRTC_SPL_RSHIFT_W16(tmp16, 1);
// *(1-QUANTILE), in Q2 QUANTILE=0.25, 1-0.25=0.75=3 in Q2 // *(1-QUANTILE), in Q2 QUANTILE=0.25, 1-0.25=0.75=3 in Q2
@ -218,21 +207,18 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
// update density estimate // update density estimate
if (WEBRTC_SPL_ABS_W16(lmagn[i] - inst->noiseEstLogQuantile[offset + i]) if (WEBRTC_SPL_ABS_W16(lmagn[i] - inst->noiseEstLogQuantile[offset + i])
< WIDTH_Q8) < WIDTH_Q8) {
{
tmp16no1 = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND( tmp16no1 = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(
inst->noiseEstDensity[offset + i], countProd, 15); inst->noiseEstDensity[offset + i], countProd, 15);
tmp16no2 = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(widthFactor, tmp16no2 = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(
countDiv, 15); widthFactor, countDiv, 15);
inst->noiseEstDensity[offset + i] = tmp16no1 + tmp16no2; inst->noiseEstDensity[offset + i] = tmp16no1 + tmp16no2;
} }
} // end loop over magnitude spectrum } // end loop over magnitude spectrum
if (counter >= END_STARTUP_LONG) if (counter >= END_STARTUP_LONG) {
{
inst->noiseEstCounter[s] = 0; inst->noiseEstCounter[s] = 0;
if (inst->blockIndex >= END_STARTUP_LONG) if (inst->blockIndex >= END_STARTUP_LONG) {
{
WebRtcNsx_UpdateNoiseEstimate(inst, offset); WebRtcNsx_UpdateNoiseEstimate(inst, offset);
} }
} }
@ -241,13 +227,11 @@ void WebRtcNsx_NoiseEstimation(NsxInst_t *inst, WebRtc_UWord16 *magn, WebRtc_UWo
} // end loop over simultaneous estimates } // end loop over simultaneous estimates
// Sequentially update the noise during startup // Sequentially update the noise during startup
if (inst->blockIndex < END_STARTUP_LONG) if (inst->blockIndex < END_STARTUP_LONG) {
{
WebRtcNsx_UpdateNoiseEstimate(inst, offset); WebRtcNsx_UpdateNoiseEstimate(inst, offset);
} }
for (i = 0; i < inst->magnLen; i++) for (i = 0; i < inst->magnLen; i++) {
{
noise[i] = (WebRtc_UWord32)(inst->noiseEstQuantile[i]); // Q(qNoise) noise[i] = (WebRtc_UWord32)(inst->noiseEstQuantile[i]); // Q(qNoise)
} }
(*qNoise) = (WebRtc_Word16)inst->qNoise; (*qNoise) = (WebRtc_Word16)inst->qNoise;

View File

@ -568,6 +568,7 @@ static const float kBlocks480w1024[1024] = {
(float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000,
(float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000,
(float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000,
(float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000}; (float)0.00000000, (float)0.00000000, (float)0.00000000, (float)0.00000000
};
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_WINDOWS_PRIVATE_H_ #endif // WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_WINDOWS_PRIVATE_H_