From 671f75b246e5e99c527b8f58d03d83686bfc8bb8 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Wed, 3 Apr 2019 15:04:02 +0800 Subject: [PATCH] FS-11753 tweak vad test code and add debug logs --- .../applications/mod_dptools/mod_dptools.c | 44 +++++++++---------- src/switch_vad.c | 16 +++++++ 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 91999f91b3..4a9edf54e8 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -6245,25 +6245,6 @@ 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"))) { - tmp = atoi(var); - - if (tmp > 0) switch_vad_set_param(vad, "hangover_len", tmp); - } - - if ((var = switch_channel_get_variable(channel, "vad_thresh"))) { - tmp = atoi(var); - - if (tmp > 0) switch_vad_set_param(vad, "thresh", tmp); - } - - if ((var = switch_channel_get_variable(channel, "vad_listen_hits"))) { - tmp = atoi(var); - - if (tmp > 0) switch_vad_set_param(vad, "listen_hits", tmp); - } if ((var = switch_channel_get_variable(channel, "vad_debug"))) { tmp = atoi(var); @@ -6274,6 +6255,26 @@ SWITCH_STANDARD_APP(vad_test_function) switch_vad_set_param(vad, "debug", tmp); } + 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, "sicence_ms", tmp); + } + + if ((var = switch_channel_get_variable(channel, "vad_thresh"))) { + tmp = atoi(var); + + if (tmp > 0) switch_vad_set_param(vad, "thresh", tmp); + } + + if ((var = switch_channel_get_variable(channel, "vad_voice_ms"))) { + tmp = atoi(var); + + if (tmp > 0) switch_vad_set_param(vad, "voice_ms", tmp); + } + while (switch_channel_ready(channel)) { switch_status_t status = switch_core_session_read_frame(session, &frame, SWITCH_IO_FLAG_NONE, 0); @@ -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)); } } diff --git a/src/switch_vad.c b/src/switch_vad.c index 9e7ab0f773..e9c1232103 100644 --- a/src/switch_vad.c +++ b/src/switch_vad.c @@ -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; }