P
paul
Hi all,
I've been handed some code and, unless I've got the numbering of
parentheses wrong, one of the functions has a curious if-else
statement. The thing compiles but is it right?
I know the code contains non-standard C++, but its only the if
statement I'm after. It seems to
go:
if (condition){
}
else
{
}
else
??????????????
void CAudioProcessFrame::Voice(int iChannel, bool bDetected)
{
if (g_bVoiceTraining)
return;
if (m_bVoice[iChannel]!=bDetected) {
char szCad[512];
if (bDetected) {
if (!m_iVoiceStarted[iChannel]) { // So we have detected a voice and
it hasn't started yet.
m_iVoiceStarted[iChannel]=g_ticks;
debug.printf_(" Sound started %i \n",g_ticks);
m_EventDetected[iChannel].in_msec=libVAD_GetCurrentTimestamp(); //
When has this sound event started?
m_EventDetected[iChannel].out_msec=libVAD_GetCurrentTimestamp();
#ifndef NDEBUG
g_AudioBuffer.clear();
#endif
m_iCaptureAudio[iChannel]=1;
}
m_iVoiceEnded[iChannel]=0;
sprintf(szCad," Voice detected on channel %i card %i [%s]",
iChannel, m_iIndex, m_sCardName.c_str());
} else {
if (!m_iVoiceEnded[iChannel]) {
m_iVoiceEnded[iChannel]=g_ticks;
debug.printf_(" Sound ended %i \n",g_ticks);
}
int iElapsed=g_ticks-m_iVoiceEnded[iChannel];
if (iElapsed>g_iMilisPause) {
int
iTotalVoice=(m_iVoiceEnded[iChannel]-m_iVoiceStarted[iChannel]);
if (iTotalVoice>g_iMilisMinimumLength) {
sprintf(szCad," End of voice on channel %i card %i [%s]",
iChannel, m_iIndex, m_sCardName.c_str());
m_EventDetected[iChannel].channel=iChannel; // OK, we have a voice
and it is of the correct length
// so, we write the details to the struct (above) and then onto the
queue.
m_iCaptureAudio[iChannel]=0;
#ifndef NDEBUG
g_AudioBuffer.setName(this->m_sCardName);
g_AudioBuffer.write();
#endif
debug.printf_(" Ok Sound length %i
\n",m_iVoiceEnded[iChannel]-m_iVoiceStarted[iChannel]);
debug.printf_(" Sound Energy on Channel %i = %f \n",iChannel,
m_fSoundEnergy[iChannel]);
} else {
debug.printf_(" Fail Sound length %i < %i
\n",m_iVoiceEnded[iChannel]-m_iVoiceStarted[iChannel],
g_iMilisMinimumLength);
#ifndef NDEBUG
g_AudioBuffer.clear();
#endif
}
m_iVoiceStarted[iChannel]=0;
} else {
return;
}
}
} else //<------------------------- extra else ????
m_iVoiceEnded[iChannel]=0;
m_bVoice[iChannel]=bDetected;
}
I've been handed some code and, unless I've got the numbering of
parentheses wrong, one of the functions has a curious if-else
statement. The thing compiles but is it right?
I know the code contains non-standard C++, but its only the if
statement I'm after. It seems to
go:
if (condition){
}
else
{
}
else
??????????????
void CAudioProcessFrame::Voice(int iChannel, bool bDetected)
{
if (g_bVoiceTraining)
return;
if (m_bVoice[iChannel]!=bDetected) {
char szCad[512];
if (bDetected) {
if (!m_iVoiceStarted[iChannel]) { // So we have detected a voice and
it hasn't started yet.
m_iVoiceStarted[iChannel]=g_ticks;
debug.printf_(" Sound started %i \n",g_ticks);
m_EventDetected[iChannel].in_msec=libVAD_GetCurrentTimestamp(); //
When has this sound event started?
m_EventDetected[iChannel].out_msec=libVAD_GetCurrentTimestamp();
#ifndef NDEBUG
g_AudioBuffer.clear();
#endif
m_iCaptureAudio[iChannel]=1;
}
m_iVoiceEnded[iChannel]=0;
sprintf(szCad," Voice detected on channel %i card %i [%s]",
iChannel, m_iIndex, m_sCardName.c_str());
} else {
if (!m_iVoiceEnded[iChannel]) {
m_iVoiceEnded[iChannel]=g_ticks;
debug.printf_(" Sound ended %i \n",g_ticks);
}
int iElapsed=g_ticks-m_iVoiceEnded[iChannel];
if (iElapsed>g_iMilisPause) {
int
iTotalVoice=(m_iVoiceEnded[iChannel]-m_iVoiceStarted[iChannel]);
if (iTotalVoice>g_iMilisMinimumLength) {
sprintf(szCad," End of voice on channel %i card %i [%s]",
iChannel, m_iIndex, m_sCardName.c_str());
m_EventDetected[iChannel].channel=iChannel; // OK, we have a voice
and it is of the correct length
// so, we write the details to the struct (above) and then onto the
queue.
m_iCaptureAudio[iChannel]=0;
#ifndef NDEBUG
g_AudioBuffer.setName(this->m_sCardName);
g_AudioBuffer.write();
#endif
debug.printf_(" Ok Sound length %i
\n",m_iVoiceEnded[iChannel]-m_iVoiceStarted[iChannel]);
debug.printf_(" Sound Energy on Channel %i = %f \n",iChannel,
m_fSoundEnergy[iChannel]);
} else {
debug.printf_(" Fail Sound length %i < %i
\n",m_iVoiceEnded[iChannel]-m_iVoiceStarted[iChannel],
g_iMilisMinimumLength);
#ifndef NDEBUG
g_AudioBuffer.clear();
#endif
}
m_iVoiceStarted[iChannel]=0;
} else {
return;
}
}
} else //<------------------------- extra else ????
m_iVoiceEnded[iChannel]=0;
m_bVoice[iChannel]=bDetected;
}