#include <assert.h>
#include <stdlib.h>
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
#include <stdio.h>
#endif
#include "webrtc/modules/audio_processing/agc/analog_agc.h"
L = 8;
} else
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->add_mic, frame %d: Invalid number of samples\n\n",
- (stt->fcount + 1));
+ stt->fcount + 1);
#endif
return -1;
}
L = 16;
} else
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->add_mic, frame %d: Invalid number of samples\n\n",
- (stt->fcount + 1));
+ stt->fcount + 1);
#endif
return -1;
}
L = 16;
} else
{
-#ifdef AGC_DEBUG
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->add_mic, frame %d: Invalid sample rate\n\n",
- (stt->fcount + 1));
+ stt->fcount + 1);
#endif
return -1;
}
tmp16 = (int16_t)(stt->micVol - stt->maxAnalog);
tmp32 = WEBRTC_SPL_MUL_16_16(GAIN_TBL_LEN - 1, tmp16);
tmp16 = (int16_t)(stt->maxLevel - stt->maxAnalog);
- targetGainIdx = (uint16_t)WEBRTC_SPL_DIV(tmp32, tmp16);
+ targetGainIdx = tmp32 / tmp16;
assert(targetGainIdx < GAIN_TBL_LEN);
/* Increment through the table towards the target gain.
{
if ((samples != 80) && (samples != 160))
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->add_far_end, frame %d: Invalid number of samples\n\n",
stt->fcount);
{
if ((samples != 160) && (samples != 320))
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->add_far_end, frame %d: Invalid number of samples\n\n",
stt->fcount);
{
if ((samples != 160) && (samples != 320))
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->add_far_end, frame %d: Invalid number of samples\n\n",
stt->fcount);
subFrames = 160;
} else
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->add_far_end, frame %d: Invalid sample rate\n\n",
stt->fcount + 1);
stt->micVol = *inMicLevel;
}
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "\t\tAGC->zeroCntrl, frame %d: 500 ms under threshold, micVol:\n",
- stt->fcount, stt->micVol);
+ "\t\tAGC->zeroCntrl, frame %d: 500 ms under threshold,"
+ " micVol: %d\n",
+ stt->fcount,
+ stt->micVol);
#endif
stt->activeSpeech = 0;
if (inMicLevelTmp > stt->maxAnalog)
{
-#ifdef AGC_DEBUG //test log
- fprintf(stt->fpt, "\tAGC->ProcessAnalog, frame %d: micLvl > maxAnalog\n", stt->fcount);
+#ifdef WEBRTC_AGC_DEBUG_DUMP
+ fprintf(stt->fpt,
+ "\tAGC->ProcessAnalog, frame %d: micLvl > maxAnalog\n",
+ stt->fcount);
#endif
return -1;
} else if (inMicLevelTmp < stt->minLevel)
{
-#ifdef AGC_DEBUG //test log
- fprintf(stt->fpt, "\tAGC->ProcessAnalog, frame %d: micLvl < minLevel\n", stt->fcount);
+#ifdef WEBRTC_AGC_DEBUG_DUMP
+ fprintf(stt->fpt,
+ "\tAGC->ProcessAnalog, frame %d: micLvl < minLevel\n",
+ stt->fcount);
#endif
return -1;
}
#ifdef MIC_LEVEL_FEEDBACK
//stt->numBlocksMicLvlSat = 0;
#endif
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "\tAGC->ProcessAnalog, frame %d: micLvl < minLevel by manual decrease, raise vol\n",
+ "\tAGC->ProcessAnalog, frame %d: micLvl < minLevel by manual"
+ " decrease, raise vol\n",
stt->fcount);
#endif
}
}
inMicLevelTmp = stt->micVol;
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"\tAGC->ProcessAnalog, frame %d: saturated, micVol = %d\n",
- stt->fcount, stt->micVol);
+ stt->fcount,
+ stt->micVol);
#endif
if (stt->micVol < stt->minOutput)
#ifdef MIC_LEVEL_FEEDBACK
//stt->numBlocksMicLvlSat = 0;
#endif
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "\tAGC->ProcessAnalog, frame %d: measure > 2ndUpperLim, micVol = %d, maxLevel = %d\n",
- stt->fcount, stt->micVol, stt->maxLevel);
+ "\tAGC->ProcessAnalog, frame %d: measure >"
+ " 2ndUpperLim, micVol = %d, maxLevel = %d\n",
+ stt->fcount,
+ stt->micVol,
+ stt->maxLevel);
#endif
}
} else if (stt->Rxx160_LPw32 > stt->upperLimit)
#ifdef MIC_LEVEL_FEEDBACK
//stt->numBlocksMicLvlSat = 0;
#endif
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "\tAGC->ProcessAnalog, frame %d: measure > UpperLim, micVol = %d, maxLevel = %d\n",
- stt->fcount, stt->micVol, stt->maxLevel);
+ "\tAGC->ProcessAnalog, frame %d: measure >"
+ " UpperLim, micVol = %d, maxLevel = %d\n",
+ stt->fcount,
+ stt->micVol,
+ stt->maxLevel);
#endif
}
} else if (stt->Rxx160_LPw32 < stt->lowerSecondaryLimit)
tmp32 = WEBRTC_SPL_LSHIFT_W32(inMicLevelTmp - stt->minLevel, 14);
if (stt->maxInit != stt->minLevel)
{
- volNormFIX = (int16_t)WEBRTC_SPL_DIV(tmp32,
- (stt->maxInit - stt->minLevel));
+ volNormFIX = tmp32 / (stt->maxInit - stt->minLevel);
}
/* Find correct curve */
fprintf(stderr, "Sat mic Level: %d\n", stt->numBlocksMicLvlSat);
}
#endif
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "\tAGC->ProcessAnalog, frame %d: measure < 2ndLowerLim, micVol = %d\n",
- stt->fcount, stt->micVol);
+ "\tAGC->ProcessAnalog, frame %d: measure <"
+ " 2ndLowerLim, micVol = %d\n",
+ stt->fcount,
+ stt->micVol);
#endif
}
} else if (stt->Rxx160_LPw32 < stt->lowerLimit)
tmp32 = WEBRTC_SPL_LSHIFT_W32(inMicLevelTmp - stt->minLevel, 14);
if (stt->maxInit != stt->minLevel)
{
- volNormFIX = (int16_t)WEBRTC_SPL_DIV(tmp32,
- (stt->maxInit - stt->minLevel));
+ volNormFIX = tmp32 / (stt->maxInit - stt->minLevel);
}
/* Find correct curve */
fprintf(stderr, "Sat mic Level: %d\n", stt->numBlocksMicLvlSat);
}
#endif
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"\tAGC->ProcessAnalog, frame %d: measure < LowerLim, micVol = %d\n",
- stt->fcount, stt->micVol);
+ stt->fcount,
+ stt->micVol);
#endif
}
{
if ((samples != 80) && (samples != 160))
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "AGC->Process, frame %d: Invalid number of samples\n\n", stt->fcount);
+ "AGC->Process, frame %d: Invalid number of samples\n\n",
+ stt->fcount);
#endif
return -1;
}
{
if ((samples != 160) && (samples != 320))
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "AGC->Process, frame %d: Invalid number of samples\n\n", stt->fcount);
+ "AGC->Process, frame %d: Invalid number of samples\n\n",
+ stt->fcount);
#endif
return -1;
}
{
if ((samples != 160) && (samples != 320))
{
-#ifdef AGC_DEBUG //test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "AGC->Process, frame %d: Invalid number of samples\n\n", stt->fcount);
+ "AGC->Process, frame %d: Invalid number of samples\n\n",
+ stt->fcount);
#endif
return -1;
}
subFrames = 160;
} else
{
-#ifdef AGC_DEBUG// test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
- "AGC->Process, frame %d: Invalid sample rate\n\n", stt->fcount);
+ "AGC->Process, frame %d: Invalid sample rate\n\n",
+ stt->fcount);
#endif
return -1;
}
}
}
-#ifdef AGC_DEBUG//test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
stt->fcount++;
#endif
if (WebRtcAgc_ProcessDigital(&stt->digitalAgc, &in_near[i], &in_near_H[i], &out[i], &out_H[i],
stt->fs, stt->lowLevelSignal) == -1)
{
-#ifdef AGC_DEBUG//test log
- fprintf(stt->fpt, "AGC->Process, frame %d: Error from DigAGC\n\n", stt->fcount);
+#ifdef WEBRTC_AGC_DEBUG_DUMP
+ fprintf(stt->fpt,
+ "AGC->Process, frame %d: Error from DigAGC\n\n",
+ stt->fcount);
#endif
return -1;
}
return -1;
}
}
-#ifdef AGC_DEBUG//test log
- fprintf(stt->agcLog, "%5d\t%d\t%d\t%d\n", stt->fcount, inMicLevelTmp, *outMicLevel, stt->maxLevel, stt->micVol);
+#ifdef WEBRTC_AGC_DEBUG_DUMP
+ fprintf(stt->agcLog,
+ "%5d\t%d\t%d\t%d\t%d\n",
+ stt->fcount,
+ inMicLevelTmp,
+ *outMicLevel,
+ stt->maxLevel,
+ stt->micVol);
#endif
/* update queue */
if (WebRtcAgc_CalculateGainTable(&(stt->digitalAgc.gainTable[0]), stt->compressionGaindB,
stt->targetLevelDbfs, stt->limiterEnable, stt->analogTarget) == -1)
{
-#ifdef AGC_DEBUG//test log
- fprintf(stt->fpt, "AGC->set_config, frame %d: Error from calcGainTable\n\n", stt->fcount);
+#ifdef WEBRTC_AGC_DEBUG_DUMP
+ fprintf(stt->fpt,
+ "AGC->set_config, frame %d: Error from calcGainTable\n\n",
+ stt->fcount);
#endif
return -1;
}
return -1;
}
-#ifdef AGC_DEBUG
+#ifdef WEBRTC_AGC_DEBUG_DUMP
stt->fpt = fopen("./agc_test_log.txt", "wt");
stt->agcLog = fopen("./agc_debug_log.txt", "wt");
stt->digitalAgc.logFile = fopen("./agc_log.txt", "wt");
Agc_t *stt;
stt = (Agc_t *)state;
-#ifdef AGC_DEBUG
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fclose(stt->fpt);
fclose(stt->agcLog);
fclose(stt->digitalAgc.logFile);
* 2 - Digital Automatic Gain Control [-targetLevelDbfs (default -3 dBOv)]
* 3 - Fixed Digital Gain [compressionGaindB (default 8 dB)]
*/
-#ifdef AGC_DEBUG//test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
stt->fcount = 0;
fprintf(stt->fpt, "AGC->Init\n");
#endif
if (agcMode < kAgcModeUnchanged || agcMode > kAgcModeFixedDigital)
{
-#ifdef AGC_DEBUG//test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt, "AGC->Init: error, incorrect mode\n\n");
#endif
return -1;
stt->numBlocksMicLvlSat = 0;
stt->micLvlSat = 0;
#endif
-#ifdef AGC_DEBUG//test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt,
"AGC->Init: minLevel = %d, maxAnalog = %d, maxLevel = %d\n",
- stt->minLevel, stt->maxAnalog, stt->maxLevel);
+ stt->minLevel,
+ stt->maxAnalog,
+ stt->maxLevel);
#endif
/* Minimum output volume is 4% higher than the available lowest volume level */
/* Only positive values are allowed that are not too large */
if ((minLevel >= maxLevel) || (maxLevel & 0xFC000000))
{
-#ifdef AGC_DEBUG//test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt, "minLevel, maxLevel value(s) are invalid\n\n");
#endif
return -1;
} else
{
-#ifdef AGC_DEBUG//test log
+#ifdef WEBRTC_AGC_DEBUG_DUMP
fprintf(stt->fpt, "\n");
#endif
return 0;