summaryrefslogtreecommitdiff
path: root/common/audio_codec_wov.c
diff options
context:
space:
mode:
authorTzung-Bi Shih <tzungbi@chromium.org>2019-07-02 03:05:33 +0800
committerCommit Bot <commit-bot@chromium.org>2019-09-19 07:59:08 +0000
commitf337d5b320867c74672f517c87543acaa447278c (patch)
tree692d1b2d048063cced39764c4e4cbc7139ba23cb /common/audio_codec_wov.c
parentaa17252161c5cc526555c2f82ad238361f7d22a0 (diff)
downloadchrome-ec-f337d5b320867c74672f517c87543acaa447278c.tar.gz
audio_codec: integrate speech-micro
Leverage speech-micro to detect hotword. BRANCH=none BUG=b:122027734, b:123268236, b:132319180 TEST=1. define CONFIG_AUDIO_CODEC in board.h 2. define CONFIG_AUDIO_CODEC_DMIC in board.h 3. define CONFIG_AUDIO_CODEC_DMIC_SOFTWARE_GAIN in board.h 4. define CONFIG_AUDIO_CODEC_DMIC_MAX_SOFTWARE_GAIN in board.h 5. define CONFIG_AUDIO_CODEC_WOV in board.h 6. make BOARD=kukui_scp -j Change-Id: I8b238fd8bd9af8e70d5a747650eb8b7dbf4200cb Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1602453 Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'common/audio_codec_wov.c')
-rw-r--r--common/audio_codec_wov.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/common/audio_codec_wov.c b/common/audio_codec_wov.c
index 3609967d9d..30ffe98836 100644
--- a/common/audio_codec_wov.c
+++ b/common/audio_codec_wov.c
@@ -7,6 +7,7 @@
#include "audio_codec.h"
#include "console.h"
#include "host_command.h"
+#include "hotword_dsp_api.h"
#include "sha256.h"
#include "system.h"
#include "task.h"
@@ -60,6 +61,9 @@ static int is_buf_full(void)
return ((audio_buf_wp + 2) % AUDIO_BUF_LEN) == audio_buf_rp;
}
+/* only used by host command */
+static uint8_t speech_lib_loaded;
+
static int check_lang_buf(uint8_t *data, uint32_t len, const uint8_t *hash)
{
/*
@@ -108,6 +112,7 @@ static int wov_set_lang_shm(struct host_cmd_handler_args *args)
memcpy(lang_hash, pp->hash, sizeof(lang_hash));
lang_len = pp->total_len;
+ speech_lib_loaded = 0;
args->response_size = 0;
return EC_RES_SUCCESS;
@@ -143,6 +148,7 @@ static int wov_set_lang(struct host_cmd_handler_args *args)
memcpy(lang_hash, pp->hash, sizeof(lang_hash));
lang_len = pp->total_len;
+ speech_lib_loaded = 0;
}
args->response_size = 0;
@@ -168,6 +174,15 @@ static int wov_enable(struct host_cmd_handler_args *args)
if (audio_codec_wov_enable() != EC_SUCCESS)
return EC_RES_ERROR;
+ if (!speech_lib_loaded) {
+ if (!GoogleHotwordDspInit(
+ (void *)audio_codec_wov_lang_buf_addr))
+ return EC_RES_ERROR;
+ speech_lib_loaded = 1;
+ } else {
+ GoogleHotwordDspReset();
+ }
+
mutex_lock(&lock);
wov_enabled = 1;
hotword_detected = 0;
@@ -334,6 +349,7 @@ void audio_codec_wov_task(void *arg)
{
uint32_t n, req;
uint8_t *p;
+ int r;
while (1) {
mutex_lock(&lock);
@@ -395,6 +411,29 @@ void audio_codec_wov_task(void *arg)
mutex_unlock(&lock);
/*
+ * GoogleHotwordDspProcess() needs number of samples. In the
+ * case, sample is S16_LE. Thus, n / 2.
+ */
+ if (!hotword_detected &&
+ GoogleHotwordDspProcess(p, n / 2, &r)) {
+ CPRINTS("hotword detected");
+
+ mutex_lock(&lock);
+ /*
+ * Note: preserve 40% of buf size for AP to read
+ * (see go/cros-ec-codec#heading=h.582ga6pgfl2g)
+ */
+ audio_buf_rp = audio_buf_wp + (AUDIO_BUF_LEN * 2 / 5);
+ if (audio_buf_rp >= AUDIO_BUF_LEN)
+ audio_buf_rp -= AUDIO_BUF_LEN;
+
+ hotword_detected = 1;
+ mutex_unlock(&lock);
+
+ host_set_single_event(EC_HOST_EVENT_WOV);
+ }
+
+ /*
* Reasons to sleep here:
* 1. read the audio data in a fixed pace (10ms)
* 2. yield the processor in case of watchdog thought EC crashed