From d83912ff24ee8b8210e9a6083035c618a0bcde2c Mon Sep 17 00:00:00 2001 From: Marcin Rajwa Date: Thu, 16 May 2019 11:54:39 +0200 Subject: [PATCH] detector: add history depth as config option Detector was using keyphrase_length to: 1. delay detection 2. to calculate the amount of data that shall be drained from history buffer. This was confusing people, therefore we use two separate variables name with better naming. 1. history_depth -> to define default draining request. (in bytes) 2. preamble_time -> to define delay after which detection should be active. Signed-off-by: Marcin Rajwa --- src/audio/detect_test.c | 19 +++++++++++++------ src/include/user/detect_test.h | 10 ++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/audio/detect_test.c b/src/audio/detect_test.c index d0713d642..9de4c754f 100644 --- a/src/audio/detect_test.c +++ b/src/audio/detect_test.c @@ -40,6 +40,7 @@ struct comp_data { uint32_t detect_preamble; /**< current keyphrase preamble length */ uint32_t keyphrase_samples; /**< keyphrase length in samples */ uint32_t buf_copy_pos; /**< current copy position for incoming data */ + uint32_t history_depth; /** defines draining size in bytes. */ struct notify_data event; struct kpb_event_data event_data; @@ -73,9 +74,9 @@ static void notify_kpb(struct comp_dev *dev) cd->client_data.history_end = 0; /**< keyphrase end, 0 is now */ cd->client_data.history_begin = cd->detect_preamble; /* time in milliseconds */ - cd->client_data.history_depth = cd->detect_preamble / - (dev->params.rate / 1000); - + cd->client_data.history_depth = (cd->history_depth != 0) ? + cd->history_depth : + cd->config.history_depth; cd->event_data.event_id = KPB_EVENT_BEGIN_DRAINING; cd->event_data.client_data = &cd->client_data; @@ -118,6 +119,12 @@ static void default_detect_test(struct comp_dev *dev, if (cd->detect_preamble >= cd->keyphrase_samples) { if (cd->activation >= cd->config.activation_threshold) { + /* The algorithm shall use cd->history_depth + * to specify its draining size request. + * Zero value means default config value + * will be used. + */ + cd->history_depth = 0; detect_test_notify(dev); cd->detected = 1; } @@ -280,14 +287,14 @@ static int test_keyword_params(struct comp_dev *dev) dev->frame_bytes = comp_frame_bytes(dev); /* calculate the length of the preamble */ - if (cd->config.keyphrase_length) { - if (cd->config.keyphrase_length > KPB_MAX_BUFF_TIME) { + if (cd->config.preamble_time) { + if (cd->config.preamble_time > KPB_MAX_BUFF_TIME) { trace_keyword_error("test_keyword_params() " "error: kp length too long"); return -EINVAL; } - cd->keyphrase_samples = cd->config.keyphrase_length * + cd->keyphrase_samples = cd->config.preamble_time * (dev->params.rate / 1000); } else { cd->keyphrase_samples = KEYPHRASE_DEFAULT_PREAMBLE_LENGTH; diff --git a/src/include/user/detect_test.h b/src/include/user/detect_test.h index d56efd084..02cc85a84 100644 --- a/src/include/user/detect_test.h +++ b/src/include/user/detect_test.h @@ -18,9 +18,8 @@ struct sof_detect_test_config { /** synthetic system load settings */ uint32_t load_mips; uint32_t load_memory_size; - - /** length of the keyphrase in milliseconds */ - uint32_t keyphrase_length; + /** time in ms after which detection is activated */ + uint32_t preamble_time; /** activation right shift, determines the speed of activation */ uint16_t activation_shift; @@ -28,8 +27,11 @@ struct sof_detect_test_config { /** activation threshold */ int16_t activation_threshold; + /** default draining size in bytes */ + uint32_t history_depth; + /** reserved for future use */ - uint32_t reserved[3]; + uint32_t reserved[2]; } __attribute__((packed)); /** used for binary blob size sanity checks */