VAD refactoring

* Added TODO comment
* Updated unit test
* Code style changes and added comments to set_mode()

BUG=
TEST=vad_unittests, audioproc_unittest, voe_auto_test

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1943 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bjornv@webrtc.org 2012-03-27 11:06:29 +00:00
parent 534a435751
commit 78f0cdc191
3 changed files with 33 additions and 35 deletions

View File

@ -62,25 +62,21 @@ int WebRtcVad_Free(VadInst* handle);
// - handle [i/o] : Instance that should be initialized. // - handle [i/o] : Instance that should be initialized.
// //
// returns : 0 - (OK), // returns : 0 - (OK),
// -1 - (NULL pointer or Default mode could not be set) // -1 - (NULL pointer or Default mode could not be set).
int WebRtcVad_Init(VadInst* handle); int WebRtcVad_Init(VadInst* handle);
/**************************************************************************** // Sets the VAD operating mode. A more aggressive (higher mode) VAD is more
* WebRtcVad_set_mode(...) // restrictive in reporting speech. Put in other words the probability of being
* // speech when the VAD returns 1 is increased with increasing mode. As a
* This function initializes a VAD instance // consequence also the missed detection rate goes up.
* //
* Input: // - handle [i/o] : VAD instance.
* - vad_inst : VAD instance // - mode [i] : Aggressiveness mode (0, 1, 2, or 3).
* - mode : Aggressiveness setting (0, 1, 2, or 3) //
* // returns : 0 - (OK),
* Output: // -1 - (NULL pointer, mode could not be set or the VAD instance
* - vad_inst : Initialized instance // has not been initialized).
* int WebRtcVad_set_mode(VadInst* handle, int mode);
* Return value : 0 - Ok
* -1 - Error
*/
int WebRtcVad_set_mode(VadInst *vad_inst, int mode);
/**************************************************************************** /****************************************************************************
* WebRtcVad_Process(...) * WebRtcVad_Process(...)

View File

@ -12,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "common_audio/signal_processing/include/signal_processing_library.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "typedefs.h" #include "typedefs.h"
#include "webrtc_vad.h" #include "webrtc_vad.h"
@ -61,7 +62,7 @@ TEST_F(VadTest, ApiTest) {
speech[i] = (i * i); speech[i] = (i * i);
} }
// Null instance tests // NULL instance tests
EXPECT_EQ(-1, WebRtcVad_Create(NULL)); EXPECT_EQ(-1, WebRtcVad_Create(NULL));
EXPECT_EQ(-1, WebRtcVad_Init(NULL)); EXPECT_EQ(-1, WebRtcVad_Init(NULL));
EXPECT_EQ(-1, WebRtcVad_Assign(NULL, NULL)); EXPECT_EQ(-1, WebRtcVad_Assign(NULL, NULL));
@ -91,9 +92,14 @@ TEST_F(VadTest, ApiTest) {
// WebRtcVad_Init() test // WebRtcVad_Init() test
ASSERT_EQ(0, WebRtcVad_Init(handle)); ASSERT_EQ(0, WebRtcVad_Init(handle));
// WebRtcVad_set_mode() invalid modes tests // WebRtcVad_set_mode() invalid modes tests. Tries smallest supported value
EXPECT_EQ(-1, WebRtcVad_set_mode(handle, kModes[0] - 1)); // minus one and largest supported value plus one.
EXPECT_EQ(-1, WebRtcVad_set_mode(handle, kModes[kModesSize - 1] + 1)); EXPECT_EQ(-1, WebRtcVad_set_mode(handle,
WebRtcSpl_MinValueW32(kModes,
kModesSize) - 1));
EXPECT_EQ(-1, WebRtcVad_set_mode(handle,
WebRtcSpl_MaxValueW32(kModes,
kModesSize) + 1));
// WebRtcVad_Process() tests // WebRtcVad_Process() tests
// NULL speech pointer // NULL speech pointer

View File

@ -65,22 +65,18 @@ int WebRtcVad_Init(VadInst* handle) {
return WebRtcVad_InitCore((VadInstT*) handle); return WebRtcVad_InitCore((VadInstT*) handle);
} }
int WebRtcVad_set_mode(VadInst *vad_inst, int mode) // TODO(bjornv): Move WebRtcVad_set_mode_core() code here.
{ int WebRtcVad_set_mode(VadInst* handle, int mode) {
VadInstT* vad_ptr; VadInstT* self = (VadInstT*) handle;
if (vad_inst == NULL) if (handle == NULL) {
{ return -1;
return -1; }
} if (self->init_flag != kInitCheck) {
return -1;
}
vad_ptr = (VadInstT*)vad_inst; return WebRtcVad_set_mode_core(self, mode);
if (vad_ptr->init_flag != kInitCheck)
{
return -1;
}
return WebRtcVad_set_mode_core((VadInstT*)vad_inst, mode);
} }
WebRtc_Word16 WebRtcVad_Process(VadInst *vad_inst, WebRtc_Word16 WebRtcVad_Process(VadInst *vad_inst,