bug fix for level meter

This commit is contained in:
Volker Fischer 2006-02-18 17:03:24 +00:00
parent cfc9255ef8
commit 824bc8ab5d
2 changed files with 53 additions and 29 deletions

View file

@ -244,33 +244,50 @@ void CLlconClientDlg::OnSliderNetBuf(int value)
TextNetBuf->setText("Size: " + QString().setNum(value)); TextNetBuf->setText("Size: " + QString().setNum(value));
} }
void CLlconClientDlg::OnTimerSigMet() void CLlconClientDlg::OnTimerSigMet ()
{ {
/* get current input levels */ /* get current input levels */
double dCurSigLevelL = pClient->MicLevelL(); double dCurSigLevelL = pClient->MicLevelL ();
double dCurSigLevelR = pClient->MicLevelR(); double dCurSigLevelR = pClient->MicLevelR ();
/* linear transformation of the input level range to the progress-bar /* linear transformation of the input level range to the progress-bar
range */ range */
dCurSigLevelL -= LOW_BOUND_SIG_METER; dCurSigLevelL -= LOW_BOUND_SIG_METER;
dCurSigLevelL *= NUM_STEPS_INP_LEV_METER / dCurSigLevelL *= NUM_STEPS_INP_LEV_METER /
(UPPER_BOUND_SIG_METER - LOW_BOUND_SIG_METER); ( UPPER_BOUND_SIG_METER - LOW_BOUND_SIG_METER );
// lower bound the signal
if ( dCurSigLevelL < 0 )
{
dCurSigLevelL = 0;
}
dCurSigLevelR -= LOW_BOUND_SIG_METER; dCurSigLevelR -= LOW_BOUND_SIG_METER;
dCurSigLevelR *= NUM_STEPS_INP_LEV_METER / dCurSigLevelR *= NUM_STEPS_INP_LEV_METER /
(UPPER_BOUND_SIG_METER - LOW_BOUND_SIG_METER); ( UPPER_BOUND_SIG_METER - LOW_BOUND_SIG_METER );
// lower bound the signal
if ( dCurSigLevelR < 0 )
{
dCurSigLevelR = 0;
}
/* show current level */ /* show current level */
ProgressBarInputLevelL->setProgress((int) ceil(dCurSigLevelL)); ProgressBarInputLevelL->setProgress ( (int) ceil ( dCurSigLevelL ) );
ProgressBarInputLevelR->setProgress((int) ceil(dCurSigLevelR)); ProgressBarInputLevelR->setProgress ( (int) ceil ( dCurSigLevelR ) );
} }
void CLlconClientDlg::OnTimerStatus() void CLlconClientDlg::OnTimerStatus ()
{ {
/* show connection status in status bar */ /* show connection status in status bar */
if (pClient->IsConnected() && pClient->IsRunning()) if ( pClient->IsConnected () && pClient->IsRunning () )
TextLabelStatus->setText(tr("connected")); {
TextLabelStatus->setText ( tr ( "connected" ) );
}
else else
TextLabelStatus->setText(tr("disconnected")); {
TextLabelStatus->setText ( tr ( "disconnected" ) );
}
/* update sample rate offset label */ /* update sample rate offset label */
QString strSamRaOffs; QString strSamRaOffs;

View file

@ -27,41 +27,48 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
/* Input level meter implementation ------------------------------------------ */ /* Input level meter implementation ------------------------------------------ */
void CSignalLevelMeter::Update(CVector<double>& vecdAudio) void CSignalLevelMeter::Update ( CVector<double>& vecdAudio )
{ {
/* Do the update for entire vector, convert to floating-point */ /* Do the update for entire vector */
const int iVecSize = vecdAudio.Size(); const int iVecSize = vecdAudio.Size ();
for (int i = 0; i < iVecSize; i++) for ( int i = 0; i < iVecSize; i++ )
{ {
/* norm of current audio sample */ /* norm of current audio sample */
const double dCurSig = fabs(vecdAudio[i]); const double dCurSig = fabs ( vecdAudio[i] );
/* search for maximum. Decrease this max with time */ /* search for maximum. Decrease this max with time */
/* decrease max with time */ /* decrease max with time */
if (dCurLevel >= METER_FLY_BACK) if ( dCurLevel >= METER_FLY_BACK )
dCurLevel -= METER_FLY_BACK; {
dCurLevel *= 0.9999;
}
else else
{ {
if ((dCurLevel <= METER_FLY_BACK) && (dCurLevel > 1.0)) dCurLevel = 0;
dCurLevel -= 2.0;
} }
/* search for max */ /* search for max */
if (dCurSig > dCurLevel) if ( dCurSig > dCurLevel )
{
dCurLevel = dCurSig; dCurLevel = dCurSig;
} }
}
} }
double CSignalLevelMeter::MicLevel() double CSignalLevelMeter::MicLevel ()
{ {
const double dNormMicLevel = dCurLevel / _MAXSHORT; const double dNormMicLevel = dCurLevel / _MAXSHORT;
/* logarithmic measure */ /* logarithmic measure */
if (dNormMicLevel > 0) if ( dNormMicLevel > 0 )
return 20.0 * log10(dNormMicLevel); {
return 20.0 * log10 ( dNormMicLevel );
}
else else
{
return -100000.0; /* large negative value */ return -100000.0; /* large negative value */
}
} }