#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 "INPUT_DELEGATOR"
namespace {
template<class T>
-static unsigned long long SumSquare(unsigned long long const& a, T const& b) {
- return a + b*b;
+static float SumSquare(float const& a, T const& b) {
+ return a + b*b;
}
const double MAX_AMPLITUDE_MEAN_16 = 23170.115738161934;
WInputSttMicEffect::WInputSttMicEffect()
- : processing_effect_timer(NULL)
- , progressbar(NULL)
- , count(5)
- , square_sum(0)
- , handle(NULL) {
+ : square_sum(0)
+ , count(5)
+ , handle(NULL)
+ , processing_effect_timer(NULL)
+ , progressbar(NULL) {
}
WInputSttMicEffect::~WInputSttMicEffect() {
- ProcessingAnimationStop();
+ ProcessingAnimationStop();
}
std::vector<int> WInputSttMicEffect::GetVolume() {
- std::vector<int> 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) {
- PRINTFUNC(DLOG_ERROR, "stt_audio_snapshot invalid (%d)", 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<short>);
- level = ConvertLevel();
- result.push_back(level);
- }
- }
- return result;
+ std::vector<int> result;
+
+ float pcm[512] = {0};
+ int size = 50;
+ int ret = 0;
+
+ ret = stt_get_recording_volume(handle, pcm);
+ 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 = (unsigned long long)std::accumulate(pcm + k*step, pcm + k*step + 5, 0ull, SumSquare<float>);
+ 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;
}