Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions os/drivers/ai-soc/ndp120/src/ndp120_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator

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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand All @@ -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;
Expand All @@ -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);

/*
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much indentation.

&bytes_before_match);
dev->keyword_correction = false;
}
}

return s;
Expand Down
1 change: 1 addition & 0 deletions os/drivers/audio/ndp120_voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct ndp120_dev_s {
uint32_t extract_size;
bool extclk_inuse;
volatile bool alive;
bool keyword_correction;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
Expand Down