diff --git a/os/drivers/ai-soc/ndp120/src/ndp120_api.c b/os/drivers/ai-soc/ndp120/src/ndp120_api.c index f6515fd668..9d4ddac59b 100644 --- a/os/drivers/ai-soc/ndp120/src/ndp120_api.c +++ b/os/drivers/ai-soc/ndp120/src/ndp120_api.c @@ -446,6 +446,7 @@ static int load_synpkg(struct syntiant_ndp_device_s *ndp, const char *p) int s = 0; int pfd; int rl; + int chunk_size = 1024; /* * load synpkg file @@ -457,7 +458,7 @@ static int load_synpkg(struct syntiant_ndp_device_s *ndp, const char *p) package_len = st.st_size; - package = kmm_malloc(package_len); + package = kmm_malloc(chunk_size); if (!package) { auddbg("no memory for package_load\n"); return SYNTIANT_NDP_ERROR_FAIL; @@ -466,18 +467,10 @@ static int load_synpkg(struct syntiant_ndp_device_s *ndp, const char *p) pfd = open(p, O_RDONLY); if (pfd < 0) { auddbg("unable to open synpkg file\n"); - s = SYNTIANT_NDP_ERROR_FAIL; - goto errorout_with_package; - } - - rl = read(pfd, package, package_len); - if (check_io("synpkg file read", package_len, rl)) { - s = SYNTIANT_NDP_ERROR_FAIL; - goto errorout_with_package; + free(package); + return SYNTIANT_NDP_ERROR_FAIL; } - close(pfd); - auddbg("Loading %d bytes of package data\n", package_len); /* @@ -490,14 +483,33 @@ static int load_synpkg(struct syntiant_ndp_device_s *ndp, const char *p) } /* - * load the entire synpkg object with a single call + * load the synpkg object in chunks */ - s = syntiant_ndp_load(ndp, package, package_len); - if (check_status("load", s)) { - goto errorout_with_package; + int data_left = package_len; + while (s == SYNTIANT_NDP_ERROR_MORE) { + + int load_len = chunk_size < data_left ? chunk_size : data_left; + + rl = read(pfd, package, load_len); + if (rl <= 0) { + s = SYNTIANT_NDP_ERROR_FAIL; + goto errorout_with_package; + } + + load_len = rl; + + s = syntiant_ndp_load(ndp, package, load_len); + if (s && s != SYNTIANT_NDP_ERROR_MORE) { + if (check_status("load", s)) { + goto errorout_with_package; + } + } + + data_left -= load_len; } errorout_with_package: + close(pfd); free(package); return s; } @@ -1151,6 +1163,7 @@ int ndp120_init(struct ndp120_dev_s *dev, bool reinit) } #endif dev->alive = true; + dev->keyword_correction = false; errout_ndp120_init: return s; @@ -1332,6 +1345,7 @@ int ndp120_irq_handler_work(struct ndp120_dev_s *dev) #ifdef CONFIG_NDP120_AEC_SUPPORT g_ndp120_state = IS_RECORDING; #endif + dev->keyword_correction = true; msg.msgId = AUDIO_MSG_KD; } else if (network_id == 1) { switch (winner) { @@ -1506,6 +1520,7 @@ int ndp120_kd_start_match_process(struct ndp120_dev_s *dev) { int ndp120_start_sample_ready(struct ndp120_dev_s *dev) { int s; + #ifdef CONFIG_NDP120_AEC_SUPPORT g_ndp120_state = IS_RECORDING; #endif @@ -1517,10 +1532,13 @@ int ndp120_start_sample_ready(struct ndp120_dev_s *dev) uint32_t bytes_before_match = 0; if (!dev->running) { - /* we need not do this if this is resume case, we only need to do it if its recorder start case after keyword detection */ - s = syntiant_ndp_extract_data(dev->ndp, SYNTIANT_NDP_EXTRACT_TYPE_INPUT, + if (dev->keyword_correction) { + /* we need not do this if this is resume case, we only need to do it if its recorder start case after keyword detection */ + s = syntiant_ndp_extract_data(dev->ndp, SYNTIANT_NDP_EXTRACT_TYPE_INPUT, SYNTIANT_NDP_EXTRACT_FROM_MATCH, NULL, &bytes_before_match); + dev->keyword_correction = false; + } } return s; diff --git a/os/drivers/audio/ndp120_voice.h b/os/drivers/audio/ndp120_voice.h index 3056fbad6c..49b3a6c1ee 100644 --- a/os/drivers/audio/ndp120_voice.h +++ b/os/drivers/audio/ndp120_voice.h @@ -78,6 +78,7 @@ struct ndp120_dev_s { uint32_t extract_size; bool extclk_inuse; volatile bool alive; + bool keyword_correction; /* moved to using pthread cond variable for parity with reference implementation in ilib examples */ pthread_mutex_t ndp_mutex_mbsync;