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;
41 WInputSttMicEffect::WInputSttMicEffect()
42 : processing_effect_timer(NULL)
52 WInputSttMicEffect::~WInputSttMicEffect() {
54 ProcessingAnimationStop();
59 std::vector<int> WInputSttMicEffect::GetVolume() {
61 std::vector<int> result;
67 // ret = stt_get_spectrum(handle, (void *) pcm, &size);
72 if(STT_ERROR_NONE != ret) {
73 PRINTFUNC(DLOG_ERROR, "stt_audio_snapshot invalid (%d)", ret);
76 unsigned int level = 0;
77 unsigned int step = (unsigned int) (size/2/sample_count);
79 for (unsigned int k = 0; k < sample_count; k++ ){
80 square_sum = std::accumulate(pcm + k*step, pcm + k*step + 5, 0ull, SumSquare<short>);
81 level = ConvertLevel();
82 result.push_back(level);
91 float WInputSttMicEffect::GetDecibel() const
93 float rms = std::sqrt( square_sum/count );
94 return 20.0*log10(rms);
99 int WInputSttMicEffect::ConvertLevel()
101 float db = GetDecibel();
106 else if ( db <= 33.3 ){
109 else if ( db <= 36.6 ){
112 else if ( db <= 40 ){
115 else if ( db <= 43.3 ){
118 else if ( db <= 46.6 ){
121 else if ( db <= 50 ){
124 else if ( db <= 53.3 ){
127 else if ( db <= 56.6 ){
130 else if ( db <= 60 ){
140 void WInputSttMicEffect::ProcessingAnimationStart() {
142 elm_progressbar_pulse(progressbar, EINA_TRUE);
144 processing_effect_timer = ecore_timer_add ( 0.1,
145 [](void *data)->Eina_Bool
147 if(!data) return ECORE_CALLBACK_CANCEL;
149 WInputSttMicEffect *effect = (WInputSttMicEffect *) data;
150 Evas_Object *progressbar = effect->progressbar;
152 double progress = eext_circle_value_get(progressbar);
159 eext_circle_value_set(progressbar, progress);
161 return ECORE_CALLBACK_RENEW;
167 void WInputSttMicEffect::ProcessingAnimationStop() {
169 if(processing_effect_timer)
171 ecore_timer_del(processing_effect_timer);
172 processing_effect_timer = NULL;
174 elm_progressbar_pulse(progressbar, EINA_FALSE);
179 void WInputSttMicEffect::SetSttHandle(stt_h handle) {
181 this->handle = handle;
186 void WInputSttMicEffect::SetProgressBar(Evas_Object *progress) {
188 this->progressbar = progress;