From 21e1d883e101b56c2383cedbdd240b7bc4805b4b Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 4 Mar 2019 15:18:04 +0900 Subject: [PATCH] Provide additional time information when feeding audio data Change-Id: I3ef109cd59bc8525a2da5ccce3691faf21d25a3c --- plugins/wakeup-manager/inc/wakeup_manager.h | 2 +- plugins/wakeup-manager/src/wakeup_manager.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index 22619cc..6fce65d 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -162,7 +162,7 @@ typedef int (*wakeup_engine_set_audio_format)(int rate, int channel, int audio_t #define MA_WAKEUP_ENGINE_FUNC_GET_AUDIO_FORMAT "wakeup_engine_get_audio_format" typedef int (*wakeup_engine_get_audio_format)(int* rate, int* channel, int* audio_type); #define MA_WAKEUP_ENGINE_FUNC_FEED_AUDIO_DATA "wakeup_engine_feed_audio_data" -typedef int (*wakeup_engine_feed_audio_data)(void* data, int len); +typedef int (*wakeup_engine_feed_audio_data)(long time, void* data, int len); #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA_COUNT "wakeup_engine_get_utterance_data_count" typedef int (*wakeup_engine_get_utterance_data_count)(void); #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA "wakeup_engine_get_utterance_data" diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index 620379c..2d234c8 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -152,9 +152,21 @@ static void recorder_thread_func() static int buffer_count = 0; while (!(g_recorder_thread_should_stop.load())) { - char buffer[BUFFER_LENGTH + 10]; + unsigned char buffer[BUFFER_LENGTH]; int ret; - memset(buffer, '\0', BUFFER_LENGTH + 10); + memset(buffer, '\0', BUFFER_LENGTH); + + auto now = std::chrono::system_clock::now(); + auto now_ms = std::chrono::time_point_cast(now); + /* number of milliseconds since the epoch of system_clock */ + auto value = now_ms.time_since_epoch(); + + static long time = 0; + if (time == value.count()) { + LOGE("[Recorder WARNING] Time value duplicated : %lu", time); + } + time = value.count(); + int read_bytes = audio_in_read(g_audio_h, buffer, BUFFER_LENGTH); if (0 > read_bytes) { LOGE("[Recorder WARNING] Fail to read audio : %d", read_bytes); @@ -165,7 +177,7 @@ static void recorder_thread_func() for (int loop = 0;loop < g_engine_count;loop++) { if (g_wakeup_engine_info[loop].audio_data_require_status && g_wakeup_engine_info[loop].interface.feed_audio_data) { - ret = g_wakeup_engine_info[loop].interface.feed_audio_data(buffer, read_bytes); + ret = g_wakeup_engine_info[loop].interface.feed_audio_data(time, buffer, read_bytes); if (0 == ret) { LOGE("[ERROR] Fail to feed speech data, ret(%d)", ret); } -- 2.34.1