2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <efl_extension.h>
22 #include "WInputSttMicEffect.h"
25 #define LOG_TAG "INPUT_DELEGATOR"
29 static float SumSquare(float const& a, T const& b) {
33 const double MAX_AMPLITUDE_MEAN_16 = 23170.115738161934;
34 const double MAX_AMPLITUDE_MEAN_08 = 89.803909382810;
36 unsigned int sample_count = SAMPLE_COUNT;
40 using namespace is::ui;
43 WInputSttMicEffect::WInputSttMicEffect()
47 , processing_effect_timer(NULL)
51 WInputSttMicEffect::~WInputSttMicEffect() {
52 ProcessingAnimationStop();
55 std::vector<int> WInputSttMicEffect::GetVolume() {
56 std::vector<int> result;
62 ret = stt_get_recording_volume(handle, pcm);
65 if (STT_ERROR_NONE != ret) {
67 unsigned int level = 0;
68 unsigned int step = (unsigned int) (size/2/sample_count);
70 for (unsigned int k = 0; k < sample_count; k++ ){
71 square_sum = (unsigned long long)std::accumulate(pcm + k*step, pcm + k*step + 5, 0ull, SumSquare<float>);
72 level = ConvertLevel();
73 result.push_back(level);
79 float WInputSttMicEffect::GetDecibel() const
81 float rms = std::sqrt(square_sum/count);
82 return 20.0*log10(rms);
85 int WInputSttMicEffect::ConvertLevel()
87 float db = GetDecibel();
91 } else if ( db <= 33.3 ){
93 } else if ( db <= 36.6 ){
95 } else if ( db <= 40 ){
97 } else if ( db <= 43.3 ){
99 } else if ( db <= 46.6 ){
101 } else if ( db <= 50 ){
103 } else if ( db <= 53.3 ){
105 } else if ( db <= 56.6 ){
107 } else if ( db <= 60 ){
114 void WInputSttMicEffect::ProcessingAnimationStart() {
115 elm_progressbar_pulse(progressbar, EINA_TRUE);
117 processing_effect_timer = ecore_timer_add(0.1,
118 [](void *data)->Eina_Bool
120 if (!data) return ECORE_CALLBACK_CANCEL;
122 WInputSttMicEffect *effect = (WInputSttMicEffect *) data;
123 Evas_Object *progressbar = effect->progressbar;
125 double progress = eext_circle_value_get(progressbar);
132 eext_circle_value_set(progressbar, progress);
134 return ECORE_CALLBACK_RENEW;
138 void WInputSttMicEffect::ProcessingAnimationStop() {
139 if (processing_effect_timer)
141 ecore_timer_del(processing_effect_timer);
142 processing_effect_timer = NULL;
144 elm_progressbar_pulse(progressbar, EINA_FALSE);
147 void WInputSttMicEffect::SetSttHandle(stt_h handle) {
148 this->handle = handle;
151 void WInputSttMicEffect::SetProgressBar(Evas_Object *progress) {
152 this->progressbar = progress;