#include <pthread.h>
#include <sound_manager.h>
#include <sound_manager_internal.h>
+#include <math.h>
#include "vc_cmd_db.h"
#include "vc_config_mgr.h"
}
static int g_cnt = 0;
-static Eina_Bool __vc_mgr_set_volume(void* data)
+static Eina_Bool __vc_mgr_set_volume_timer_cb(void* data)
{
g_cnt++;
g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5 * g_cnt;
int __vc_mgr_cb_set_volume(float volume)
{
+ // called in vc_mgr_dbus
g_prev_volume_db = g_volume_db;
g_cur_volume_db = volume;
}
g_cnt = 1;
- g_m_set_volume_timer = ecore_timer_add(0.05, __vc_mgr_set_volume, NULL);
+ g_m_set_volume_timer = ecore_timer_add(0.05, __vc_mgr_set_volume_timer_cb, NULL);
+
+ return 0;
+}
+
+int __vc_mgr_set_volume(float volume)
+{
+ // called by app directly
+ g_volume_db = volume;
return 0;
}
return 0;
}
+static float __get_volume_decibel(char* data, int size)
+{
+#define MAX_AMPLITUDE_MEAN_16 32768
+
+ int i, depthByte;
+ int count = 0;
+
+ float db = 0.0;
+ float rms = 0.0;
+ unsigned long long square_sum = 0;
+ short pcm16 = 0;
+
+ depthByte = 2;
+
+ for (i = 0; i < size; i += (depthByte<<1)) {
+ pcm16 = 0;
+ memcpy(&pcm16, data + i, sizeof(short));
+ square_sum += pcm16 * pcm16;
+ count++;
+ }
+
+ if (0 == count || 0 == square_sum) {
+ SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No data");
+ rms = 1.0;
+ } else {
+ rms = sqrt((float)square_sum/count);
+ }
+
+ db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_16);
+ return db;
+}
+
int vc_mgr_send_audio_streaming(vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len)
{
SLOG(LOG_INFO, TAG_VCM, "[Manager] Send audio streaming to the engine service");
return VC_ERROR_INVALID_STATE;
}
+ /* set volume */
+ float volume = __get_volume_decibel((char*)buffer, len);
+ __vc_mgr_set_volume(volume);
+
/* send audio streaming */
int ret = vc_mgr_dbus_send_audio_streaming(g_vc_m->handle, event, buffer, len);
if (0 != ret) {