Skip to content
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
10 changes: 8 additions & 2 deletions apps/examples/wakerec/wakerec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <media/voice/SpeechDetectorListenerInterface.h>
#include <media/FocusManager.h>
#include <media/stream_info.h>
#include <audio/SoundManager.h>
#include <iostream>
#include <memory>
#include <functional>
Expand Down Expand Up @@ -124,7 +125,7 @@ class WakeRec : public media::voice::SpeechDetectorListenerInterface,public Focu
return;
}

if (mr.setDuration(7) == RECORDER_ERROR_NONE && mr.prepare() == RECORDER_ERROR_NONE) {
if (mr.setDuration(15) == RECORDER_ERROR_NONE && mr.prepare() == RECORDER_ERROR_NONE) {
printf("#### [MR] prepare succeeded.\n");
} else {
printf("#### [MR] prepare failed.\n");
Expand Down Expand Up @@ -347,7 +348,12 @@ int wakerec_main(int argc, char *argv[])
return -1;
}
auto recorder = std::shared_ptr<WakeRec>(new WakeRec());
if (argc == 2 && atoi(argv[1]) == 0) {
if (atoi(argv[1]) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (argc == 3 && atoi(argv[1]) == 0)

uint8_t select_dsp_rules = atoi(argv[2]);
if (changeDSPFlow(select_dsp_rules)) {
printf("Success changeDSPFlow\n");
}

printf("disable KD!!\n");
recorder->initWakeRec(false);
recorder->startRecord();
Expand Down
7 changes: 7 additions & 0 deletions framework/include/audio/SoundManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ bool setStreamMute(stream_policy_t stream_policy, bool mute);
*/
bool getStreamMuteState(stream_policy_t stream_policy, bool *mute);

/**
* @brief Change dsp flow rule.
* @param[in] dwp flow rule number to be changed.
* @return true if the operation was successful, false otherwise.
*/
bool changeDSPFlow(uint8_t dsp_flow_num);

#if defined(__cplusplus)
}
#endif
Expand Down
17 changes: 17 additions & 0 deletions framework/src/audio/SoundManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,20 @@ bool getStreamMuteState(stream_policy_t stream_policy, bool *mute)
return true;
}

bool changeDSPFlow(uint8_t dsp_flow_num)
{
if (dsp_flow_num == 0) {
meddbg("dsp_flow_num can not be 0, it starts from 1\n");
return false;
}

meddbg("SoundManager : changeDSPFlow. dsp_flow_num: %d\n", dsp_flow_num);
audio_manager_result_t res = change_input_dsp_flow(dsp_flow_num);
if (res != AUDIO_MANAGER_SUCCESS) {
meddbg("change_output_dsp_flow failed dsp_flow_num : %d, ret : %d\n", dsp_flow_num, res);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not matching with calling function and msg.
change_output_dsp_flow failed dsp_flow_num -> change_input_dsp_flow failed dsp_flow_num

return false;
}
return true;
}


21 changes: 21 additions & 0 deletions framework/src/media/audio/audio_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,27 @@ audio_manager_result_t get_audio_stream_mute_state(stream_policy_t stream_policy
return AUDIO_MANAGER_SUCCESS;
}

audio_manager_result_t change_input_dsp_flow(uint8_t dsp_flow_num)
{
audio_manager_result_t ret;
struct audio_caps_desc_s caps_desc;
Copy link
Contributor

Choose a reason for hiding this comment

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

caps_desc not used anywhere

audio_card_info_t *card;
char card_path[AUDIO_DEVICE_FULL_PATH_LENGTH];

card = &g_audio_in_cards[g_actual_audio_in_card_id];
get_card_path(card_path, card->card_id, card->device_id, INPUT);

pthread_mutex_lock(&(card->card_mutex));

ret = control_audio_stream_device(card_path, AUDIOIOC_CHANGEDSPFLOW, (unsigned long)dsp_flow_num);
if (ret != AUDIO_MANAGER_SUCCESS) {
meddbg("Fail to change dsp flow, ret = %d errno : %d\n", ret, get_errno());
}

pthread_mutex_unlock(&(card->card_mutex));
return ret;
}

#ifdef CONFIG_DEBUG_MEDIA_INFO
void print_audio_card_info(audio_io_direction_t direct)
{
Expand Down
15 changes: 15 additions & 0 deletions framework/src/media/audio/audio_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,21 @@ audio_manager_result_t set_audio_stream_mute_from_json(stream_policy_t stream_po
****************************************************************************/
audio_manager_result_t get_audio_stream_mute_state(stream_policy_t stream_policy, bool *mute);

/****************************************************************************
* Name: change_input_dsp_flow
*
* Description:
* It changes the current dsp flow to dsp flow of given number.
*
* Input parameter:
* stream_policy: dwp flow rule number to be changed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor comment

  Input parameter:
  	 dsp_flow_num: dsp flow rule number to be changed. 1 for AFE processed data & 2 for raw audio data

* mute: pointer to store the mute state of given stream policy.
*
* Return Value:
* On success, AUDIO_MANAGER_SUCCESS. Otherwise, a negative value.
****************************************************************************/
audio_manager_result_t change_input_dsp_flow(uint8_t dsp_flow_num);

#ifdef CONFIG_DEBUG_MEDIA_INFO
/****************************************************************************
* Name: dump_audio_card_info
Expand Down
116 changes: 109 additions & 7 deletions os/drivers/ai-soc/ndp120/src/ndp120_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static struct ndp120_dev_s *_ndp_debug_handle = NULL;
/****************************************************************************
* Function Prototypes
****************************************************************************/
int ndp120_init(struct ndp120_dev_s *dev, bool reinit);
int ndp120_init(struct ndp120_dev_s *dev, uint8_t dsp_fw_num);
void ndp120_aec_enable(struct ndp120_dev_s *dev);
void ndp120_aec_disable(struct ndp120_dev_s *dev);
void ndp120_test_internal_passthrough_switch(struct ndp120_dev_s *dev, int internal);
Expand Down Expand Up @@ -965,6 +965,65 @@ void add_dsp_flow_rules(struct syntiant_ndp_device_s *ndp)

}

static
void add_dsp_flow_rules_extract_raw_data(struct syntiant_ndp_device_s *ndp)
{
int s = 0;
ndp120_dsp_data_flow_setup_t setup;

int src_pcm = 0;
int src_func = 0;
int src_nn = 0;

memset(&setup, 0, sizeof(setup));

// ----------
// COMBINED NORMAL + AEC FLOW
/* PCM7->FUNCx */
setup.src_pcm_audio[src_pcm].src_param = NDP120_DSP_DATA_FLOW_SRC_PARAM_AUD0_STEREO;
#ifdef CONFIG_NDP120_AEC_SUPPORT
setup.src_pcm_audio[src_pcm].src_param |= NDP120_DSP_DATA_FLOW_SRC_PARAM_AUD1_LEFT;
#endif
setup.src_pcm_audio[src_pcm].dst_param = FF_ID;
setup.src_pcm_audio[src_pcm].dst_type = NDP120_DSP_DATA_FLOW_DST_TYPE_FUNCTION;
setup.src_pcm_audio[src_pcm].algo_config_index = 0;
setup.src_pcm_audio[src_pcm].set_id = COMBINED_FLOW_SET_ID;
setup.src_pcm_audio[src_pcm].algo_exec_property = 0;
src_pcm++;

/* FUNCx->NN0 */
setup.src_function[src_func].src_param = FF_ID;
setup.src_function[src_func].dst_param = KEYWORD_NETWORK_ID;
setup.src_function[src_func].dst_type = NDP120_DSP_DATA_FLOW_DST_TYPE_NN;
setup.src_function[src_func].algo_config_index = -1;
setup.src_function[src_func].set_id = COMBINED_FLOW_SET_ID;
setup.src_function[src_func].algo_exec_property = 0;
src_func++;

/* PCMx->HOST_EXT_AUDIO */
setup.src_pcm_audio[src_pcm].src_param = NDP120_DSP_DATA_FLOW_SRC_PARAM_AUD0_LEFT;
setup.src_pcm_audio[src_pcm].dst_param = NDP120_DSP_DATA_FLOW_DST_SUBTYPE_AUDIO;
setup.src_pcm_audio[src_pcm].dst_type = NDP120_DSP_DATA_FLOW_DST_TYPE_HOST_EXTRACT;
setup.src_pcm_audio[src_pcm].algo_config_index = 0;
setup.src_pcm_audio[src_pcm].set_id = COMBINED_FLOW_SET_ID;
setup.src_pcm_audio[src_pcm].algo_exec_property = 0;
src_pcm++;

/* NN0->MCU */
setup.src_nn[src_nn].src_param = 0;
setup.src_nn[src_nn].dst_param = 0;
setup.src_nn[src_nn].dst_type = NDP120_DSP_DATA_FLOW_DST_TYPE_MCU;
setup.src_nn[src_nn].algo_config_index = -1;
setup.src_nn[src_nn].set_id = COMBINED_FLOW_SET_ID;
setup.src_nn[src_nn].algo_exec_property = 0;
src_nn++;

auddbg("Applied flow rules extract raw data\n");
s = syntiant_ndp120_dsp_flow_setup_apply(ndp, &setup);
check_status("syntiant_ndp120_dsp_flow_setup_apply", s);

}

#if BT_MIC_SUPPORT == 1
static
void add_dsp_flow_rules_btmic(struct syntiant_ndp_device_s *ndp)
Expand Down Expand Up @@ -1237,7 +1296,7 @@ check_firmware_aliveness(struct ndp120_dev_s *dev, uint32_t wait_period_ms)

dev->lower->reset();

s = ndp120_init(dev, true);
s = ndp120_init(dev, dev->cur_dsp_flow_num);

if (s) {
/* For now do nothing, there may be some cases where init might
Expand Down Expand Up @@ -1285,7 +1344,7 @@ ndp120_app_device_health_check(void)
}
#endif

int ndp120_init(struct ndp120_dev_s *dev, bool reinit)
int ndp120_init(struct ndp120_dev_s *dev, uint8_t dsp_fw_num)
{
/* File names */
int s;
Expand All @@ -1310,7 +1369,7 @@ int ndp120_init(struct ndp120_dev_s *dev, bool reinit)
/* save handle so we can use it from debug routine later, e.g. from other util/shell */
_ndp_debug_handle = dev;

if (!reinit) {
if (dsp_fw_num == 0) {
s = pthread_mutex_init(&dev->ndp_mutex_mbsync, NULL);
if (s) {
auddbg("failed to initialize mb sync mutex variable\n");
Expand Down Expand Up @@ -1380,8 +1439,22 @@ int ndp120_init(struct ndp120_dev_s *dev, bool reinit)
#if BT_MIC_SUPPORT == 1
// add special rules for BT-mic
add_dsp_flow_rules_btmic(dev->ndp);
dev->cur_dsp_flow_num = 1;
#else
add_dsp_flow_rules(dev->ndp);
switch(dsp_fw_num) {
case 1:
add_dsp_flow_rules(dev->ndp);
dev->cur_dsp_flow_num = 1;
break;
case 2:
add_dsp_flow_rules_extract_raw_data(dev->ndp);
dev->cur_dsp_flow_num = 2;
break;
default:
add_dsp_flow_rules(dev->ndp);
dev->cur_dsp_flow_num = 1;
break;
}
#endif

struct syntiant_ndp120_config_tank_s tank_config;
Expand Down Expand Up @@ -1444,7 +1517,7 @@ int ndp120_init(struct ndp120_dev_s *dev, bool reinit)
#endif

#ifdef CONFIG_NDP120_ALIVE_CHECK
if (!reinit) {
if (dsp_fw_num == 0) {
pid_t pid = kernel_thread("NDP_health_check", 100, 4096, ndp120_app_device_health_check, NULL);
if (pid < 0) {
auddbg("Device health check thread creation failed\n");
Expand Down Expand Up @@ -1835,7 +1908,7 @@ int ndp120_change_kd(struct ndp120_dev_s *dev)

dev->lower->reset();

s = ndp120_init(dev, true);
s = ndp120_init(dev, dev->cur_dsp_flow_num);

if (s) {
/* For now do nothing, there may be some cases where init might
Expand Down Expand Up @@ -2015,3 +2088,32 @@ void ndp120_aec_disable(struct ndp120_dev_s *dev)
dev->extclk_inuse = false;
}
#endif

void ndp120_change_dsp_flow(struct ndp120_dev_s *dev, uint8_t dsp_flow_num)
{
#if BT_MIC_SUPPORT == 1
auddbg("To change dsp flow is not spported when BT_MIC_SUPPORT.\n");
return;
#endif

int s;
ndp120_semtake(dev);
dev->lower->irq_enable(false);

s = syntiant_ndp_uninit(dev->ndp, false, SYNTIANT_NDP_INIT_MODE_RESET);
audvdbg("uninit : %d\n", s);

dev->lower->reset();

s = ndp120_init(dev, dsp_flow_num);
if (s) {
/* For now do nothing, there may be some cases where init might
* have failed due to no memory, so retry after some time */
auddbg("reinit failed!\n");
} else {
/* re enable interrupts */
dev->lower->irq_enable(true);
}

ndp120_semgive(dev);
}
7 changes: 6 additions & 1 deletion os/drivers/audio/ndp120_voice.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,11 @@ static int ndp120_ioctl(FAR struct audio_lowerhalf_s *dev, int cmd, unsigned lon
ndp120_change_kd(priv);
break;
}
case AUDIOIOC_CHANGEDSPFLOW: {
uint8_t dsp_flow_num = (uint8_t)arg;
ndp120_change_dsp_flow(priv, dsp_flow_num);
break;
}
default:
audvdbg("ndp120_ioctl received unkown cmd 0x%x\n", cmd);
ret = -EINVAL;
Expand Down Expand Up @@ -906,7 +911,7 @@ FAR struct audio_lowerhalf_s *ndp120_lowerhalf_initialize(FAR struct spi_dev_s *
int retry = NDP120_INIT_RETRY_COUNT;
while (retry--) {
lower->reset();
ret = ndp120_init(priv, false);
ret = ndp120_init(priv, 0);
if (ret != OK) {
auddbg("ndp120 init failed\n");
} else {
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 @@ -84,6 +84,7 @@ struct ndp120_dev_s {
bool keyword_correction;
struct pm_domain_s *pm_domain;
uint32_t sample_ready_cnt;
uint8_t cur_dsp_flow_num;

/* moved to using pthread cond variable for parity with reference implementation in ilib examples */
pthread_mutex_t ndp_mutex_mbsync;
Expand Down
1 change: 1 addition & 0 deletions os/include/tinyara/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
#define AUDIOIOC_GETKDDATA _AUDIOIOC(26)
#define AUDIOIOC_ENABLEDMIC _AUDIOIOC(27)
#define AUDIOIOC_CHANGEKD _AUDIOIOC(28)
#define AUDIOIOC_CHANGEDSPFLOW _AUDIOIOC(29)

/* Audio Device Types *******************************************************/
/* The audio interface support different types of audio devices for
Expand Down