]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11753 tweak vad test code and add debug logs
authorSeven Du <seven@signalwire.com>
Wed, 3 Apr 2019 07:04:02 +0000 (15:04 +0800)
committerAndrey Volk <andywolk@gmail.com>
Wed, 17 Jul 2019 18:57:53 +0000 (22:57 +0400)
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_vad.c

index 91999f91b365bdb72559824c3c704816caa65a24..4a9edf54e8565199325c61500f76c806f849e93b 100644 (file)
@@ -6245,33 +6245,34 @@ SWITCH_STANDARD_APP(vad_test_function)
 
        vad = switch_vad_init(imp.samples_per_second, imp.number_of_channels);
        switch_assert(vad);
-       switch_vad_set_mode(vad, mode);
 
-       if ((var = switch_channel_get_variable(channel, "vad_hangover_len"))) {
+       if ((var = switch_channel_get_variable(channel, "vad_debug"))) {
                tmp = atoi(var);
 
-               if (tmp > 0) switch_vad_set_param(vad, "hangover_len", tmp);
+               if (tmp < 0) tmp = 0;
+               if (tmp > 1) tmp = 1;
+
+               switch_vad_set_param(vad, "debug", tmp);
        }
 
-       if ((var = switch_channel_get_variable(channel, "vad_thresh"))) {
+       switch_vad_set_mode(vad, mode);
+
+       if ((var = switch_channel_get_variable(channel, "vad_silence_ms"))) {
                tmp = atoi(var);
 
-               if (tmp > 0) switch_vad_set_param(vad, "thresh", tmp);
+               if (tmp > 0) switch_vad_set_param(vad, "sicence_ms", tmp);
        }
 
-       if ((var = switch_channel_get_variable(channel, "vad_listen_hits"))) {
+       if ((var = switch_channel_get_variable(channel, "vad_thresh"))) {
                tmp = atoi(var);
 
-               if (tmp > 0) switch_vad_set_param(vad, "listen_hits", tmp);
+               if (tmp > 0) switch_vad_set_param(vad, "thresh", tmp);
        }
 
-       if ((var = switch_channel_get_variable(channel, "vad_debug"))) {
+       if ((var = switch_channel_get_variable(channel, "vad_voice_ms"))) {
                tmp = atoi(var);
 
-               if (tmp < 0) tmp = 0;
-               if (tmp > 1) tmp = 1;
-
-               switch_vad_set_param(vad, "debug", tmp);
+               if (tmp > 0) switch_vad_set_param(vad, "voice_ms", tmp);
        }
 
        while (switch_channel_ready(channel)) {
@@ -6288,14 +6289,13 @@ SWITCH_STANDARD_APP(vad_test_function)
                vad_state = switch_vad_process(vad, frame->data, frame->datalen / 2);
 
                if (vad_state == SWITCH_VAD_STATE_START_TALKING) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "START TALKING\n");
                        switch_core_session_write_frame(session, frame, SWITCH_IO_FLAG_NONE, 0);
                } else if (vad_state == SWITCH_VAD_STATE_STOP_TALKING) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STOP TALKING\n");
+                       switch_vad_reset(vad);
                } else if (vad_state == SWITCH_VAD_STATE_TALKING) {
                        switch_core_session_write_frame(session, frame, SWITCH_IO_FLAG_NONE, 0);
                } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "vad_state: %s\n", switch_vad_state2str(vad_state));
+                       // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "vad_state: %s\n", switch_vad_state2str(vad_state));
                }
        }
 
index 9e7ab0f773eac3d27809a1f8a7fd2bbd79a0a151..e9c12321036cedbdd6597bf7bfb5f0debf17b081 100644 (file)
@@ -122,6 +122,8 @@ SWITCH_DECLARE(int) switch_vad_set_mode(switch_vad_t *vad, int mode)
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "libfvad started, mode = %d\n", mode);
        return ret;
 #else
+       if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "set vad mode = %d\n", mode);
+
        return 0;
 #endif
 }
@@ -155,6 +157,10 @@ SWITCH_DECLARE(void) switch_vad_set_param(switch_vad_t *vad, const char *key, in
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "listen_hits is deprecated, setting voice_ms to %d\n", 20 * val);
                switch_vad_set_param(vad, "voice_ms", 20 * val);
        }
+
+       if (vad->debug) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "set %s to %d\n", key, val);
+       }
 }
 
 SWITCH_DECLARE(void) switch_vad_reset(switch_vad_t *vad)
@@ -167,6 +173,8 @@ SWITCH_DECLARE(void) switch_vad_reset(switch_vad_t *vad)
        vad->vad_state = SWITCH_VAD_STATE_NONE;
        vad->voice_samples = 0;
        vad->silence_samples = 0;
+
+       if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "reset vad state\n");
 }
 
 SWITCH_DECLARE(switch_vad_state_t) switch_vad_process(switch_vad_t *vad, int16_t *data, unsigned int samples)
@@ -199,6 +207,10 @@ SWITCH_DECLARE(switch_vad_state_t) switch_vad_process(switch_vad_t *vad, int16_t
        }
 #endif
 
+       if (vad->debug > 9) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "score: %d\n", score);
+       }
+
        // clear the STOP/START TALKING events
        if (vad->vad_state == SWITCH_VAD_STATE_STOP_TALKING) {
                vad->vad_state = SWITCH_VAD_STATE_NONE;
@@ -218,10 +230,14 @@ SWITCH_DECLARE(switch_vad_state_t) switch_vad_process(switch_vad_t *vad, int16_t
        // check for state transitions
        if (vad->vad_state == SWITCH_VAD_STATE_TALKING && vad->silence_samples > vad->silence_samples_thresh) {
                vad->vad_state = SWITCH_VAD_STATE_STOP_TALKING;
+               if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "vad state STOP_TALKING\n");
        } else if (vad->vad_state == SWITCH_VAD_STATE_NONE && vad->voice_samples > vad->voice_samples_thresh) {
                vad->vad_state = SWITCH_VAD_STATE_START_TALKING;
+               if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "vad state START_TALKING\n");
        }
 
+       if (vad->debug > 9) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "vad state %s\n", switch_vad_state2str(vad->vad_state));
+
        return vad->vad_state;
 }