From d67a3fb1dcb9b6b592ac40a7ca3c6839557a9971 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 8 Sep 2016 07:54:29 +0900 Subject: [PATCH] Fix code formatting Change-Id: I66e992d8d2ac563bbae5dd1f1f343877c9989aa9 Signed-off-by: Jihoon Kim --- po/en_US.po | 5 +- src/MicEffector.cpp | 539 +++++++++++++++++++-------------------- src/SttFeedback.cpp | 21 +- src/SttManager.cpp | 24 +- src/WInputSttMicEffect.cpp | 161 ++++++------ src/include/SttManager.h | 1 - src/include/WInputSttMicEffect.h | 35 ++- src/ise-stt-mode.cpp | 91 ++++--- src/ise-stt-option.cpp | 6 +- 9 files changed, 420 insertions(+), 463 deletions(-) diff --git a/po/en_US.po b/po/en_US.po index 5a235e5..444c422 100755 --- a/po/en_US.po +++ b/po/en_US.po @@ -106,9 +106,6 @@ msgstr "Language" msgid "IDS_VC_BODY_AUTOMATIC" msgstr "Automatic" - - - msgid "IDS_ACCS_BODY_DISABLED_TTS" msgstr "Turned off." @@ -167,4 +164,4 @@ msgid "IDS_VTR_BODY_RECOGNITION_SERVICE_BUSY" msgstr "Recognition service busy." msgid "IDS_VOICE_NPBODY_TAP_TO_PAUSE_ABB" -msgstr "Tap to pause" \ No newline at end of file +msgstr "Tap to pause" diff --git a/src/MicEffector.cpp b/src/MicEffector.cpp index f2602d1..f939b9a 100644 --- a/src/MicEffector.cpp +++ b/src/MicEffector.cpp @@ -33,28 +33,27 @@ static float timeout_s = 1.0f / 60.0f; double cubic_easy_in_out(double index, double start, double end, double duration) { - index /= duration/2; - if (index < 1) - return end/2*index*index*index + start; + index /= duration/2; + if (index < 1) + return end/2*index*index*index + start; - index -= 2; - return end/2*(index*index*index + 2) + start; + index -= 2; + return end/2*(index*index*index + 2) + start; } double cubic_easy_in(double index, double start, double end, double duration) { - index /= duration; - return end*index*index*index*index*index + start; + index /= duration; + return end*index*index*index*index*index + start; } double cubic_easy_out(double index, double start, double end, double duration) { - index /= duration; - index--; - return end*(index*index*index + 1) + start; + index /= duration; + index--; + return end*(index*index*index + 1) + start; } - /** * Constructor * @@ -63,31 +62,28 @@ double cubic_easy_out(double index, double start, double end, double duration) * #2. Drawing empty frame to avoid broken screen. * */ - MicEffector::MicEffector(Evas_Object *canvas, Evas_Object *layout, IMicEffector& effect) - : drawcount(0) - , forcestop(false) - , started(false) - , fake(false) - , timer(NULL) - , layout(layout) - , ieffect(effect) + : drawcount(0) + , forcestop(false) + , started(false) + , fake(false) + , timer(NULL) + , layout(layout) + , ieffect(effect) { -// path = ea_vector_path_create(); -// paint = ea_vector_paint_create(); -// ea_vector_paint_set_style(paint, EA_VECTOR_PAINT_STYLE_STROKE); -// ea_vector_paint_set_line_cap(paint, EA_VECTOR_PAINT_LINE_CAP_ROUND); -// ea_vector_paint_set_line_join(paint, EA_VECTOR_PAINT_LINE_JOIN_ROUND); -// ea_vector_paint_set_line_width(paint, 3.0); -// ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, 1.0f); +// path = ea_vector_path_create(); +// paint = ea_vector_paint_create(); +// ea_vector_paint_set_style(paint, EA_VECTOR_PAINT_STYLE_STROKE); +// ea_vector_paint_set_line_cap(paint, EA_VECTOR_PAINT_LINE_CAP_ROUND); +// ea_vector_paint_set_line_join(paint, EA_VECTOR_PAINT_LINE_JOIN_ROUND); +// ea_vector_paint_set_line_width(paint, 3.0); +// ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, 1.0f); -// this->canvas = ea_vector_canvas_create(canvas); +// this->canvas = ea_vector_canvas_create(canvas); - DrawDummyFrame(); + DrawDummyFrame(); }; - - /** * Destructor * @@ -96,33 +92,29 @@ MicEffector::MicEffector(Evas_Object *canvas, Evas_Object *layout, IMicEffector& */ MicEffector::~MicEffector() { - if(timer) - { - ecore_timer_del(timer); - timer = NULL; - } - -// ea_vector_path_destroy(path); -// ea_vector_paint_destroy(paint); -// ea_vector_canvas_destroy(canvas); + if(timer) + { + ecore_timer_del(timer); + timer = NULL; + } + +// ea_vector_path_destroy(path); +// ea_vector_paint_destroy(paint); +// ea_vector_canvas_destroy(canvas); } - - /** * Draw empty frame to remove or initiate screen * */ void MicEffector::DrawDummyFrame() { -// ea_vector_path_reset(path); -// ea_vector_path_move_to(path, 0, 0); -// ea_vector_path_line_to(path, 0, 0); -// ea_vector_canvas_draw(canvas, path, paint); +// ea_vector_path_reset(path); +// ea_vector_path_move_to(path, 0, 0); +// ea_vector_path_line_to(path, 0, 0); +// ea_vector_canvas_draw(canvas, path, paint); } - - /** * Draw Que animation * @@ -134,83 +126,81 @@ void MicEffector::DrawDummyFrame() */ void MicEffector::DrawQue(int idx, bool is_start) { -// float margin = spectrum_posx; -// float posx = 0.0; +// float margin = spectrum_posx; +// float posx = 0.0; - double speed = cubic_easy_out(idx + 1.0, 0.0, 23.0, 23); + double speed = cubic_easy_out(idx + 1.0, 0.0, 23.0, 23); - unsigned int start = start_stop_anim_count - (int) speed; - unsigned int end = start_stop_anim_count + (int) speed; + unsigned int start = start_stop_anim_count - (int) speed; + unsigned int end = start_stop_anim_count + (int) speed; -// double opacity; +// double opacity; - if (is_start) { -// opacity = cubic_easy_out(idx, 0.0, 1.0, 26.0); - } else { -// opacity = cubic_easy_out(idx, 0, 1.0, 26.0); - } + if (is_start) { +// opacity = cubic_easy_out(idx, 0.0, 1.0, 26.0); + } else { +// opacity = cubic_easy_out(idx, 0, 1.0, 26.0); + } -// ea_vector_path_reset(path); +// ea_vector_path_reset(path); - for(unsigned int i = start; i < end; i++) - { -// posx = margin + (i * 5); + for(unsigned int i = start; i < end; i++) + { +// posx = margin + (i * 5); -// ea_vector_path_move_to(path, posx, 37.0f); -// ea_vector_path_line_to(path, posx, 38.0f); +// ea_vector_path_move_to(path, posx, 37.0f); +// ea_vector_path_line_to(path, posx, 38.0f); -// ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity); - } +// ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity); + } -// ea_vector_canvas_draw(canvas, path, paint); +// ea_vector_canvas_draw(canvas, path, paint); } - - float MicEffector::GetAmplifyValue(unsigned int idx) { - float amplify = 0.0; + float amplify = 0.0; - int max[SAMPLE_COUNT] = { - /** - * dot "A" (9) - * - */ - 1, 1, 1, 1, + int max[SAMPLE_COUNT] = { + /** + * dot "A" (9) + * + */ + 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, - /** - * dot "B" (9) - * - */ - 10, 8, 2, 3, 10, 11, 6, 12, 4, + /** + * dot "B" (9) + * + */ + 10, 8, 2, 3, 10, 11, 6, 12, 4, - /** - * dot "C" (15) - * - */ - 3, 5, 9, 12, 11, 8, 14, 15, 13, 11, 12, 6, 8, 3, 2, + /** + * dot "C" (15) + * + */ + 3, 5, 9, 12, 11, 8, 14, 15, 13, 11, 12, 6, 8, 3, 2, - /** - * reverse dot "B" (9) - * - */ - 4, 12, 6, 11, 10, 3, 2, 8, 10, + /** + * reverse dot "B" (9) + * + */ + 4, 12, 6, 11, 10, 3, 2, 8, 10, - /** - * dot "A" (9) - * - */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, + /** + * dot "A" (9) + * + */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1 - }; + 1, 1, 1, 1 + }; - amplify = (float) max[idx] / 10.0f * 1.9f; + amplify = (float) max[idx] / 10.0f * 1.9f; - return amplify; + return amplify; } /** @@ -222,84 +212,82 @@ float MicEffector::GetAmplifyValue(unsigned int idx) */ void MicEffector::DrawWave(unsigned int idx, int amount, int prev_amount, double opacity, bool is_lastcmd) { -// float ratio = GetAmplifyValue(idx); +// float ratio = GetAmplifyValue(idx); -// float am = ((float) amount) * ratio; -// float pam = ((float) prev_amount) * ratio; -// float cnt = (float) drawcount; +// float am = ((float) amount) * ratio; +// float pam = ((float) prev_amount) * ratio; +// float cnt = (float) drawcount; - float posx = spectrum_posx; + float posx = spectrum_posx; -// float height = pam > am? -// pam - cubic_easy_in_out(cnt + 1.0, am, pam, 7): -// cubic_easy_in_out(cnt + 1.0, pam, am, 7); +// float height = pam > am? +// pam - cubic_easy_in_out(cnt + 1.0, am, pam, 7): +// cubic_easy_in_out(cnt + 1.0, pam, am, 7); - posx += idx * 5; + posx += idx * 5; -// ea_vector_path_move_to(path, posx, (37.0f - (height / 2.0))); -// ea_vector_path_line_to(path, posx, (38.0f + (height / 2.0))); +// ea_vector_path_move_to(path, posx, (37.0f - (height / 2.0))); +// ea_vector_path_line_to(path, posx, (38.0f + (height / 2.0))); - if (is_lastcmd) { -// ea_vector_paint_set_color(paint, 0.1451f, 0.204f, 0.255f, opacity);//RGB = 37:52:65 - } else { -// ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);//RGB: 255 255 255 - } + if (is_lastcmd) { +// ea_vector_paint_set_color(paint, 0.1451f, 0.204f, 0.255f, opacity);//RGB = 37:52:65 + } else { +// ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);//RGB: 255 255 255 + } } - - /** * Effect Start * */ void MicEffector::Start() { - if(timer) { - ecore_timer_del(timer); - timer = NULL; - } - - drawcount = 0; - - prev.clear(); - current.clear(); - - for(size_t i = 0; i < spectrum_count; i++) - { - prev.push_back(0); - current.push_back(0); - } - - Listening(); - - /** - * Que animation - * - */ - timer = ecore_timer_add(timeout_s, - [](void *data)->Eina_Bool - { - MicEffector *effector = static_cast(data); - - effector->DrawQue(effector->drawcount); - - if(effector->drawcount < (int) start_stop_anim_count) { - effector->drawcount += 2; - return ECORE_CALLBACK_RENEW; - } else { - for(unsigned int i = 0; i < spectrum_count; i++) - effector->DrawWave(i, 0, 0); - -// ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint); - - effector->drawcount = 0; - effector->timer = NULL; - effector->VolumeCheck(); - effector->Effect(); - return ECORE_CALLBACK_CANCEL; - } - }, - this); + if(timer) { + ecore_timer_del(timer); + timer = NULL; + } + + drawcount = 0; + + prev.clear(); + current.clear(); + + for(size_t i = 0; i < spectrum_count; i++) + { + prev.push_back(0); + current.push_back(0); + } + + Listening(); + + /** + * Que animation + * + */ + timer = ecore_timer_add(timeout_s, + [](void *data)->Eina_Bool + { + MicEffector *effector = static_cast(data); + + effector->DrawQue(effector->drawcount); + + if(effector->drawcount < (int) start_stop_anim_count) { + effector->drawcount += 2; + return ECORE_CALLBACK_RENEW; + } else { + for(unsigned int i = 0; i < spectrum_count; i++) + effector->DrawWave(i, 0, 0); + +// ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint); + + effector->drawcount = 0; + effector->timer = NULL; + effector->VolumeCheck(); + effector->Effect(); + return ECORE_CALLBACK_CANCEL; + } + }, + this); } /** @@ -308,90 +296,88 @@ void MicEffector::Start() */ void MicEffector::Effect(bool fake) { - /** - * Volume effect animation - * - */ - if ( timer ) { - ecore_timer_del(timer); - timer = NULL; - } - - timer = ecore_timer_add(timeout_s, - [](void *data)->Eina_Bool - { - MicEffector *effector = static_cast(data); - - bool is_empty_prev = effector->prev.empty(); - - -// ea_vector_path_reset(effector->path); - - for(unsigned int i = 0; i < effector->current.size(); i++) - { - if (is_empty_prev) - effector->DrawWave(i, effector->current.at(i), 0); - else - effector->DrawWave(i, effector->current.at(i), effector->prev.at(i)); - } -// ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint); - - if (effector->drawcount < 7) { - effector->drawcount++; - } else { - effector->drawcount = 0; - effector->VolumeCheck(effector->fake); - } - - return ECORE_CALLBACK_RENEW; - }, this); + /** + * Volume effect animation + * + */ + if ( timer ) { + ecore_timer_del(timer); + timer = NULL; + } + + timer = ecore_timer_add(timeout_s, + [](void *data)->Eina_Bool + { + MicEffector *effector = static_cast(data); + + bool is_empty_prev = effector->prev.empty(); + + +// ea_vector_path_reset(effector->path); + + for(unsigned int i = 0; i < effector->current.size(); i++) + { + if (is_empty_prev) + effector->DrawWave(i, effector->current.at(i), 0); + else + effector->DrawWave(i, effector->current.at(i), effector->prev.at(i)); + } +// ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint); + + if (effector->drawcount < 7) { + effector->drawcount++; + } else { + effector->drawcount = 0; + effector->VolumeCheck(effector->fake); + } + + return ECORE_CALLBACK_RENEW; + }, this); } - - /** * Stop volume animation effect * */ void MicEffector::Stop(bool forced) { - if(timer) - { - ecore_timer_del(timer); - timer = NULL; - } - - if(!started) - { - Idle(); - return; - } - - forcestop = forced; - - timer = ecore_timer_add(timeout_s, - [](void *data)->Eina_Bool - { - MicEffector *effector = static_cast(data); - - effector->DrawQue(start_stop_anim_count - effector->drawcount, false); - - if(effector->drawcount < (int) start_stop_anim_count) { - effector->drawcount += 2; - return ECORE_CALLBACK_RENEW; - } else { - if(!effector->forcestop) { - effector->Processing(); - } else { - effector->Idle(); - } - - effector->forcestop = false; - effector->drawcount = 0; - effector->timer = NULL; - return ECORE_CALLBACK_CANCEL; - } - }, this); + if(timer) + { + ecore_timer_del(timer); + timer = NULL; + } + + if(!started) + { + Idle(); + return; + } + + forcestop = forced; + + timer = ecore_timer_add(timeout_s, + [](void *data)->Eina_Bool + { + MicEffector *effector = static_cast(data); + + effector->DrawQue(start_stop_anim_count - effector->drawcount, false); + + if(effector->drawcount < (int) start_stop_anim_count) { + effector->drawcount += 2; + return ECORE_CALLBACK_RENEW; + } else { + if(!effector->forcestop) { + effector->Processing(); + } else { + effector->Idle(); + } + + effector->forcestop = false; + effector->drawcount = 0; + effector->timer = NULL; + return ECORE_CALLBACK_CANCEL; + } + }, this); } /** @@ -400,79 +386,72 @@ void MicEffector::Stop(bool forced) */ void MicEffector::VolumeCheck(bool fake) { - std::vector volumes; + std::vector volumes; - this->fake = fake; + this->fake = fake; - if(!fake) { - volumes = ieffect.GetVolume(); - } else { - for(unsigned int i = 0; i < spectrum_count; i++) { - volumes.push_back(rand_r((unsigned int*)time(NULL)) % 2); - } - } + if(!fake) { + volumes = ieffect.GetVolume(); + } else { + for(unsigned int i = 0; i < spectrum_count; i++) { + volumes.push_back(rand_r((unsigned int*)time(NULL)) % 2); + } + } - prev.clear(); - prev.assign(current.begin(), current.end()); + prev.clear(); + prev.assign(current.begin(), current.end()); - current.clear(); - current.assign(volumes.begin(), volumes.end()); + current.clear(); + current.assign(volumes.begin(), volumes.end()); } - - /** * Signal. Listening effect * */ void MicEffector::Listening() { - started = true; + started = true; - elm_object_signal_emit(layout, "elm,state,eq,show", "eq"); - elm_object_signal_emit(layout, "elm,state,listening", "elm"); + elm_object_signal_emit(layout, "elm,state,eq,show", "eq"); + elm_object_signal_emit(layout, "elm,state,listening", "elm"); } - - /** * Signal. Processing effect * */ void MicEffector::Processing() { - started = false; + started = false; - elm_object_signal_emit(layout, "elm,state,eq,hide", "eq"); - elm_object_signal_emit(layout, "elm,state,processing", "elm"); + elm_object_signal_emit(layout, "elm,state,eq,hide", "eq"); + elm_object_signal_emit(layout, "elm,state,processing", "elm"); - ieffect.ProcessingAnimationStart(); + ieffect.ProcessingAnimationStart(); } - - /** * Signal. Idle effect * */ void MicEffector::Idle() { - const char *text; - const char *state; - double val; + const char *text; + const char *state; + double val; - started = false; + started = false; - elm_object_signal_emit(layout, "elm,state,eq,hide", "eq"); + elm_object_signal_emit(layout, "elm,state,eq,hide", "eq"); - text = elm_object_part_text_get(layout, "elm.text"); - state = edje_object_part_state_get(elm_layout_edje_get(layout), "guide_text_block", &val); + text = elm_object_part_text_get(layout, "elm.text"); + state = edje_object_part_state_get(elm_layout_edje_get(layout), "guide_text_block", &val); - if ((text && strlen(text) > 0) && (state && !strcmp(state, "bottom"))) - elm_object_signal_emit(layout, "elm,state,init_message", "elm"); - else - elm_object_signal_emit(layout, "elm,state,init", "elm"); + if ((text && strlen(text) > 0) && (state && !strcmp(state, "bottom"))) + elm_object_signal_emit(layout, "elm,state,init_message", "elm"); + else + elm_object_signal_emit(layout, "elm,state,init", "elm"); - ieffect.ProcessingAnimationStop(); + ieffect.ProcessingAnimationStop(); } - diff --git a/src/SttFeedback.cpp b/src/SttFeedback.cpp index ec73e87..b82333d 100644 --- a/src/SttFeedback.cpp +++ b/src/SttFeedback.cpp @@ -47,15 +47,15 @@ void SttFeedback::OnResult( // Partial result case : STT_RECOGNITION_TYPE_FREE_PARTIAL // Normal result case : STT_RECOGNITION_TYPE_FREE - if(results.size() < 1) { + if (results.size() < 1) { LOGD("Result size : %d", results.size()); vd.state = STT_STATE_VAL_NOT_RECOGNISED; set_animation_state(&vd); } else { - for(std::vector::iterator result = results.begin(); result != results.end(); std::advance(result, 1)) { - if(!result->empty() && result->length() > 0) { + for (std::vector::iterator result = results.begin(); result != results.end(); std::advance(result, 1)) { + if (!result->empty() && result->length() > 0) { LOGD("%s\n", result->c_str()); - switch(event){ + switch (event){ case STT_RESULT_EVENT_FINAL_RESULT: LOGD("STT_RESULT_EVENT_FINAL_RESULT"); vd.state = STT_STATE_VAL_INIT; @@ -125,14 +125,14 @@ void SttFeedback::SttIdle(void) void SttFeedback::SttRecording(void) { - if(!owner) { + if (!owner) { LOGD("no owner"); return; } VoiceData& vd = *((VoiceData *) owner); - if(vd.partial_result){ + if (vd.partial_result){ free(vd.partial_result); vd.partial_result = NULL; } @@ -145,7 +145,7 @@ void SttFeedback::SttRecording(void) void SttFeedback::SttProcessing(void) { - if(!owner) { + if (!owner) { LOGD("no owner"); return; } @@ -158,11 +158,9 @@ void SttFeedback::SttProcessing(void) set_animation_state(&vd); } - - void SttFeedback::OnError(stt_error_e reason) { - if(!owner) { + if (!owner) { LOGD("no owner"); return; } @@ -175,9 +173,8 @@ void SttFeedback::OnError(stt_error_e reason) show_error_message(&vd, reason); } - void SttFeedback::SetVoiceData(void *data) { - if(!data) { + if (!data) { LOGD("no data"); return; } diff --git a/src/SttManager.cpp b/src/SttManager.cpp index cc19d8a..aed5354 100644 --- a/src/SttManager.cpp +++ b/src/SttManager.cpp @@ -33,16 +33,12 @@ static inline const char *stt_state_str(stt_state_e cur) { if (cur == STT_STATE_CREATED) return (const char *) "STT_STATE_CREATED"; - else if (cur == STT_STATE_READY) return (const char *) "STT_STATE_READY"; - else if (cur == STT_STATE_RECORDING) return (const char *) "STT_STATE_RECORDING"; - else if (cur == STT_STATE_PROCESSING) return (const char *) "STT_STATE_PROCESSING"; - else return (const char *) "ABNORMAL CASE"; } @@ -58,7 +54,7 @@ SttManager::SttManager(ISttFeedback& feedback) */ int ret = stt_create(&handle); - if(ret != STT_ERROR_NONE) + if (ret != STT_ERROR_NONE) throw SttException(ret, ErrorString((stt_error_e)ret)); /** @@ -93,7 +89,7 @@ void SttManager::Prepare() { */ int ret = stt_prepare(handle); - if(ret != STT_ERROR_NONE) + if (ret != STT_ERROR_NONE) throw SttException(ret, ErrorString((stt_error_e)ret)); } @@ -109,7 +105,7 @@ void SttManager::UnPrepare() { } void SttManager::Start() { - if(!Validate((int) READY)) { + if (!Validate((int) READY)) { throw SttException((int) STT_ERROR_INVALID_STATE, "INVALID STATE - !STT_STATE_READY"); } @@ -125,12 +121,12 @@ void SttManager::Start() { int ret; ret = stt_start(handle, language.c_str(), asrtype.c_str()); - if(ret != STT_ERROR_NONE) + if (ret != STT_ERROR_NONE) throw SttException(ret, ErrorString((stt_error_e)ret)); } void SttManager::Stop() { - if(!Validate((int) RECORDING)) { + if (!Validate((int) RECORDING)) { throw SttException((int) STT_ERROR_INVALID_STATE, "INVALID STATE - !STT_STATE_RECORDING"); } @@ -140,17 +136,17 @@ void SttManager::Stop() { */ int ret = stt_stop(handle); - if(ret != STT_ERROR_NONE) + if (ret != STT_ERROR_NONE) throw SttException(ret, ErrorString((stt_error_e)ret)); } void SttManager::Cancel() { - if(iscancelled) { + if (iscancelled) { LOGD("iscancelled (%d)", iscancelled); return; } - if(!Validate((int) (RECORDING|PROCESSING))) { + if (!Validate((int) (RECORDING|PROCESSING))) { throw SttException((int) STT_ERROR_INVALID_STATE, "INVALID STATE - !(STT_STATE_RECORDING or STT_STATE_PROCESSING)"); } @@ -160,7 +156,7 @@ void SttManager::Cancel() { */ int ret = stt_cancel(handle); - if(ret != STT_ERROR_NONE) + if (ret != STT_ERROR_NONE) throw SttException(ret, ErrorString((stt_error_e)ret)); iscancelled = true; @@ -185,7 +181,7 @@ bool SttManager::Validate(int state) { cur == STT_STATE_RECORDING ? "STT_STATE_RECORDING" : cur == STT_STATE_PROCESSING ? "STT_STATE_PROCESSING" : "ABNORMAL"); - switch(cur) { + switch (cur) { case STT_STATE_CREATED : if (state & CREATE) return true; break; diff --git a/src/WInputSttMicEffect.cpp b/src/WInputSttMicEffect.cpp index 44a41d9..efb2c42 100644 --- a/src/WInputSttMicEffect.cpp +++ b/src/WInputSttMicEffect.cpp @@ -24,7 +24,7 @@ namespace { template static unsigned long long SumSquare(unsigned long long const& a, T const& b) { - return a + b*b; + return a + b*b; } const double MAX_AMPLITUDE_MEAN_16 = 23170.115738161934; @@ -38,118 +38,113 @@ using namespace is::ui; WInputSttMicEffect::WInputSttMicEffect() - : square_sum(0) - , count(5) - , handle(NULL) - , processing_effect_timer(NULL) - , progressbar(NULL) { + : square_sum(0) + , count(5) + , handle(NULL) + , processing_effect_timer(NULL) + , progressbar(NULL) { } WInputSttMicEffect::~WInputSttMicEffect() { - ProcessingAnimationStop(); + ProcessingAnimationStop(); } std::vector WInputSttMicEffect::GetVolume() { - std::vector result; - - short pcm[512] = {0}; - int size = 0; - int ret = 0; - -// ret = stt_get_spectrum(handle, (void *) pcm, &size); - count = 5; - - if (STT_ERROR_NONE != ret) { - - } else { - unsigned int level = 0; - unsigned int step = (unsigned int) (size/2/sample_count); - - for (unsigned int k = 0; k < sample_count; k++ ){ - square_sum = std::accumulate(pcm + k*step, pcm + k*step + 5, 0ull, SumSquare); - level = ConvertLevel(); - result.push_back(level); - } - } - return result; + std::vector result; + + short pcm[512] = {0}; + int size = 0; + int ret = 0; + +// ret = stt_get_spectrum(handle, (void *) pcm, &size); + count = 5; + + if (STT_ERROR_NONE != ret) { + } else { + unsigned int level = 0; + unsigned int step = (unsigned int) (size/2/sample_count); + + for (unsigned int k = 0; k < sample_count; k++ ){ + square_sum = std::accumulate(pcm + k*step, pcm + k*step + 5, 0ull, SumSquare); + level = ConvertLevel(); + result.push_back(level); + } + } + return result; } float WInputSttMicEffect::GetDecibel() const { - float rms = std::sqrt(square_sum/count); - return 20.0*log10(rms); + float rms = std::sqrt(square_sum/count); + return 20.0*log10(rms); } int WInputSttMicEffect::ConvertLevel() { - float db = GetDecibel(); - - if ( db <= 30.0 ){ - return 0; - } else if ( db <= 33.3 ){ - return 1; - } else if ( db <= 36.6 ){ - return 2; - } else if ( db <= 40 ){ - return 3; - } else if ( db <= 43.3 ){ - return 4; - } else if ( db <= 46.6 ){ - return 5; - } else if ( db <= 50 ){ - return 6; - } else if ( db <= 53.3 ){ - return 7; - } else if ( db <= 56.6 ){ - return 8; - } else if ( db <= 60 ){ - return 9; - } else { - return 10; - } + float db = GetDecibel(); + + if ( db <= 30.0 ){ + return 0; + } else if ( db <= 33.3 ){ + return 1; + } else if ( db <= 36.6 ){ + return 2; + } else if ( db <= 40 ){ + return 3; + } else if ( db <= 43.3 ){ + return 4; + } else if ( db <= 46.6 ){ + return 5; + } else if ( db <= 50 ){ + return 6; + } else if ( db <= 53.3 ){ + return 7; + } else if ( db <= 56.6 ){ + return 8; + } else if ( db <= 60 ){ + return 9; + } else { + return 10; + } } void WInputSttMicEffect::ProcessingAnimationStart() { - elm_progressbar_pulse(progressbar, EINA_TRUE); + elm_progressbar_pulse(progressbar, EINA_TRUE); - processing_effect_timer = ecore_timer_add(0.1, - [](void *data)->Eina_Bool - { - if(!data) return ECORE_CALLBACK_CANCEL; + processing_effect_timer = ecore_timer_add(0.1, + [](void *data)->Eina_Bool + { + if(!data) return ECORE_CALLBACK_CANCEL; /* - WInputSttMicEffect *effect = (WInputSttMicEffect *) data; - Evas_Object *progressbar = effect->progressbar; + WInputSttMicEffect *effect = (WInputSttMicEffect *) data; + Evas_Object *progressbar = effect->progressbar; - double progress = eext_circle_value_get(progressbar); + double progress = eext_circle_value_get(progressbar); - if (progress < 100) - progress += 5.0; - else - progress = 0.0; + if (progress < 100) + progress += 5.0; + else + progress = 0.0; - eext_circle_value_set(progressbar, progress); + eext_circle_value_set(progressbar, progress); */ - return ECORE_CALLBACK_RENEW; - }, this); + return ECORE_CALLBACK_RENEW; + }, this); } void WInputSttMicEffect::ProcessingAnimationStop() { - if(processing_effect_timer) - { - ecore_timer_del(processing_effect_timer); - processing_effect_timer = NULL; - } - elm_progressbar_pulse(progressbar, EINA_FALSE); + if(processing_effect_timer) + { + ecore_timer_del(processing_effect_timer); + processing_effect_timer = NULL; + } + elm_progressbar_pulse(progressbar, EINA_FALSE); } - - void WInputSttMicEffect::SetSttHandle(stt_h handle) { - this->handle = handle; + this->handle = handle; } - - void WInputSttMicEffect::SetProgressBar(Evas_Object *progress) { - this->progressbar = progress; + this->progressbar = progress; } diff --git a/src/include/SttManager.h b/src/include/SttManager.h index 1c31d41..8e89ec7 100644 --- a/src/include/SttManager.h +++ b/src/include/SttManager.h @@ -134,7 +134,6 @@ class SttManager bool Validate(int state); - /** * result cb for tizen stt api. * diff --git a/src/include/WInputSttMicEffect.h b/src/include/WInputSttMicEffect.h index 41331d0..04d37ce 100644 --- a/src/include/WInputSttMicEffect.h +++ b/src/include/WInputSttMicEffect.h @@ -18,7 +18,7 @@ #include extern "C" { - #include + #include } #include @@ -31,34 +31,33 @@ namespace ui { class WInputSttMicEffect : public IMicEffector { - private : - unsigned long long square_sum; - unsigned int count; + private : + unsigned long long square_sum; + unsigned int count; + public : + WInputSttMicEffect(); - public : - WInputSttMicEffect(); + virtual ~WInputSttMicEffect(); - virtual ~WInputSttMicEffect(); + std::vector GetVolume(); - std::vector GetVolume(); + void ProcessingAnimationStart(); - void ProcessingAnimationStart(); + void ProcessingAnimationStop(); - void ProcessingAnimationStop(); + float GetDecibel() const; - float GetDecibel() const; + int ConvertLevel(); - int ConvertLevel(); + void SetSttHandle(stt_h handle); - void SetSttHandle(stt_h handle); + void SetProgressBar(Evas_Object *progress); - void SetProgressBar(Evas_Object *progress); + stt_h handle; - stt_h handle; - - Ecore_Timer *processing_effect_timer; - Evas_Object *progressbar; + Ecore_Timer *processing_effect_timer; + Evas_Object *progressbar; }; }} /** end of is::ui */ diff --git a/src/ise-stt-mode.cpp b/src/ise-stt-mode.cpp index 2c5066e..bf2ed18 100644 --- a/src/ise-stt-mode.cpp +++ b/src/ise-stt-mode.cpp @@ -39,7 +39,7 @@ static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info); void send_result_text(void *data) { - if(!data) + if (!data) return; VoiceData* voicedata = (VoiceData*)data; @@ -50,7 +50,7 @@ void send_result_text(void *data) void voice_get_string(const char *keyValue, VoiceData *voicedata) { - if(!voicedata) + if (!voicedata) return; char* strbuf = NULL; @@ -59,9 +59,9 @@ void voice_get_string(const char *keyValue, VoiceData *voicedata) LOGD("text : %s, voicedata->partial_result=%s", strbuf, voicedata->partial_result); - if(strbuf){ - if(voicedata->partial_result){ // partial_result is not Null so replace - if(strcmp(voicedata->partial_result, strbuf)){ + if (strbuf){ + if (voicedata->partial_result){ // partial_result is not Null so replace + if (strcmp(voicedata->partial_result, strbuf)){ // different replace LOGD("different replace"); @@ -80,16 +80,15 @@ void voice_get_string(const char *keyValue, VoiceData *voicedata) send_result_text(voicedata); - if(strbuf) + if (strbuf) free(strbuf); LOGD("ends"); } - static Eina_Bool _recognition_failure_cb(void *data) { - if(data) { + if (data) { VoiceData *voicedata = (VoiceData *) data; voicedata->state = STT_STATE_VAL_INIT; @@ -101,7 +100,7 @@ static Eina_Bool _recognition_failure_cb(void *data) static Eina_Bool hide_guide_text(void *data) { - if(data) { + if (data) { VoiceData *voicedata = (VoiceData *) data; voicedata->guide_text_timer = NULL; elm_object_part_text_set(voicedata->layout_main, "elm.text", ""); @@ -115,13 +114,13 @@ static void set_guide_text(VoiceData *vd, const char* text, bool translatable) { elm_object_signal_emit(vd->layout_main, "idle,state,guide_text,bottom", "elm"); - if(translatable) + if (translatable) elm_object_domain_translatable_part_text_set(vd->layout_main, "elm.text", PACKAGE, text); else elm_object_part_text_set(vd->layout_main, "elm.text", text); - if(!strcmp(text, SK_SPEAK_NOW)){ - if(vd->guide_text_timer == NULL) + if (!strcmp(text, SK_SPEAK_NOW)){ + if (vd->guide_text_timer == NULL) vd->guide_text_timer = ecore_timer_add(2.0, hide_guide_text, vd); } } @@ -142,7 +141,7 @@ void show_popup_toast(const char *text, bool check_img) elm_image_file_set(img, path_ic.c_str(), NULL); elm_object_part_content_set(popup, "toast,icon", img); } - if(text) { + if (text) { elm_object_part_text_set(popup, "elm.text", text); } @@ -156,7 +155,7 @@ void show_popup_toast(const char *text, bool check_img) static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info) { - if(obj){ + if (obj){ evas_object_hide(obj); evas_object_del(obj); } @@ -164,11 +163,10 @@ static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info) static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info) { - if(obj) + if (obj) elm_popup_dismiss(obj); } - void start_by_press(VoiceData *voicedata) { LOGD("start_by_press "); @@ -185,7 +183,7 @@ static void on_mic_button_press_cb(void *data, Evas_Object *obj, void *event_inf static Eina_Bool _mic_button_enable_cb(void *data) { - if(!data) + if (!data) return ECORE_CALLBACK_CANCEL; VoiceData* voicedata = (VoiceData*)data; @@ -196,7 +194,6 @@ static Eina_Bool _mic_button_enable_cb(void *data) return ECORE_CALLBACK_CANCEL; } - void init_customizing_theme(void) { std::string stt_edj_path = app_get_resource_path(); @@ -210,13 +207,13 @@ bool _app_stt_initialize(VoiceData *voice_data) VoiceData *vd = (VoiceData *)voice_data; try { - if(vd != NULL && vd->sttmanager) { + if (vd != NULL && vd->sttmanager) { vd->sttmanager->Cancel(); delete vd->sttmanager; vd->sttmanager = NULL; } - if(vd != NULL && vd->sttfeedback) { + if (vd != NULL && vd->sttfeedback) { delete vd->sttfeedback; vd->sttfeedback = NULL; } @@ -237,9 +234,9 @@ bool _app_stt_initialize(VoiceData *voice_data) static Eina_Bool _idler_cb(void *data) { LOGD("_idler_cb"); - if(!data) return ECORE_CALLBACK_CANCEL; + if (!data) return ECORE_CALLBACK_CANCEL; - if(my_voicedata == NULL) { + if (my_voicedata == NULL) { LOGD("_idler_cb : my_voicedata is null"); return ECORE_CALLBACK_CANCEL; } @@ -291,7 +288,7 @@ void set_animation_state(VoiceData *voicedata) } #endif - if(voicedata->effector) + if (voicedata->effector) voicedata->effector->Stop(true); set_guide_text(voicedata, ""); @@ -299,12 +296,12 @@ void set_animation_state(VoiceData *voicedata) } else if (voicedata->state == STT_STATE_VAL_LISTENING) { set_guide_text(voicedata, SK_SPEAK_NOW, true); - if(voicedata->effector) + if (voicedata->effector) voicedata->effector->Start(); } else if (voicedata->state == STT_STATE_VAL_PROCESSING) { set_guide_text(voicedata, ""); - if(voicedata->effector) + if (voicedata->effector) voicedata->effector->Stop(); } else { @@ -313,11 +310,11 @@ void set_animation_state(VoiceData *voicedata) voicedata->state = STT_STATE_VAL_NOT_RECOGNISED; - if(voicedata->refresh_timer) { + if (voicedata->refresh_timer) { ecore_timer_del(voicedata->refresh_timer); } - if(voicedata->effector) + if (voicedata->effector) voicedata->effector->Stop(true); voicedata->refresh_timer = ecore_timer_add(2.0, _recognition_failure_cb, voicedata); @@ -326,7 +323,7 @@ void set_animation_state(VoiceData *voicedata) void show_error_message(VoiceData *vd, stt_error_e reason) { - if(reason == STT_ERROR_OUT_OF_NETWORK) { + if (reason == STT_ERROR_OUT_OF_NETWORK) { show_popup_toast(_(SK_NETWORK_ERROR), false); vd->state = STT_STATE_VAL_INIT; } else if (reason == STT_ERROR_RECORDER_BUSY) { @@ -341,7 +338,7 @@ void show_error_message(VoiceData *vd, stt_error_e reason) static Eina_Bool _start_timer_cb(void* data) { LOGD("_start_timer_cb"); - if(data) { + if (data) { VoiceData *voicedata = (VoiceData *) data; try { @@ -377,7 +374,7 @@ void on_initial_anim_press_cb(void *data, Evas_Object *obj, const char *emission VoiceData *vd = (VoiceData *)data; int tempVal = vd->sttmanager->GetCurrent(); - if(tempVal == STT_STATE_CREATED) { + if (tempVal == STT_STATE_CREATED) { LOGD("IGNORE TOUCH event before STT READY. STT is preparing", vd->state); return; } @@ -385,13 +382,13 @@ void on_initial_anim_press_cb(void *data, Evas_Object *obj, const char *emission LOGD("SttManager State : %d", vd->sttmanager->GetCurrent()); LOGD("Ui Voice State : %d", vd->state); - switch(vd->state) { + switch (vd->state) { case STT_STATE_VAL_INIT: LOGD("%s", "STT_STATE_VAL_INIT"); get_stt_default_language(vd); vd->sttmanager->SetLanguage(std::string(vd->kbd_lang)); - if(vd->start_timer) { + if (vd->start_timer) { ecore_timer_del(vd->start_timer); vd->start_timer = NULL; } @@ -411,16 +408,16 @@ void on_initial_anim_press_cb(void *data, Evas_Object *obj, const char *emission */ set_guide_text(vd, ""); - if(vd->effector) + if (vd->effector) vd->effector->Stop(); } catch (is::stt::SttException &e) { LOGD("%s", e.what()); - if(e.GetEcode() != STT_ERROR_INVALID_STATE) { + if (e.GetEcode() != STT_ERROR_INVALID_STATE) { set_guide_text(vd, _(SK_RECOGNITION_FAILED)); vd->state = STT_STATE_VAL_INIT; - if(vd->effector) + if (vd->effector) vd->effector->Stop(true); } } @@ -433,7 +430,6 @@ void on_initial_anim_press_cb(void *data, Evas_Object *obj, const char *emission vd->sttmanager->Cancel(); } catch (is::stt::SttException &e) { - } break; @@ -485,20 +481,20 @@ int init_voice(Evas_Object *parent, const char *lang, VoiceData *r_voicedata) voicedata->voicefw_state = 0; /* Set Voice Language */ - if(voicedata->kbd_lang){ + if (voicedata->kbd_lang){ free(voicedata->kbd_lang); voicedata->kbd_lang = NULL; } //stt_get_default_language(my_voicedata->voicefw_handle, &my_voicedata->kbd_lang); get_stt_default_language(voicedata); - if(NULL == voicedata->kbd_lang || FALSE == is_lang_supported_by_stt(voicedata->kbd_lang)) { + if (NULL == voicedata->kbd_lang || FALSE == is_lang_supported_by_stt(voicedata->kbd_lang)) { voicedata->kbd_lang = strdup("en_US"); } LOGD("Voice input active language is : %s", voicedata->kbd_lang); - voicedata->naviframe= parent; + voicedata->naviframe = parent; if (NULL == voicedata->naviframe) { return FALSE; @@ -550,7 +546,7 @@ Evas_Object *create_fullview(Evas_Object *win, VoiceData *r_voicedata) voicedata->mic_button = m_mic_button; - if(voicedata->btn_disabling_timer == NULL){ + if (voicedata->btn_disabling_timer == NULL){ voicedata->btn_disabling_timer = ecore_timer_add(2.0, _mic_button_enable_cb, voicedata); } @@ -578,7 +574,7 @@ Eina_Bool init_view(void *data) VoiceData *voicedata = (VoiceData *)data; - if(voicedata == NULL) { + if (voicedata == NULL) { LOGD("init_view : voicedata == NULL"); return ECORE_CALLBACK_CANCEL; } @@ -592,7 +588,6 @@ Eina_Bool init_view(void *data) return ECORE_CALLBACK_CANCEL; } - Evas_Object *show_voice_window(Evas_Object *parent, VoiceData *r_voicedata) { LOGD("show_voice_window"); @@ -680,27 +675,27 @@ void on_destroy(VoiceData *r_voicedata) voicedata->power_unlock_timer = NULL; } - if(voicedata->kbd_lang) { + if (voicedata->kbd_lang) { free(voicedata->kbd_lang); voicedata->kbd_lang = NULL; } - if(voicedata->ieffect) { + if (voicedata->ieffect) { delete voicedata->ieffect; voicedata->ieffect = NULL; } - if(voicedata->effector) { + if (voicedata->effector) { delete voicedata->effector; voicedata->effector = NULL; } - if(voicedata->sttmanager) { + if (voicedata->sttmanager) { delete voicedata->sttmanager; voicedata->sttmanager = NULL; } - if(voicedata->sttfeedback) { + if (voicedata->sttfeedback) { delete voicedata->sttfeedback; voicedata->sttfeedback = NULL; } @@ -755,7 +750,7 @@ void show_voice_input(Evas_Object *parent, const char *lang, void (*get_string)( void ise_show_stt_mode(Evas_Object *win) { - if(!win) + if (!win) return; show_voice_input(win, NULL, NULL); diff --git a/src/ise-stt-option.cpp b/src/ise-stt-option.cpp index 5907e6d..86dd510 100644 --- a/src/ise-stt-option.cpp +++ b/src/ise-stt-option.cpp @@ -145,7 +145,7 @@ static void set_language_value(int type) void _stt_lang_changed_cb(keynode_t *key, void* data) { - if(!data) return; + if (!data) return; VoiceData *vd = (VoiceData *) data; get_stt_default_language(vd); @@ -173,11 +173,11 @@ int is_lang_supported_by_stt(char lang[]) void get_stt_default_language(VoiceData *my_voicedata) { - if(!my_voicedata) { + if (!my_voicedata) { return; } - if(my_voicedata->kbd_lang) { + if (my_voicedata->kbd_lang) { free(my_voicedata->kbd_lang); my_voicedata->kbd_lang = NULL; } -- 2.7.4