aboutsummaryrefslogtreecommitdiffstats
path: root/src/StatsServer.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-04-25 11:34:46 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-04-25 11:34:46 +0200
commit450300013cdcc34570365832b31024959e19b107 (patch)
treec4d9a9d5c6b118d9e584434bc3b7d055d36151bb /src/StatsServer.cpp
parente79bbb00757cb6e7a415aa613d52253b12ca26a8 (diff)
downloaddabmux-450300013cdcc34570365832b31024959e19b107.tar.gz
dabmux-450300013cdcc34570365832b31024959e19b107.tar.bz2
dabmux-450300013cdcc34570365832b31024959e19b107.zip
Add peak audio levels to statistics
Diffstat (limited to 'src/StatsServer.cpp')
-rw-r--r--src/StatsServer.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/StatsServer.cpp b/src/StatsServer.cpp
index 2e89134..be40920 100644
--- a/src/StatsServer.cpp
+++ b/src/StatsServer.cpp
@@ -28,6 +28,7 @@
#include <errno.h>
#include <string.h>
+#include <math.h>
#include <sstream>
#include "StatsServer.h"
#include "Log.h"
@@ -69,6 +70,27 @@ void StatsServer::notifyBuffer(std::string id, long bufsize)
}
}
+void StatsServer::notifyPeakLevels(std::string id, int peak_left, int peak_right)
+{
+ boost::mutex::scoped_lock lock(m_mutex);
+
+ if (m_inputStats.count(id) == 0) {
+ etiLog.level(error) <<
+ "Stats Server id '" <<
+ id << "' does was not registered";
+ return;
+ }
+
+ InputStat& is = m_inputStats[id];
+ if (peak_left > is.peak_left) {
+ is.peak_left = peak_left;
+ }
+
+ if (peak_right > is.peak_right) {
+ is.peak_right = peak_right;
+ }
+}
+
void StatsServer::notifyUnderrun(std::string id)
{
boost::mutex::scoped_lock lock(m_mutex);
@@ -252,10 +274,16 @@ std::string InputStat::encodeJSON()
{
std::ostringstream ss;
+ /* convert to dB */
+ int dB_l = peak_left ? round(20*log10((double)peak_left / INT16_MAX)) : -90;
+ int dB_r = peak_right ? round(20*log10((double)peak_right / INT16_MAX)) : -90;
+
ss <<
"{ \"inputstat\" : {"
"\"min_fill\": " << min_fill_buffer << ", "
"\"max_fill\": " << max_fill_buffer << ", "
+ "\"peak_left\": " << dB_l << ", "
+ "\"peak_right\": " << dB_r << ", "
"\"num_underruns\": " << num_underruns << ", "
"\"num_overruns\": " << num_overruns <<
" } }";