Skip to content

Commit

Permalink
audio_processing/agc: Solved building with AGC_DEBUG + few style changes
Browse files Browse the repository at this point in the history
webrtc did not build if AGC_DEBUG was turned on. This CL fixes that. Has no impact on performance since it is development/debug code.

* Name change to WEBRT_AGC_DEBUG_DUMP
* Added build flag agc_debug_dump to .gypi
* Added missing "%d" in printf at two places
* Some line length related style changes

Tested audioproc and modules_unittests with GYP_DEFINES=agc_debug_dump=1 webrtc/build/gyp_webrtc

BUG=N/A
TESTED=locally and trybots
R=aluebs@webrtc.org, kwiberg@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7271 4adac7df-926f-26a2-2b94-8c16560cd09d
  • Loading branch information
bjornv@webrtc.org committed Sep 23, 2014
1 parent 0a2087a commit ea29787
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 74 deletions.
145 changes: 89 additions & 56 deletions webrtc/modules/audio_processing/agc/analog_agc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#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"
Expand Down Expand Up @@ -139,10 +139,10 @@ int WebRtcAgc_AddMic(void *state, int16_t *in_mic, int16_t *in_mic_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;
}
Expand All @@ -160,10 +160,10 @@ int WebRtcAgc_AddMic(void *state, int16_t *in_mic, int16_t *in_mic_H,
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;
}
Expand All @@ -177,10 +177,10 @@ int WebRtcAgc_AddMic(void *state, int16_t *in_mic, int16_t *in_mic_H,
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;
}
Expand Down Expand Up @@ -343,7 +343,7 @@ int WebRtcAgc_AddFarend(void *state, const int16_t *in_far, int16_t samples)
{
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);
Expand All @@ -355,7 +355,7 @@ int WebRtcAgc_AddFarend(void *state, const int16_t *in_far, int16_t samples)
{
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);
Expand All @@ -367,7 +367,7 @@ int WebRtcAgc_AddFarend(void *state, const int16_t *in_far, int16_t samples)
{
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);
Expand All @@ -377,7 +377,7 @@ int WebRtcAgc_AddFarend(void *state, const int16_t *in_far, int16_t samples)
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);
Expand Down Expand Up @@ -657,10 +657,12 @@ void WebRtcAgc_ZeroCtrl(Agc_t *stt, int32_t *inMicLevel, int32_t *env)
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;
Expand Down Expand Up @@ -771,14 +773,18 @@ int32_t WebRtcAgc_ProcessAnalog(void *state, int32_t inMicLevel,

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;
}
Expand Down Expand Up @@ -813,9 +819,10 @@ int32_t WebRtcAgc_ProcessAnalog(void *state, int32_t inMicLevel,
#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
}
Expand Down Expand Up @@ -871,10 +878,11 @@ int32_t WebRtcAgc_ProcessAnalog(void *state, int32_t inMicLevel,
}
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)
Expand Down Expand Up @@ -1011,10 +1019,13 @@ int32_t WebRtcAgc_ProcessAnalog(void *state, int32_t inMicLevel,
#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)
Expand Down Expand Up @@ -1054,10 +1065,13 @@ int32_t WebRtcAgc_ProcessAnalog(void *state, int32_t inMicLevel,
#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)
Expand Down Expand Up @@ -1113,10 +1127,12 @@ int32_t WebRtcAgc_ProcessAnalog(void *state, int32_t inMicLevel,
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)
Expand Down Expand Up @@ -1172,10 +1188,11 @@ int32_t WebRtcAgc_ProcessAnalog(void *state, int32_t inMicLevel,
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

}
Expand Down Expand Up @@ -1272,9 +1289,10 @@ int WebRtcAgc_Process(void *agcInst, const int16_t *in_near,
{
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;
}
Expand All @@ -1283,9 +1301,10 @@ int WebRtcAgc_Process(void *agcInst, const int16_t *in_near,
{
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;
}
Expand All @@ -1294,18 +1313,20 @@ int WebRtcAgc_Process(void *agcInst, const int16_t *in_near,
{
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;
}
Expand Down Expand Up @@ -1341,7 +1362,7 @@ int WebRtcAgc_Process(void *agcInst, const int16_t *in_near,
}
}

#ifdef AGC_DEBUG//test log
#ifdef WEBRTC_AGC_DEBUG_DUMP
stt->fcount++;
#endif

Expand All @@ -1350,8 +1371,10 @@ int WebRtcAgc_Process(void *agcInst, const int16_t *in_near,
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;
}
Expand All @@ -1364,8 +1387,14 @@ int WebRtcAgc_Process(void *agcInst, const int16_t *in_near,
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 */
Expand Down Expand Up @@ -1441,8 +1470,10 @@ int WebRtcAgc_set_config(void *agcInst, WebRtcAgc_config_t agcConfig)
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;
}
Expand Down Expand Up @@ -1498,7 +1529,7 @@ int WebRtcAgc_Create(void **agcInst)
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");
Expand All @@ -1515,7 +1546,7 @@ int WebRtcAgc_Free(void *state)
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);
Expand Down Expand Up @@ -1553,13 +1584,13 @@ int WebRtcAgc_Init(void *agcInst, int32_t minLevel, int32_t maxLevel,
* 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;
Expand Down Expand Up @@ -1616,10 +1647,12 @@ int WebRtcAgc_Init(void *agcInst, int32_t minLevel, int32_t maxLevel,
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 */
Expand Down Expand Up @@ -1687,13 +1720,13 @@ int WebRtcAgc_Init(void *agcInst, int32_t minLevel, int32_t maxLevel,
/* 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;
Expand Down
Loading

0 comments on commit ea29787

Please sign in to comment.