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"
26 static unsigned long long SumSquare(unsigned long long const& a, T const& b) {
30 const double MAX_AMPLITUDE_MEAN_16 = 23170.115738161934;
31 const double MAX_AMPLITUDE_MEAN_08 = 89.803909382810;
33 unsigned int sample_count = SAMPLE_COUNT;
37 using namespace is::ui;
40 WInputSttMicEffect::WInputSttMicEffect()
41 : processing_effect_timer(NULL)
48 WInputSttMicEffect::~WInputSttMicEffect() {
49 ProcessingAnimationStop();
52 std::vector<int> WInputSttMicEffect::GetVolume() {
53 std::vector<int> result;
59 // ret = stt_get_spectrum(handle, (void *) pcm, &size);
62 if (STT_ERROR_NONE != ret) {
63 PRINTFUNC(DLOG_ERROR, "stt_audio_snapshot invalid (%d)", ret);
65 unsigned int level = 0;
66 unsigned int step = (unsigned int) (size/2/sample_count);
68 for (unsigned int k = 0; k < sample_count; k++ ){
69 square_sum = std::accumulate(pcm + k*step, pcm + k*step + 5, 0ull, SumSquare<short>);
70 level = ConvertLevel();
71 result.push_back(level);
77 float WInputSttMicEffect::GetDecibel() const
79 float rms = std::sqrt(square_sum/count);
80 return 20.0*log10(rms);
83 int WInputSttMicEffect::ConvertLevel()
85 float db = GetDecibel();
89 } else if ( db <= 33.3 ){
91 } else if ( db <= 36.6 ){
93 } else if ( db <= 40 ){
95 } else if ( db <= 43.3 ){
97 } else if ( db <= 46.6 ){
99 } else if ( db <= 50 ){
101 } else if ( db <= 53.3 ){
103 } else if ( db <= 56.6 ){
105 } else if ( db <= 60 ){
112 void WInputSttMicEffect::ProcessingAnimationStart() {
113 elm_progressbar_pulse(progressbar, EINA_TRUE);
115 processing_effect_timer = ecore_timer_add(0.1,
116 [](void *data)->Eina_Bool
118 if(!data) return ECORE_CALLBACK_CANCEL;
120 WInputSttMicEffect *effect = (WInputSttMicEffect *) data;
121 Evas_Object *progressbar = effect->progressbar;
123 double progress = eext_circle_value_get(progressbar);
130 eext_circle_value_set(progressbar, progress);
132 return ECORE_CALLBACK_RENEW;
136 void WInputSttMicEffect::ProcessingAnimationStop() {
137 if(processing_effect_timer)
139 ecore_timer_del(processing_effect_timer);
140 processing_effect_timer = NULL;
142 elm_progressbar_pulse(progressbar, EINA_FALSE);
147 void WInputSttMicEffect::SetSttHandle(stt_h handle) {
148 this->handle = handle;
153 void WInputSttMicEffect::SetProgressBar(Evas_Object *progress) {
154 this->progressbar = progress;