📄 aud_vr_sd.c
字号:
vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_PROCESS;
}
else
{
result = MED_RES_FAIL;
aud_vr_sd_abort();
}
}
else
{
result = MED_RES_FAIL;
}
return result;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_trn_voice_in
* DESCRIPTION
* vr sd voice in notification in a training session
* PARAMETERS
* seq_no [IN]
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_trn_voice_in(kal_uint8 seq_no)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 result, i, j;
kal_uint16 *word_id_list_p;
kal_uint16 word_id_list[VR_SD_MAX_GROUP_TAG_NUM];
kal_uint16 word_id_length;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
AUD_FUNC_ENTRY(AUD_VR_SD_TRN_VOICE_IN_REQ_HDLR);
AUD_VALUE_TRACE(vr_ctx.state, vr_sd_ctx.stage, seq_no);
if (vr_sd_ctx.stage == AUD_VR_SD_SESSION_STAGE_READY && seq_no == 0)
{
/* copy word id list except the training word id */
word_id_list_p = vr_sd_ctx.id_array[vr_ctx.group_id];
word_id_length = vr_sd_ctx.id_length[vr_ctx.group_id];
for (j = 0, i = word_id_length - 1; i >= 0; i--)
{
if (word_id_list_p[i] == vr_ctx.word_id)
{
word_id_length--;
}
else
{
word_id_list[j++] = word_id_list_p[i];
}
}
/* 1st training sample */
if (VR_TRA_Start(vr_ctx.word_id, word_id_list, &word_id_length, aud_vr_sd_trn_callback) == VR_OK)
{
result = MED_RES_OK;
vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_PROCESS;
}
else
{
result = MED_RES_FAIL;
aud_vr_sd_abort();
}
}
else if (vr_sd_ctx.stage == AUD_VR_SD_SESSION_STAGE_WAIT && seq_no == 1)
{
/* 2nd training sample */
if (VR_TRA2Start() == VR_OK)
{
result = MED_RES_OK;
vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_PROCESS_2ND;
}
else
{
result = MED_RES_FAIL;
aud_vr_sd_abort();
}
}
else
{
result = MED_RES_FAIL;
}
return result;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_sync_db
* DESCRIPTION
* vr sd sync database
* PARAMETERS
* group_id [IN]
* id_length_p [?]
* id_array [?]
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_sync_db(kal_uint16 group_id, kal_uint16 *id_length_p, kal_uint16 *id_array)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_bool found;
kal_int32 i, j, id_length;
kal_uint16 *target_list = vr_sd_ctx.id_array[group_id];
kal_uint16 *target_length_p = &(vr_sd_ctx.id_length[group_id]);
kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* eliminate tags which found in source list, but not in target list or its file doesn't exist */
for (i = id_length = 0; i < *id_length_p; i++)
{
if (aud_vr_sd_find_word_id(group_id, id_array[i]) >= 0)
{
id_array[id_length++] = id_array[i];
}
}
*id_length_p = id_length;
if (id_length != *target_length_p)
{
/* delete tag files whose id not in target list */
for (i = 0; i < *target_length_p; i++)
{
found = KAL_FALSE;
for (j = 0; j < id_length; j++)
{
if (id_array[j] == target_list[i])
{
found = KAL_TRUE;
break;
}
}
if (!found)
{
/* delete tag file */
kal_wsprintf(
filename,
"%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd",
(kal_uint8) vr_ctx.db_drive,
group_id,
target_list[i]);
FS_Delete(filename);
}
}
/* copy id_array to target list and update target id length */
*target_length_p = id_length;
if (id_length > 0)
{
memcpy(target_list, id_array, id_length << 1);
}
}
return MED_RES_OK;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_delete_tag
* DESCRIPTION
* vr sd delete tag
* PARAMETERS
* group_id [IN]
* word_id [IN]
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_delete_tag(kal_uint16 group_id, kal_uint16 word_id)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_bool done;
kal_uint16 *id_length_p = &vr_sd_ctx.id_length[group_id];
kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
kal_uint16 id_list[VR_SD_MAX_GROUP_TAG_NUM];
kal_uint16 i, count;
kal_int32 result = MED_RES_FAIL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (word_id == 0xFFFF) /* delete all */
{
if (*id_length_p > 0)
{
/* bcoz we need to delete tags in id array, we'd better copy id array to another array and loop throgh it */
count = *id_length_p;
memcpy(id_list, id_array, count << 1);
done = KAL_TRUE;
for (i = 0; i < count; i++)
{
if (!aud_vr_sd_delete_one_tag(group_id, id_list[i]))
{
done = KAL_FALSE;
}
}
if (done)
{
result = MED_RES_OK;
}
}
else
{
result = MED_RES_OK;
}
}
else /* delete one */
{
if (aud_vr_sd_delete_one_tag(group_id, word_id))
{
result = MED_RES_OK;
}
}
return result;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_add_tag
* DESCRIPTION
* vr sd add tags
* PARAMETERS
* group_id [IN]
* cid_array [?]
* cid_length [IN]
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_add_tag(kal_uint16 group_id, kal_uint16 *cid_array, kal_uint16 cid_length)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
FS_HANDLE file_handle;
kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];
kal_uint16 *id_length_p = &vr_sd_ctx.id_length[group_id];
kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
kal_uint16 i, j;
kal_int32 result = MED_RES_OK;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* loop through src id array */
for (i = 0; i < cid_length; i++)
{
/* try to find the corresponding index in target id array */
for (j = 0; j < *id_length_p; j++)
{
if (id_array[j] == cid_array[i])
{
result = MED_RES_ID_EXIST;
break;
}
}
if (j == *id_length_p) /* not found */
{
/* check does the tag file exist */
kal_wsprintf(
filename,
"%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd",
(kal_uint8) vr_ctx.db_drive,
group_id,
cid_array[i]);
if ((file_handle = FS_Open(filename, FS_READ_ONLY)) >= 0)
{
FS_Close(file_handle);
id_array[(*id_length_p)++] = cid_array[i];
}
else
{
result = MED_RES_ID_MISMATCH;
}
}
}
return result;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_play_tag
* DESCRIPTION
* vr sd play a tag
* PARAMETERS
* void
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_play_tag(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 result;
kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (aud_context_p->speech_on)
{
result = MED_RES_BUSY;
}
else
{
aud_context_p->src_mod = vr_ctx.src_mod;
aud_context_p->src_id = 0;
aud_context_p->play_mode = AUD_MEDIA_PLAY_AS_SONG;
aud_context_p->play_style = DEVICE_AUDIO_PLAY_ONCE;
/* if keytone is playing, stop it */
aud_keytone_stop();
/* if tone is playing, stop it */
if (aud_context_p->tone_playing)
{
aud_tone_stop();
}
#ifdef __MED_MMA_MOD__
/* close all mma tasks */
aud_mma_close_all();
#endif /* __MED_MMA_MOD__ */
if (aud_context_p->state != AUD_MEDIA_RECORD && aud_context_p->state != AUD_MEDIA_RECORD_PAUSED &&
aud_context_p->state != AUD_VM_RECORD && aud_context_p->state != AUD_VM_RECORD_PAUSED)
{
aud_stop_unfinished_process();
/* set volume and path */
aud_context_p->melody_output_device = AUDIO_DEVICE_SPEAKER_BOTH;
aud_context_p->current_format = MED_TYPE_VR;
kal_wsprintf(
filename,
"%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd",
(kal_uint8) vr_ctx.db_drive,
vr_ctx.group_id,
vr_ctx.word_id);
aud_context_p->source_type = AUD_FILE;
aud_context_p->play_style = DEVICE_AUDIO_PLAY_ONCE;
result = aud_media_play_file_stream(filename, DEVICE_AUDIO_PLAY_ONCE, 1, KAL_FALSE, NULL);
}
else
{
result = MED_RES_BUSY;
}
}
return result;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_abort
* DESCRIPTION
* vr sd abort a session
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void aud_vr_sd_abort(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
VR_Stop();
vr_ctx.state = AUD_VR_STATE_IDLE;
vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_NOT_READY;
if (vr_sd_ctx.buffer != NULL)
{
med_free_ext_mem((void **)&vr_sd_ctx.buffer);
}
}
#endif /* __MED_VR_MOD__ */
#endif /* MED_NOT_PRESENT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -