-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ai-soc/ndp120: implement packages loding to NDP120 in chunks #6561
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let us not hardcode this. Let us atleast use a #define instead. |
||
|
||
/* | ||
* 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too much indentation. |
||
&bytes_before_match); | ||
dev->keyword_correction = false; | ||
} | ||
} | ||
|
||
return s; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ struct ndp120_dev_s { | |
uint32_t extract_size; | ||
bool extclk_inuse; | ||
volatile bool alive; | ||
bool keyword_correction; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on what basis the keyword_correction is enabled and disabled? Do we need to provide this control also to the application? |
||
|
||
/* moved to using pthread cond variable for parity with reference implementation in ilib examples */ | ||
pthread_mutex_t ndp_mutex_mbsync; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to provide this chunk size with config?