Fix defect detected by static anlysis tool 58/103058/1
authorsungwook79.park <sungwook79.park@samsung.com>
Wed, 7 Dec 2016 06:41:59 +0000 (15:41 +0900)
committersungwook79.park <sungwook79.park@samsung.com>
Wed, 7 Dec 2016 06:41:59 +0000 (15:41 +0900)
Change-Id: I6e181a74c9a054368a6a701e8bac51bc5179c5b2
Signed-off-by: sungwook79.park <sungwook79.park@samsung.com>
src/MicEffector.cpp
src/WInputSttMicEffect.cpp

index 2d6c46f..a6bdbfb 100644 (file)
@@ -309,7 +309,7 @@ void MicEffector::Start()
 
                         effector->drawcount = 0;
                         effector->timer = NULL;
-                        effector->VolumeCheck();
+                        effector->VolumeCheck(true);
                         effector->Effect();
                         return ECORE_CALLBACK_CANCEL;
                     }
@@ -353,10 +353,10 @@ void MicEffector::Effect(bool fake)
 
                     if (effector->drawcount < 7)    {
                         effector->drawcount++;
-                        effector->VolumeCheck(effector->fake);
+                        effector->VolumeCheck(true);
                     } else {
                         effector->drawcount = 0;
-                        effector->VolumeCheck(effector->fake);
+                        effector->VolumeCheck(true);
                     }
 
                     return ECORE_CALLBACK_RENEW;
@@ -420,13 +420,17 @@ void MicEffector::VolumeCheck(bool fake)
 
     this->fake = fake;
 
-    for (unsigned int i = 0; i < spectrum_count; i++) {
-        unsigned int seed = time(NULL);
+    if (!fake) {
+        volumes = ieffect.GetVolume();
+    } else {
+        for (unsigned int i = 0; i < spectrum_count; i++) {
+            unsigned int seed = time(NULL);
 #ifdef _WEARABLE
-        volumes.push_back(rand_r(&seed) % 6);
+            volumes.push_back(rand_r(&seed) % 6);
 #else
-        volumes.push_back(rand_r(&seed) % 15);
+            volumes.push_back(rand_r(&seed) % 15);
 #endif
+        }
     }
 
     prev.clear();
index fa0f710..8844983 100644 (file)
 #include <cmath>
 #include <algorithm>
 #include <numeric>
-
+#include <stt.h>
 #include <efl_extension.h>
 #include "WInputSttMicEffect.h"
+#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "ISE_DEFAULT"
 
 namespace {
 template<class T>
-static unsigned long long SumSquare(unsigned long long const& a, T const& b) {
+static float SumSquare(float const& a, T const& b) {
     return a + b*b;
 }
 
@@ -52,11 +55,11 @@ WInputSttMicEffect::~WInputSttMicEffect() {
 std::vector<int> WInputSttMicEffect::GetVolume() {
     std::vector<int> result;
 
-    short pcm[512] = {0};
-    int size = 0;
+    float pcm[512] = {0};
+    int size = 50;
     int ret = 0;
 
-//    ret = stt_get_spectrum(handle, (void *) pcm, &size);
+    ret = stt_get_recording_volume(handle, pcm);
     count = 5;
 
     if (STT_ERROR_NONE != ret) {
@@ -65,7 +68,7 @@ std::vector<int> WInputSttMicEffect::GetVolume() {
         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<short>);
+            square_sum = (unsigned long long)std::accumulate(pcm + k*step, pcm + k*step + 5, 0ull, SumSquare<float>);
             level = ConvertLevel();
             result.push_back(level);
         }